diff options
| author | fukachan <fukachan> | 2002-12-20 03:49:15 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2002-12-20 03:49:15 +0000 |
| commit | 11e81f65bb5de90e1490e18525639a3872dde8fb (patch) | |
| tree | 3771745aea3df25c932d0b5ae2e2a96408b31a0d /fml | |
| parent | 7af38788fffef7b5efca875d1601c26df2b09c7e (diff) | |
| download | fml8-11e81f65bb5de90e1490e18525639a3872dde8fb.tar.gz fml8-11e81f65bb5de90e1490e18525639a3872dde8fb.tar.bz2 fml8-11e81f65bb5de90e1490e18525639a3872dde8fb.zip | |
clean up.
+ define label or rename label to more appropriate one for loop.
+ use return().
+ use qw() if could.
use //o if could.
fix comments.
Diffstat (limited to 'fml')
| -rw-r--r-- | fml/lib/Mail/Bounce.pm | 44 | ||||
| -rw-r--r-- | fml/lib/Mail/Bounce/DSN.pm | 24 | ||||
| -rw-r--r-- | fml/lib/Mail/Bounce/Exim.pm | 7 | ||||
| -rw-r--r-- | fml/lib/Mail/Bounce/FixBrokenAddress.pm | 9 | ||||
| -rw-r--r-- | fml/lib/Mail/Bounce/GOO.pm | 3 | ||||
| -rw-r--r-- | fml/lib/Mail/Bounce/Postfix19991231.pm | 4 | ||||
| -rw-r--r-- | fml/lib/Mail/Bounce/Qmail.pm | 11 | ||||
| -rw-r--r-- | fml/lib/Mail/Bounce/SimpleMatch.pm | 20 | ||||
| -rw-r--r-- | fml/lib/Mail/Bounce/Smtpfeed.pm | 24 |
9 files changed, 86 insertions, 60 deletions
diff --git a/fml/lib/Mail/Bounce.pm b/fml/lib/Mail/Bounce.pm index 6c6a52a5..7f5b4e18 100644 --- a/fml/lib/Mail/Bounce.pm +++ b/fml/lib/Mail/Bounce.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Bounce.pm,v 1.21 2002/09/11 23:18:21 fukachan Exp $ +# $FML: Bounce.pm,v 1.22 2002/09/22 14:56:59 fukachan Exp $ # package Mail::Bounce; @@ -16,7 +16,7 @@ my $debug = 0; =head1 NAME -Mail::Bounce - analye error messages +Mail::Bounce - analyze error messages =head1 SYNOPSIS @@ -134,25 +134,26 @@ sub analyze print STDERR " ----- dump msg end -----\n"; } - for my $pkg ( - 'DSN', - 'Postfix19991231', - 'Qmail', - 'Exim', - 'GOO', - 'SimpleMatch', - ) { + MODEL: + for my $pkg (qw( + DSN + Postfix19991231 + Qmail + Exim + GOO + SimpleMatch + )) { my $module = "Mail::Bounce::$pkg"; print STDERR "\n --- module: $module\n" if $debug; eval qq { - require $module; $module->import(); + use $module; $module->analyze( \$msg , \$result ); }; croak($@) if $@; if (keys %$result) { print STDERR "\n match $module\n" if $debug; - last; + last MODEL; } if ($debug) { @@ -186,16 +187,19 @@ sub address_list =head2 C<status($addr)> return status (string) for C<$addr>. -The status is extracted from C<result> analyze() method gives. +The status can be extracted from C<result> analyze() method gives. =head2 C<reason($addr)> return error reason (string) for C<$addr>. -It is extracted from C<result> analyze() method gives. +It can be extracted from C<result> analyze() method gives. =cut +# XXX-TODO: hmm, we should prepare $addr->status() and $addr->reason() ? + + # Descriptions: return status (string) for $addr # Arguments: OBJ($self) STR($addr) # Side Effects: none @@ -276,11 +280,11 @@ sub look_like_japanese } -=head2 C<address_clean_up(type, addr)> +=head2 C<address_clean_up(hint, addr)> clean up C<addr> and return it. -C<type> gives a special hint for some specific MTA or domain. +C<hint> gives a special hint for some specific MTA or domain. It is rarely used. =cut @@ -314,11 +318,18 @@ sub address_clean_up # Mail::Bounce::FixBrokenAddress class provides irrgular # address handlings, so handles domain/MTA specific addresses. # For example, nifty.ne.jp, webtv.ne.jp, ... + # XXX-TODO: Mail::Bounce::FixBrokenAddress::FixIt is ugly. use Mail::Bounce::FixBrokenAddress; return Mail::Bounce::FixBrokenAddress::FixIt($hint, $addr); } +=head1 SECURITY CONSIDERATION + +The address returned by Mail::Bounce class may be unsafe. Please +validate it by some other class such as FML::Restriction class before +use it at some other place. + =head1 CODING STYLE See C<http://www.fml.org/software/FNF/> on fml coding style guide. @@ -343,3 +354,4 @@ See C<http://www.fml.org/> for more details. 1; + diff --git a/fml/lib/Mail/Bounce/DSN.pm b/fml/lib/Mail/Bounce/DSN.pm index 6ca97658..e0345501 100644 --- a/fml/lib/Mail/Bounce/DSN.pm +++ b/fml/lib/Mail/Bounce/DSN.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: DSN.pm,v 1.18 2002/09/11 23:18:22 fukachan Exp $ +# $FML: DSN.pm,v 1.19 2002/09/22 14:57:01 fukachan Exp $ # @@ -33,6 +33,8 @@ See C<Mail::Bounce> for more details. =head1 ERROR EXAMPLE +See RFC1894 on DSN (Delivery Status Notification) definition. + From: MAILER-DAEMON@ahodori.fml.org (Mail Delivery System) Subject: Undelivered Mail Returned to Sender To: fml-help-admin@ffs.fml.org @@ -61,7 +63,7 @@ See C<Mail::Bounce> for more details. Final-Recipient: rfc822; rudo@nuinui.net Action: failed Status: 4.0.0 - Diagnostic-Code: X-Postfix; connect to sv.nuinui.net[210.161.170.173]: + Diagnostic-Code: X-Postfix; connect to sv.nuinui.net[10.0.0.1]: Connection refused --C687D866E0.986737575/ahodori.fml.org @@ -107,7 +109,7 @@ sub analyze return undef; } - $result; + return $result; } @@ -143,15 +145,15 @@ sub _parse_dsn_format } # set up return buffer - if ($addr =~ /\@/) { + if ($addr =~ /\@/o) { $result->{ $addr }->{ 'Final-Recipient' } = $addr; - for ('Final-Recipient', - 'Original-Recipient', - 'Action', - 'Status', - 'Diagnostic-Code', - 'Reporting-MTA', - 'Received-From-MTA') { + for (qw(Final-Recipient + Original-Recipient + Action + Status + Diagnostic-Code + Reporting-MTA + Received-From-MTA)) { $result->{ $addr }->{ $_ } = $header->get($_) || undef; } $result->{ $addr }->{ 'hints' } = 'DSN'; diff --git a/fml/lib/Mail/Bounce/Exim.pm b/fml/lib/Mail/Bounce/Exim.pm index eb9020ee..e0463f99 100644 --- a/fml/lib/Mail/Bounce/Exim.pm +++ b/fml/lib/Mail/Bounce/Exim.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Exim.pm,v 1.8 2002/09/11 23:18:22 fukachan Exp $ +# $FML: Exim.pm,v 1.9 2002/09/22 14:57:01 fukachan Exp $ # @@ -39,12 +39,14 @@ See C<Mail::Bounce> for more details. =head1 TODO -need to guess MTA as "exim" ??? +We need to guess MTA as "exim", but how ? if (/^Message-ID:\s+\<[\w\d]+\-[\w\d]+\-[\w\d]+\@/i) { $MTA = "exim"; } +o.k. ? + =cut @@ -59,6 +61,7 @@ sub analyze my $addr = $m->get('X-Failed-Recipients'); # set up return buffer if $addr is found. + # XXX-TODO: we should use $self->address_clean_up() ? if ($addr) { $addr =~ s/\s*$//; $result->{ $addr }->{ 'Final-Recipient' } = $addr; diff --git a/fml/lib/Mail/Bounce/FixBrokenAddress.pm b/fml/lib/Mail/Bounce/FixBrokenAddress.pm index 20722061..e0ac8672 100644 --- a/fml/lib/Mail/Bounce/FixBrokenAddress.pm +++ b/fml/lib/Mail/Bounce/FixBrokenAddress.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: FixBrokenAddress.pm,v 1.7 2002/09/11 23:18:22 fukachan Exp $ +# $FML: FixBrokenAddress.pm,v 1.8 2002/09/22 14:57:01 fukachan Exp $ # @@ -21,7 +21,7 @@ my $debug = 0; =head1 NAME -Mail::Bounce::FixBrokenAddress - handles irregular error message +Mail::Bounce::FixBrokenAddress - handle irregular error message =head1 SYNOPSIS @@ -33,7 +33,6 @@ See C<Mail::Bounce> for more details. =head1 ERROR EXAMPLE - =cut @@ -50,12 +49,12 @@ sub FixIt } # error address from nifty.ne.jp has no domain part ;) - if ($hint eq 'nifty.ne.jp' && $addr !~ /\@/) { + if ($hint eq 'nifty.ne.jp' && $addr !~ /\@/o) { return( $addr . '@nifty.ne.jp' ); } # looks like URL for DB # e.g. errorperson?user-id=102624708&subscriber-id=94219786@webtv.ne.jp - elsif ($hint =~ /webtv.ne.jp/ && $addr =~ /\?/) { + elsif ($hint =~ /webtv.ne.jp/ && $addr =~ /\?/o) { if ($addr =~ /^(\S+)\?/) { return( $1 .'@webtv.ne.jp' ); } diff --git a/fml/lib/Mail/Bounce/GOO.pm b/fml/lib/Mail/Bounce/GOO.pm index 94259cdc..359ccc09 100644 --- a/fml/lib/Mail/Bounce/GOO.pm +++ b/fml/lib/Mail/Bounce/GOO.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: GOO.pm,v 1.7 2002/09/11 23:18:22 fukachan Exp $ +# $FML: GOO.pm,v 1.8 2002/09/22 14:57:01 fukachan Exp $ # @@ -54,6 +54,7 @@ sub analyze my $addr = $1; # set up return buffer if $addr is found. + # XXX-TODO: we should use $self->address_clean_up() ? if ($addr) { $addr =~ s/\s*$//; $result->{ $addr }->{ 'Final-Recipient' } = $addr; diff --git a/fml/lib/Mail/Bounce/Postfix19991231.pm b/fml/lib/Mail/Bounce/Postfix19991231.pm index 650e0137..58643e9b 100644 --- a/fml/lib/Mail/Bounce/Postfix19991231.pm +++ b/fml/lib/Mail/Bounce/Postfix19991231.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Postfix19991231.pm,v 1.19 2002/09/11 23:18:22 fukachan Exp $ +# $FML: Postfix19991231.pm,v 1.20 2002/09/22 14:57:01 fukachan Exp $ # @@ -32,6 +32,8 @@ subclass used in C<Mail::Bounce>. =head1 ERROR FORMAT +Postfix old style error format. + Date: Fri, 29 Jan 1999 15:05:06 +0900 (JST) From: MAILER-DAEMON@fml.org (Mail Delivery System) Subject: Undelivered Mail Returned to Sender diff --git a/fml/lib/Mail/Bounce/Qmail.pm b/fml/lib/Mail/Bounce/Qmail.pm index 596bb13a..ea25bf8e 100644 --- a/fml/lib/Mail/Bounce/Qmail.pm +++ b/fml/lib/Mail/Bounce/Qmail.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Qmail.pm,v 1.6 2002/09/11 23:18:22 fukachan Exp $ +# $FML: Qmail.pm,v 1.7 2002/09/22 14:57:01 fukachan Exp $ # @@ -39,8 +39,8 @@ format), as describbed in sub analyze { my ($self, $msg, $result) = @_; - my $state = 0; - my $pattern = 'Hi. This is the'; + my $state = 0; + my $pattern = 'Hi. This is the'; my $end_pattern = '--- Undelivered message follows ---'; # search data @@ -48,7 +48,7 @@ sub analyze my $m = $msg->{ next }; do { if (defined $m) { - my $num = $m->num_paragraph; + my $num = $m->num_paragraph; for ( my $i = 0; $i < $num ; $i++ ) { my $data = $m->nth_paragraph( $i + 1 ); @@ -60,6 +60,8 @@ sub analyze if ($data =~ /\<(\S+\@\S+)\>:\s*(.*)/) { ($addr, $reason) = ($1, $2); + # XXX-TODO: we should use $self->address_clean_up() ? + my $status = '5.x.y'; if ($data =~ /\#(\d+\.\d+\.\d+)/) { $status = $1; @@ -70,7 +72,6 @@ sub analyze $status = '4.x.y' if $code =~ /^4/; } - $result->{ $addr }->{ 'Diagnostic-Code' } = $reason; $result->{ $addr }->{ 'Status' } = $status; $result->{ $addr }->{ 'hints' } = 'qmail'; diff --git a/fml/lib/Mail/Bounce/SimpleMatch.pm b/fml/lib/Mail/Bounce/SimpleMatch.pm index 1680a71e..ddcf2b42 100644 --- a/fml/lib/Mail/Bounce/SimpleMatch.pm +++ b/fml/lib/Mail/Bounce/SimpleMatch.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: SimpleMatch.pm,v 1.30 2002/09/11 23:18:22 fukachan Exp $ +# $FML: SimpleMatch.pm,v 1.31 2002/09/22 14:57:01 fukachan Exp $ # @@ -22,7 +22,7 @@ use Mail::Bounce::Language::Japanese; =head1 NAME -Mail::Bounce::SimpleMatch - SimpleState error message format parser +Mail::Bounce::SimpleMatch - simple state machine to parse error messages =head1 SYNOPSIS @@ -179,6 +179,7 @@ sub analyze my $n = $m->num_paragraph; if ($debug) { print STDERR " num_paragraph: $n\n";} + PARAGRAPH: for (my $i = 0; $i < $n; $i++) { my $buf = $m->nth_paragraph($i + 1); # 1 not 0 for 1st paragraph $args->{ buf } = \$buf; @@ -193,7 +194,7 @@ sub analyze } # we found the mark of "end of error message part". - last if $self->_reach_end($args); + last PARAGRAPH if $self->_reach_end($args); } } else { @@ -212,8 +213,9 @@ sub _reach_end my $result = $args->{ result }; my $rbuf = $args->{ buf }; + REGEXP: for my $mta_type (keys %$address_trap_regexp) { - next unless $mta_type; + next REGEXP unless $mta_type; my $end_regexp = $address_trap_regexp->{ $mta_type }->{ 'end' }; if ($end_regexp && ($$rbuf =~ /$end_regexp/)) { @@ -222,15 +224,15 @@ sub _reach_end } } - 0; + return 0; } -# Descriptions: trap address in error message +# Descriptions: trap address in error message. # our state check is applied to each paragraph # not the whole body. # Arguments: OBJ($self) HASH_REF($args) -# Side Effects: update $result +# Side Effects: update $result and state in $args if found. # Return Value: none sub _address_match { @@ -239,8 +241,9 @@ sub _address_match my $rbuf = $args->{ buf }; unless ($args->{ state }) { + REGEXP: for my $mta_type (keys %$address_trap_regexp) { - next unless $mta_type; + next REGEXP unless $mta_type; my $start_regexp = $address_trap_regexp->{ $mta_type }->{'start'}; if ($$rbuf =~ /$start_regexp/) { @@ -266,6 +269,7 @@ sub _address_match for (@buf) { print STDERR "scan($args->{ mta_type })|state=$args->{state}> $_\n" if $debug; + # XXX in some cases, $end_regexp not defined. last SCAN if $end_regexp && /$end_regexp/; if (/(\S+\@\S+)/) { diff --git a/fml/lib/Mail/Bounce/Smtpfeed.pm b/fml/lib/Mail/Bounce/Smtpfeed.pm index bd7e5d85..69b44f93 100644 --- a/fml/lib/Mail/Bounce/Smtpfeed.pm +++ b/fml/lib/Mail/Bounce/Smtpfeed.pm @@ -1,10 +1,10 @@ #-*- perl -*- # -# Copyright (C) 2001 Ken'ichi Fukamachi +# Copyright (C) 2001,2002 Ken'ichi Fukamachi # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: Smtpfeed.pm,v 1.5 2002/09/11 23:18:23 fukachan Exp $ +# $FML: Smtpfeed.pm,v 1.6 2002/09/22 14:57:01 fukachan Exp $ # @@ -47,22 +47,24 @@ sub analyze my ($self, $msg, $result) = @_; my $m = $msg->find( { data_type => 'message/rfc822' } ); my $header = $m->nth_paragraph( 1 ); - my $addr; + my $addr = ''; # - # XXX code below is correct ? + # XXX-TODO: code below is correct ? # if ($header =~ /^To: \(original recipient in envelope at \S+\) <(\S+)>/) { $addr = $1; + $addr =~ s/\s*$//; + + if ($addr) { + # set up return buffer + $result->{ $addr }->{ 'Final-Recipient' } = $addr; + $result->{ $addr }->{ 'Status' } = '5.x.y'; + $result->{ $addr }->{ 'hints' } = 'smtpfeed'; + } } - $addr =~ s/\s*$//; - - # set up return buffer - $result->{ $addr }->{ 'Final-Recipient' } = $addr; - $result->{ $addr }->{ 'Status' } = '5.x.y'; - $result->{ $addr }->{ 'hints' } = 'smtpfeed'; } @@ -76,7 +78,7 @@ Ken'ichi Fukamachi =head1 COPYRIGHT -Copyright (C) 2001 Ken'ichi Fukamachi +Copyright (C) 2001,2002 Ken'ichi Fukamachi All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
