Skip to content

Commit

Permalink
Merge branch 'bugfixes-5_0_4' into 5_1_0-alpha1
Browse files Browse the repository at this point in the history
  • Loading branch information
justingit committed May 22, 2012
2 parents 388671b + 69eb7b7 commit 280b2ac
Show file tree
Hide file tree
Showing 16 changed files with 822 additions and 189 deletions.
138 changes: 114 additions & 24 deletions dada/DADA/App/BounceHandler/MessageParser.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ sub run_all_parses {
%{$diagnostics} = ( %{$diagnostics}, %{$ses_diagnostics} ) %{$diagnostics} = ( %{$diagnostics}, %{$ses_diagnostics} )
if $ses_diagnostics; if $ses_diagnostics;
} }
elsif($self->isa_rfc6522_bounce($entity)) {
my ( $rfc6522_list, $rfc6522_email, $rfc6522_diagnostics ) =
$self->parse_for_rfc6522($entity);
$list ||= $rfc6522_list;
$email ||= $rfc6522_email;
%{$diagnostics} = ( %{$diagnostics}, %{$rfc6522_diagnostics} )
if $rfc6522_diagnostics;
}
elsif($self->bounce_from_secureserver_dot_net($entity)){ elsif($self->bounce_from_secureserver_dot_net($entity)){
my ( $ss_list, $ss_email, $ss_diagnostics ) = my ( $ss_list, $ss_email, $ss_diagnostics ) =
$self->parse_for_secureserver_dot_net($entity); $self->parse_for_secureserver_dot_net($entity);
Expand Down Expand Up @@ -186,6 +194,7 @@ sub run_all_parses {
# This is a special case - since this outside module adds pseudo diagonistic # This is a special case - since this outside module adds pseudo diagonistic
# reports, we'll say, add them if they're NOT already there: # reports, we'll say, add them if they're NOT already there:



my ( $bp_list, $bp_email, $bp_diagnostics ) = my ( $bp_list, $bp_email, $bp_diagnostics ) =
$self->parse_using_m_ds_bp($entity); $self->parse_using_m_ds_bp($entity);


Expand All @@ -197,6 +206,8 @@ sub run_all_parses {
%{$diagnostics} = ( %{$diagnostics}, %{$bp_diagnostics} ) %{$diagnostics} = ( %{$diagnostics}, %{$bp_diagnostics} )
if $bp_diagnostics; if $bp_diagnostics;




chomp($email) if $email; chomp($email) if $email;


#small hack, turns, %2 into, '-' #small hack, turns, %2 into, '-'
Expand Down Expand Up @@ -330,12 +341,28 @@ sub find_list_in_list_headers {
my $entity = shift; my $entity = shift;
my @parts = $entity->parts; my @parts = $entity->parts;
my $list; my $list;
my $orig_msg_copy = undef;


if ( $entity->head->mime_type eq 'message/rfc822' ) { if ( $entity->head->mime_type eq 'message/rfc822') {
my $orig_msg_copy = $parts[0]; $orig_msg_copy = $parts[0];
$list = $self->list_in_list_headers($orig_msg_copy); $list = $self->list_in_list_headers($orig_msg_copy);

} }
elsif($entity->head->mime_type eq 'text/rfc822-headers'){

require MIME::Parser;
my $parser = new MIME::Parser;
$parser = optimize_mime_parser($parser);

eval {
$orig_msg_copy = $parser->parse_data( $entity->bodyhandle->as_string );
};
if ($@) {
warn "Trouble parsing text/rfc822-headers message. $@";
}
else {
}
$list = $self->list_in_list_headers($orig_msg_copy);
}
else { else {
my $i; my $i;
for $i ( 0 .. $#parts ) { for $i ( 0 .. $#parts ) {
Expand All @@ -350,11 +377,14 @@ sub find_list_in_list_headers {
sub list_in_list_headers { sub list_in_list_headers {
my $self = shift; my $self = shift;
my $entity = shift; my $entity = shift;
my $list = undef; my $list = undef;

my $list_header = $entity->head->get( 'List', 0 ) || undef;
my $list_header = $entity->head->get( 'List', 0 ); if(defined($list_header)){
$list = $list_header if $list_header !~ /\:/; if($list_header !~ /\:/) {

$list = $list_header;
}
}

if ( !$list ) { if ( !$list ) {
$list_header = $entity->head->get( 'X-List', 0 ); $list_header = $entity->head->get( 'X-List', 0 );
$list = $list_header if $list_header !~ /\:/; $list = $list_header if $list_header !~ /\:/;
Expand Down Expand Up @@ -382,12 +412,28 @@ sub find_message_id_in_headers {
my $entity = shift; my $entity = shift;
my @parts = $entity->parts; my @parts = $entity->parts;
my $mid; my $mid;
if ( $entity->head->mime_type eq 'message/rfc822' ) { if ( $entity->head->mime_type eq 'message/rfc822' || $entity->head->mime_type eq 'text/rfc822-headers') {
my $orig_msg_copy = $parts[0]; my $orig_msg_copy = '';


if($entity->head->mime_type eq 'text/rfc822-headers') {

require MIME::Parser;
my $parser = new MIME::Parser;
$parser = optimize_mime_parser($parser);

eval { $orig_msg_copy = $parser->parse_data($entity->bodyhandle->as_string) };
if ( $@ ) {
warn "Trouble parsing text/rfc822-headers message. $@";
}
else {
}
}
else {
$orig_msg_copy = $parts[0];
}

# Amazon SES finds this in the, "X-Message-ID" header: # Amazon SES finds this in the, "X-Message-ID" header:
# Amazon SES will also set its own Message-ID. Maddening! # Amazon SES will also set its own Message-ID. Maddening!

if($orig_msg_copy->head->get( 'X-Message-ID', 0 )){ if($orig_msg_copy->head->get( 'X-Message-ID', 0 )){
$mid = $orig_msg_copy->head->get( 'X-Message-ID', 0 ); $mid = $orig_msg_copy->head->get( 'X-Message-ID', 0 );
} }
Expand Down Expand Up @@ -476,10 +522,17 @@ sub generic_delivery_status_parse {
$diag->{Guessed_MTA} = 'Postfix'; $diag->{Guessed_MTA} = 'Postfix';
} }


my ( $rfc, $remail ) = split( ';', $diag->{'Final-Recipient'} ); my $rfc = undef;
if ( $remail eq '<>' ) { #example: Final-Recipient: LOCAL;<> my $remail = undef;
( $rfc, $remail ) = split( ';', $diag->{'Original-Recipient'} ); if(exists($diag->{'Original-Recipient'})){
} ( $rfc, $remail ) = split( ';', $diag->{'Original-Recipient'} );
}
elsif(exists($diag->{'Final-Recipient'})){
( $rfc, $remail ) = split( ';', $diag->{'Final-Recipient'} );
if ( $remail eq '<>' ) { #example: Final-Recipient: LOCAL;<>
$remail = undef;
}
}
$email = $remail; $email = $remail;


for ( keys %$diag ) { for ( keys %$diag ) {
Expand Down Expand Up @@ -575,6 +628,23 @@ sub bounce_from_ses {
} }
} }


sub isa_rfc6522_bounce {
my $self = shift;
my $entity = shift;
# print '$entity->effective_type ' . $entity->effective_type . "\n";
# print '$entity->head->mime_attr(\'content-type.report-type\'); ' . $entity->head->mime_attr('content-type.report-type') . "\n";

if ( $entity->effective_type eq 'multipart/report'
&& $entity->head->mime_attr('content-type.report-type') eq 'delivery-status' )
{
return 1;
}
else {
return 0;
}
}


sub bounce_from_secureserver_dot_net { sub bounce_from_secureserver_dot_net {
my $self = shift; my $self = shift;
my $entity = shift; my $entity = shift;
Expand All @@ -592,9 +662,16 @@ sub bounce_from_secureserver_dot_net {






sub parse_for_amazon_ses {
my $self = shift;
my $entity = shift;
my ( $list, $email, $diag ) = $self->parse_for_rfc6522($entity);
$diag->{Guessed_MTA} = 'Amazon_SES';
return ( $list, $email, $diag );
}




sub parse_for_amazon_ses { sub parse_for_rfc6522 {


my $self = shift; my $self = shift;
my $entity = shift; my $entity = shift;
Expand All @@ -604,6 +681,12 @@ sub parse_for_amazon_ses {
my $list; my $list;


my @parts = $entity->parts; my @parts = $entity->parts;

# Human readable
my $notification = '';
if($parts[0]){
$notification = $self->generic_human_readable_parse($parts[0]);
}
if($parts[1]){ if($parts[1]){
my $mds_entity = $parts[1]; my $mds_entity = $parts[1];


Expand All @@ -613,20 +696,27 @@ sub parse_for_amazon_ses {
} }
if($parts[2]){ if($parts[2]){
my $orig_msg_entity = $parts[2]; my $orig_msg_entity = $parts[2];
if ( $orig_msg_entity->head->mime_type eq 'message/rfc822' ) { if ( $orig_msg_entity->head->mime_type eq 'message/rfc822'
|| $orig_msg_entity->head->mime_type eq 'text/rfc822-headers'
) {
$list = $self->find_list_in_list_headers($orig_msg_entity); $list = $self->find_list_in_list_headers($orig_msg_entity);
$diag->{'Message-Id'} = $self->find_message_id_in_headers($orig_msg_entity); $diag->{'Message-Id'} = $self->find_message_id_in_headers($orig_msg_entity);
} }
} }

$diag->{'Notification'} = $notification;

$diag->{Guessed_MTA} = 'Amazon_SES';
return ( $list, $email, $diag ); return ( $list, $email, $diag );



} }




sub generic_human_readable_parse {
my $self = shift;
my $entity = shift;

return $entity->bodyhandle->as_string;

}



sub parse_for_secureserver_dot_net { sub parse_for_secureserver_dot_net {


Expand Down
45 changes: 36 additions & 9 deletions dada/DADA/App/BounceHandler/Rules.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -94,17 +94,20 @@ sub find_rule_to_use {
MESSAGEFIELD: MESSAGEFIELD:
for my $pos_match ( @{ $message_fields->{$m_field} } ) { for my $pos_match ( @{ $message_fields->{$m_field} } ) {
if ( $is_regex == 1 ) { if ( $is_regex == 1 ) {
if ( $diagnostics->{$real_field} =~ m/$pos_match/ ) { if(exists($diagnostics->{$real_field})){
$ThingsToMatch{$m_field} = 1; if ( $diagnostics->{$real_field} =~ m/$pos_match/ ) {
next MESSAGEFIELD; $ThingsToMatch{$m_field} = 1;
} next MESSAGEFIELD;
}
}
} }
else { else {

if(exists($diagnostics->{$real_field})){
if ( $diagnostics->{$real_field} eq $pos_match ) { if ( $diagnostics->{$real_field} eq $pos_match ) {
$ThingsToMatch{$m_field} = 1; $ThingsToMatch{$m_field} = 1;
next MESSAGEFIELD; next MESSAGEFIELD;
} }
}


} }
} }
Expand Down Expand Up @@ -929,6 +932,30 @@ qr/SMTP\; 550|550 MAILBOX NOT FOUND|550 5\.1\.1 unknown or illegal alias|User un
} }
}, },



{
bounce_4dot4dot1_error => {
Examine => {
Message_Fields => {
Status => [qw(4.4.1)],
Action => [qw(failed)],
'Diagnostic-Code_regex' => [ (qr/(C|c)onnection refused/) ],
},
Data => {
Email => 'is_valid',
List => 'is_valid',
}
},
Action => {

#unsubscribe_bounced_email => 'from_list',
add_to_score => 'hardbounce_score',
},
}
},



{ {
permanent_move_failure => { permanent_move_failure => {
Examine => { Examine => {
Expand Down
12 changes: 9 additions & 3 deletions dada/DADA/App/FormatMessages.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -597,9 +597,15 @@ sub _add_opener_image {


my $self = shift; my $self = shift;
my $content = shift; my $content = shift;
my $img_opener_code = '<!--open_img--><img src="' . $DADA::Config::PROGRAM_URL . '/spacer_image/<!-- tmpl_var list_settings.list -->/<!-- tmpl_var message_id -->/spacer.png" width="1" height="1" /><!--/open_img-->'; my $img_opener_code = '<!--open_img--><img src="<!-- tmpl_var PROGRAM_URL -->/spacer_image/<!-- tmpl_var list_settings.list -->/<!-- tmpl_var message_id -->/spacer.png" width="1" height="1" /><!--/open_img-->';
#</body>
$content =~ s/(\<\/body(.*?)\>)/$img_opener_code\n$1/i; if($content =~ m/\<\/body(.*?)\>/i){
#</body>
$content =~ s/(\<\/body(.*?)\>)/$img_opener_code\n$1/i;
}else {
# No end body tag?!
$content .= "\n" . $img_opener_code
}
return $content; return $content;
} }


Expand Down
15 changes: 8 additions & 7 deletions dada/DADA/App/Guts.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ require Exporter;
uriescape uriescape
lc_email lc_email
make_safer make_safer
convert_to_html_entities encode_html_entities
webify_plain_text webify_plain_text
check_list_setup check_list_setup
make_all_list_files make_all_list_files
Expand Down Expand Up @@ -1438,22 +1438,23 @@ sub make_safer {
} }


} }
sub convert_to_html_entities { sub encode_html_entities {


my $s = shift; my $s = shift;
my $unsafe_chars = shift || undef;


eval {require HTML::Entities}; eval {require HTML::Entities};
if(!$@){ if(!$@){


$s = HTML::Entities::encode_entities($s, "\200-\377" ); #, "\200-\377" $s = HTML::Entities::encode_entities($s, $unsafe_chars ); #, "\200-\377"


}else{ }else{
# require HTML::EntitiesPurePerl # require HTML::EntitiesPurePerl
# is our own module, based on HTML::Entities. # is our own module, based on HTML::Entities.
eval {require HTML::EntitiesPurePerl}; eval {require HTML::EntitiesPurePerl};
if(!$@){ if(!$@){


$s = HTML::EntitiesPurePerl::encode_entities($s, "\200-\377" ); #", \200-\377" $s = HTML::EntitiesPurePerl::encode_entities($s, $unsafe_chars); #", \200-\377"
} }
} }
# These are done by the above (if there's no argument in, encode_entities - right? # These are done by the above (if there's no argument in, encode_entities - right?
Expand Down Expand Up @@ -1487,7 +1488,7 @@ sub webify_plain_text {
# so, I use the below for Text Versions of HTML messages # so, I use the below for Text Versions of HTML messages


require HTML::FromText; require HTML::FromText;
$args->{-str} = convert_to_html_entities($args->{-str}); $args->{-str} = encode_html_entities($args->{-str}, "\200-\377");
$r = HTML::FromText::text2html($args->{-str}, $r = HTML::FromText::text2html($args->{-str},
metachars => 1, metachars => 1,
urls => 1, urls => 1,
Expand All @@ -1507,7 +1508,7 @@ sub webify_plain_text {
$multi_line = 1; $multi_line = 1;
} }


$args->{-str} = convert_to_html_entities($args->{-str}); $args->{-str} = encode_html_entities($args->{-str}, "\200-\377");


require HTML::TextToHTML; require HTML::TextToHTML;
my $conv = HTML::TextToHTML->new; my $conv = HTML::TextToHTML->new;
Expand Down
Loading

0 comments on commit 280b2ac

Please sign in to comment.