import rt 3.4.5
[freeside.git] / rt / lib / RT / Interface / Email.pm
index 5db7c8a..efc4c26 100755 (executable)
@@ -56,7 +56,7 @@ BEGIN {
     use vars qw ($VERSION  @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
     
     # set the version for version checking
-    $VERSION = do { my @r = (q$Revision: 1.1.1.5 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
+    $VERSION = do { my @r = (q$Revision: 1.1.1.6 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker
     
     @ISA         = qw(Exporter);
     
@@ -68,6 +68,7 @@ BEGIN {
               &CheckForLoops 
               &CheckForSuspiciousSender
               &CheckForAutoGenerated 
+              &CheckForBounce 
               &MailError 
               &ParseCcAddressesFromHead
               &ParseSenderAddressFromHead 
@@ -171,6 +172,16 @@ sub CheckForAutoGenerated {
 
 # }}}
 
+# {{{ sub CheckForBounce
+sub CheckForBounce {
+    my $head = shift;
+   
+    my $ReturnPath = $head->get("Return-path") || "" ;
+    return ($ReturnPath =~ /<>/);
+}
+
+# }}}
+
 # {{{ IsRTAddress
 
 =head2 IsRTAddress ADDRESS
@@ -187,7 +198,7 @@ sub IsRTAddress {
     # Example: the following rule would tell RT not to Cc 
     #   "tickets@noc.example.com"
     if ( defined($RT::RTAddressRegexp) &&
-                       $address =~ /$RT::RTAddressRegexp/ ) {
+                       $address =~ /$RT::RTAddressRegexp/i ) {
         return(1);
     } else {
         return (undef);
@@ -250,7 +261,7 @@ sub MailError {
     }
 
     if ($RT::MailCommand eq 'sendmailpipe') {
-        open (MAIL, "|$RT::SendmailPath $RT::SendmailArguments") || return(0);
+        open (MAIL, "|$RT::SendmailPath $RT::SendmailBounceArguments $RT::SendmailArguments") || return(0);
         print MAIL $entity->as_string;
         close(MAIL);
     }
@@ -378,7 +389,8 @@ sub ParseSenderAddressFromHead {
 =head2 ParseErrorsToAddressFromHead
 
 Takes a MIME::Header object. Return a single value : user@host
-of the From (evaluated in order of Errors-To:,Reply-To:, From:, Sender)
+of the From (evaluated in order of Return-path:,Errors-To:,Reply-To:,
+From:, Sender)
 
 =cut
 
@@ -386,7 +398,7 @@ sub ParseErrorsToAddressFromHead {
     my $head = shift;
     #Figure out who's sending this message.
 
-    foreach my $header ('Errors-To' , 'Reply-To', 'From', 'Sender' ) {
+    foreach my $header ('Return-path', 'Errors-To' , 'Reply-To', 'From', 'Sender' ) {
        # If there's a header of that name
        my $headerobj = $head->get($header);
        if ($headerobj) {
@@ -436,7 +448,7 @@ sub ParseTicketId {
     my $Subject = shift;
     my $id;
 
-    my $test_name = $RT::EmailSubjectTagRegex || qr/\Q$RT::rtname\E/;
+    my $test_name = $RT::EmailSubjectTagRegex || qr/\Q$RT::rtname\E/i;
 
     if ( $Subject =~ s/\[$test_name\s+\#(\d+)\s*\]//i ) {
         my $id = $1;
@@ -655,6 +667,8 @@ EOT
     # }}}
 
     # {{{ Lets check for mail loops of various sorts.
+    my $IsBounce = CheckForBounce($head);
+
     my $IsAutoGenerated = CheckForAutoGenerated($head);
 
     my $IsSuspiciousSender = CheckForSuspiciousSender($head);
@@ -665,7 +679,7 @@ EOT
 
     #If the message is autogenerated, we need to know, so we can not
     # send mail to the sender
-    if ( $IsSuspiciousSender || $IsAutoGenerated || $IsALoop ) {
+    if ( $IsBounce || $IsSuspiciousSender || $IsAutoGenerated || $IsALoop ) {
         $SquelchReplies = 1;
         $ErrorsTo       = $RT::OwnerEmail;
     }