Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created January 21, 2013 20:51
Show Gist options
  • Save waffle2k/4589238 to your computer and use it in GitHub Desktop.
Save waffle2k/4589238 to your computer and use it in GitHub Desktop.
Attempt to identify complaints based on custom rules
#!/usr/bin/perl
use strict;
use Email::ARF::Report;
my $message = do { local $/; <>; };
my $report = Email::ARF::Report->new( $message );
use Data::Dumper;
#print Dumper( $report ),"\n";
#my $email = $report->original_email->body,"\n";
my $email;
my @report_parts = $report->as_email->parts;
if( scalar @report_parts >= 3 ){
$email = $report_parts[2];
} else {
die "Could not parse email: $!"
}
#######################################################################
# global variable
my $g_rules = {};
sub evaluate_rule {
my $email = shift;
my $rulename = shift;
my $checks = shift;
my $cb = shift;
my $email_body = eval {
$email->body_str();
};
if( $@ ){
$email_body = $email->body_raw();
}
if( defined $checks->{body} ){
for my $c ( @{$checks->{body}} ){
if( $email_body =~ /$c/ ){
if( $cb ){
$cb->( "RULE: $rulename" );
}
}
}
}
if( defined $checks->{header} ){
for my $c ( @{$checks->{header}} ){
}
}
}
my @rules;
sub record_rules {
my $rule = shift;
if( $rule =~ /RULE:\s+(\S.*)/ ){
push( @rules, $1 );
}
}
evaluate_rule( $email, 'BARRISTER' => {
body => [ 'Barrister', ], }, \&record_rules
);
evaluate_rule( $email, 'PHONE' => {
body => [ 'SENDING YOUR PHONE NUMBER', ], }, \&record_rules
);
print Dumper( \@rules ),"\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment