[Rt-commit] rt branch, allow-loops, updated. rt-3.8.5-300-g154c62b

Alex Vandiver alexmv at bestpractical.com
Wed May 5 11:59:40 EDT 2010


The branch, allow-loops has been updated
       via  154c62b2907289441d5f42b3fa57fb2c55bea4c7 (commit)
      from  139774c80c77d943e543a145ecf6de342fb217d0 (commit)

Summary of changes:
 lib/RT/Interface/Email.pm |    9 ++++--
 t/mail/linkselfloops.t    |   67 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 68 insertions(+), 8 deletions(-)

- Log -----------------------------------------------------------------
commit 154c62b2907289441d5f42b3fa57fb2c55bea4c7
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed May 5 11:56:08 2010 -0400

    If self-loop mail ends back at the same queue, drop it
    
    This fixes a bug caused by ParseNewMessageForTicketCcs, where sending
    mail to an alias for a queue caused later correspondence to create
    mail loops.

diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index 17cc78a..d5f48ac 100755
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -1456,9 +1456,12 @@ sub Gateway {
         if ( $action =~ /^(?:comment|correspond)$/i ) {
 
             # Check if this is an internal self-loop
-            if (    $Ticket->QueueObj->Id != $SystemQueueObj->Id
-                and $IsALoop < 0 )
-            {
+            if ( $IsALoop < 0 ) {
+                # If mail from ourselves somehow ended back in the
+                # _same_ queue, then it's a true loop -- drop it on
+                # the floor
+                next if $Ticket->QueueObj->Id == $SystemQueueObj->Id;
+
                 my @ret = LinkSelfLoops(
                     Ticket      => $Ticket,
                     QueueObj    => $SystemQueueObj,
diff --git a/t/mail/linkselfloops.t b/t/mail/linkselfloops.t
index 0aa13a8..5bfe9b5 100644
--- a/t/mail/linkselfloops.t
+++ b/t/mail/linkselfloops.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test config => 'Set( $LinkSelfLoops, 1 );', 'no_plan' => 1;
+use RT::Test config => 'Set( $LinkSelfLoops, 1 ); Set ($ParseNewMessageForTicketCcs, 1 );', 'no_plan' => 1;
 
 RT::Test->set_mail_catcher;
 my ($baseurl, $m) = RT::Test->started_ok;
@@ -64,11 +64,12 @@ sub parse_mail {
 sub reinsert {
     my $text = shift;
     my $mime = parse_mail($text);
-    return (0, 0) unless ($mime->head->get("To")||"") =~ /(helpdesk|systems)(?:-(comment))?\@example\.com/
-        or ($mime->head->get("Cc")||"") =~ /(helpdesk|systems)(?:-(comment))?\@example\.com/
-        or ($mime->head->get("Bcc")||"") =~ /(helpdesk|systems)(?:-(comment))?\@example\.com/;
+    return (0, 0) unless ($mime->head->get("To")||"") =~ /(helpdesk|systems|alias)(?:-(comment))?\@example\.com/
+        or ($mime->head->get("Cc")||"") =~ /(helpdesk|systems|alias)(?:-(comment))?\@example\.com/
+        or ($mime->head->get("Bcc")||"") =~ /(helpdesk|systems|alias)(?:-(comment))?\@example\.com/;
 
     my ($queue, $action) = (ucfirst($1), $2 || "correspond");
+    $queue = "Helpdesk" if $queue eq "Alias";
     return RT::Test->send_via_mailgate( $text, queue => $queue, action => $action );
 }
 
@@ -123,6 +124,7 @@ sub record_ok {
     ok($id, "Added $method on @{[$ticket->Id]} as @{[$args{as}->EmailAddress]})");
 }
 
+
 # =====> SITUATION 1:  Helpdesk queue adds systems@ as a one-time cc on a
 # comment (helpdesk gets all correspondence from systems, as a comment;  
 # systems only gets mail explicitly one-time-CC'd to them)
@@ -541,11 +543,18 @@ EOF
         },
     );
 
-    #   which notifies Sven and AdminCCs on #302
+    #   which notifies Sven and AdminCCs on #302 -- as well as Joe,
+    #   since he was added as a Cc on creation because of
+    #   ParseNewMessageForTicketCcs.  This is unwanted but unavoidable
+    #   in this configuration.
     got_mail_ok(
         {   from => qr/systems\@/,
             bcc  => qr/sven\@/,
         },
+        {
+            from => qr/systems\@/,
+            cc   => qr/joe\@/,
+        }
     );
 
 }
@@ -747,3 +756,51 @@ EOF
     #   which notifies Sven and AdminCCs on #502
     # (see above note about looping)
 }
+
+# ======> SITUATION 6: Mail is sent to alias@, which contains
+# helpdesk@; $ParseNewMessageForTicketCcs is enabled, so alias@ is
+# added as a CC: Further correspondence on the ticket should not loop
+# back to itself.
+
+{
+    # Joe sends mail to helpdesk@
+    my $text = <<EOF;
+From: joe\@example.com
+To: alias\@example.com
+Subject: This is a test of aliases
+Message-Id: sixth\@example.com
+
+A helpdesk ticket to an alias
+EOF
+
+    my ($status, $id) = RT::Test->send_via_mailgate($text, queue => 'Helpdesk');
+    is ($status >> 8, 0, "The mail gateway exited normally");
+    ok ($id, "Created ticket");
+    my ($helpticket) = ($id);
+
+    # Sends mail back to Joe, and to Bjoern
+    got_mail_ok(
+        { to => qr/joe\@/, },
+        { bcc => qr/bjoern\@/, },
+    );
+
+    # Ticket #601 is created in the helpdesk queue with joe as the requestor
+    my $ticket = RT::Test->last_ticket( $bjoern );
+    isa_ok ($ticket, 'RT::Ticket');
+    is ($ticket->Id, $id, "correct ticket id");
+    is ($ticket->Subject , 'This is a test of aliases', "Created the ticket");
+
+    # Bjoern adds a correspondence on #601
+    record_ok( mode => 'correspond', on => $helpticket, as => $bjoern );
+
+    # Should generate mail to Joe, and alias@
+    got_mail_ok(
+        {   to => qr/joe\@/,
+            cc => qr/alias\@/,
+        },
+    );
+
+    # The last got_mail to alias@ should have reinserted a mail, but
+    # that shouldn't have generated anything
+    got_mail_ok();
+}

-----------------------------------------------------------------------


More information about the Rt-commit mailing list