[Rt-commit] rt branch, 4.2/sendmail-action-logs, created. rt-4.0.7-337-g90aa836

Alex Vandiver alexmv at bestpractical.com
Thu Oct 25 23:34:00 EDT 2012


The branch, 4.2/sendmail-action-logs has been created
        at  90aa83610eae46b01f39a5e47aafdf9366956fb1 (commit)

- Log -----------------------------------------------------------------
commit 6d83608f2a89708246a28460659631efb1c9a6c9
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 9 14:49:36 2011 +0400

    save lengthy call into a variable

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index b85d6d1..d8319e2 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -764,7 +764,9 @@ sub RemoveInappropriateRecipients {
             # caused by one of the watcher addresses being broken.
             # Default ("true") is to redistribute, for historical reasons.
 
-            if ( !RT->Config->Get('RedistributeAutoGeneratedMessages') ) {
+            my $redistribute = RT->Config->Get('RedistributeAutoGeneratedMessages');
+
+            if ( !$redistribute ) {
 
                 # Don't send to any watchers.
                 @{ $self->{$_} } = () for (@EMAIL_RECIPIENT_HEADERS);
@@ -772,9 +774,7 @@ sub RemoveInappropriateRecipients {
                         . " The incoming message was autogenerated. "
                         . "Not redistributing this message based on site configuration."
                 );
-            } elsif ( RT->Config->Get('RedistributeAutoGeneratedMessages') eq
-                'privileged' )
-            {
+            } elsif ( $redistribute eq 'privileged' ) {
 
                 # Only send to "privileged" watchers.
                 foreach my $type (@EMAIL_RECIPIENT_HEADERS) {

commit 25cc795911158d44e9b31e8e138adbb8a86685e4
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 9 14:50:21 2011 +0400

    don't use split for addresses, use parser

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index d8319e2..f9b00e3 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -792,7 +792,7 @@ sub RemoveInappropriateRecipients {
         }
 
         if ( my $squelch = $attachment->GetHeader('RT-Squelch-Replies-To') ) {
-            push @blacklist, split( /,/, $squelch );
+            push @blacklist, map $_->address, Email::Address->parse( $squelch );
         }
     }
 

commit 258bbc27a30641ae7bc7f7123d9e6b8bc5e67832
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 9 15:17:08 2011 +0400

    turn blacklist into a hash with reasons
    
    * to make log clearer about why we blacklist recipients
    * make sure we use case insensitive email comparision

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index f9b00e3..33566a6 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -750,7 +750,7 @@ Remove addresses that are RT addresses or that are on this transaction's blackli
 sub RemoveInappropriateRecipients {
     my $self = shift;
 
-    my @blacklist = ();
+    my %blacklist = ();
 
     # If there are no recipients, don't try to send the message.
     # If the transaction has content and has the header RT-Squelch-Replies-To
@@ -781,7 +781,8 @@ sub RemoveInappropriateRecipients {
                     foreach my $addr ( @{ $self->{$type} } ) {
                         my $user = RT::User->new(RT->SystemUser);
                         $user->LoadByEmail($addr);
-                        push @blacklist, $addr unless $user->id && $user->Privileged;
+                        $blacklist{ $addr } ||= 'not privileged'
+                            unless $user->id && $user->Privileged;
                     }
                 }
                 $RT::Logger->info( $msgid
@@ -792,20 +793,27 @@ sub RemoveInappropriateRecipients {
         }
 
         if ( my $squelch = $attachment->GetHeader('RT-Squelch-Replies-To') ) {
-            push @blacklist, map $_->address, Email::Address->parse( $squelch );
+            $blacklist{ $_->address } ||= 'squelch:attachment'
+                foreach Email::Address->parse( $squelch );
         }
     }
 
-    # Let's grab the SquelchMailTo attributes and push those entries into the @blacklisted
-    push @blacklist, map $_->Content, $self->TicketObj->SquelchMailTo, $self->TransactionObj->SquelchMailTo;
-
-    # Cycle through the people we're sending to and pull out anyone on the
-    # system blacklist
-
-    # Trim leading and trailing spaces. 
-    @blacklist = map { RT::User->CanonicalizeEmailAddress( $_->address ) }
-        Email::Address->parse( join ', ', grep defined, @blacklist );
+    # Let's grab the SquelchMailTo attributes and push those entries
+    # into the blacklisted
+    $blacklist{ $_->Content } ||= 'squelch:transaction'
+        foreach $self->TransactionObj->SquelchMailTo;
+    $blacklist{ $_->Content } ||= 'squelch:ticket'
+        foreach $self->TicketObj->SquelchMailTo;
+
+    # canonicalize emails
+    foreach my $address ( keys %blacklist ) {
+        my $reason = delete $blacklist{ $address };
+        $blacklist{ lc $_ } = $reason
+            foreach map RT::User->CanonicalizeEmailAddress( $_->address ),
+            Email::Address->parse( $address );
+    }
 
+    # Cycle through the people we're sending to and pull out anyone on the blacklist
     foreach my $type (@EMAIL_RECIPIENT_HEADERS) {
         my @addrs;
         foreach my $addr ( @{ $self->{$type} } ) {
@@ -816,7 +824,7 @@ sub RemoveInappropriateRecipients {
                 $RT::Logger->info( $msgid . "$addr appears to point to this RT instance. Skipping" );
                 next;
             }
-            if ( grep $addr eq $_, @blacklist ) {
+            if ( $blacklist{ lc $addr } ) {
                 $RT::Logger->info( $msgid . "$addr was blacklisted for outbound mail on this transaction. Skipping");
                 next;
             }

commit 1c80214285726b8450cf9fb095e13860ff69712c
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Sep 9 16:58:12 2011 +0400

    explain in logs why email is in blacklist

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index 33566a6..e916f9e 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -747,6 +747,17 @@ Remove addresses that are RT addresses or that are on this transaction's blackli
 
 =cut
 
+my %squelch_reasons = (
+    'not privileged' => "as user is not privileged, not redistributing autogenerated message",
+    'squelch:attachment'
+        => "by RT-Squelch-Replies-To header in the incoming message",
+    'squelch:transaction'
+        => "by squelch settings for this transaction only",
+    'squelch:ticket'
+        => "by squelch settings for this ticket",
+);
+
+
 sub RemoveInappropriateRecipients {
     my $self = shift;
 
@@ -824,8 +835,8 @@ sub RemoveInappropriateRecipients {
                 $RT::Logger->info( $msgid . "$addr appears to point to this RT instance. Skipping" );
                 next;
             }
-            if ( $blacklist{ lc $addr } ) {
-                $RT::Logger->info( $msgid . "$addr was blacklisted for outbound mail on this transaction. Skipping");
+            if ( my $reason = $blacklist{ lc $addr } ) {
+                $RT::Logger->info( $msgid . " $addr is blacklisted $squelch_reasons{ $reason }. Skipping" );
                 next;
             }
             push @addrs, $addr;

commit 13e3659c872d5c6a17da7569b08e65812146b9fa
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Mar 23 17:03:43 2012 -0400

    Make messages more verbose and actionable

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index e916f9e..824de00 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -748,13 +748,14 @@ Remove addresses that are RT addresses or that are on this transaction's blackli
 =cut
 
 my %squelch_reasons = (
-    'not privileged' => "as user is not privileged, not redistributing autogenerated message",
+    'not privileged'
+        => "because autogenerated messages are configured to only be sent to privileged users (RedistributeAutoGeneratedMessages)",
     'squelch:attachment'
         => "by RT-Squelch-Replies-To header in the incoming message",
     'squelch:transaction'
-        => "by squelch settings for this transaction only",
+        => "by notification checkboxes for this transaction",
     'squelch:ticket'
-        => "by squelch settings for this ticket",
+        => "by notification checkboxes on this ticket's People page",
 );
 
 

commit a2af4627c9db87db35c2187fbe386fcfedf2147c
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Mar 23 16:47:56 2012 -0400

    Remove the trailing newline from the msgid before logging using it

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index 824de00..940f007 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -768,6 +768,8 @@ sub RemoveInappropriateRecipients {
     # If the transaction has content and has the header RT-Squelch-Replies-To
 
     my $msgid = $self->TemplateObj->MIMEObj->head->get('Message-Id');
+    chomp $msgid;
+
     if ( my $attachment = $self->TransactionObj->Attachments->First ) {
 
         if ( $attachment->GetHeader('RT-DetectedAutoGenerated') ) {

commit 50c5df9e8f32ab928a1df630c69c5a15fb0f383e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Mar 23 16:48:58 2012 -0400

    Refactor RemoveInappropriateRecipients to use a callback interface
    
    This allows other subclasses to add their own particular cases for why
    an address should be skipped, by overriding
    RemoveInappropriateRecipients to call an additional RecipientFilter.

diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index 940f007..3b0ceca 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -827,35 +827,68 @@ sub RemoveInappropriateRecipients {
             Email::Address->parse( $address );
     }
 
-    # Cycle through the people we're sending to and pull out anyone on the blacklist
-    foreach my $type (@EMAIL_RECIPIENT_HEADERS) {
+    $self->RecipientFilter(
+        Callback => sub {
+            return unless RT::EmailParser->IsRTAddress( $_[0] );
+            return "$_[0] appears to point to this RT instance. Skipping";
+        },
+        All => 1,
+    );
+
+    $self->RecipientFilter(
+        Callback => sub {
+            return unless $blacklist{ lc $_[0] };
+            return "$_[0] is blacklisted $squelch_reasons{ $blacklist{ lc $_[0] } }. Skipping";
+        },
+    );
+
+
+    # Cycle through the people we're sending to and pull out anyone that meets any of the callbacks
+    for my $type (@EMAIL_RECIPIENT_HEADERS) {
         my @addrs;
-        foreach my $addr ( @{ $self->{$type} } ) {
 
-         # Weed out any RT addresses. We really don't want to talk to ourselves!
-         # If we get a reply back, that means it's not an RT address
-            if ( !RT::EmailParser->CullRTAddresses($addr) ) {
-                $RT::Logger->info( $msgid . "$addr appears to point to this RT instance. Skipping" );
-                next;
-            }
-            if ( my $reason = $blacklist{ lc $addr } ) {
-                $RT::Logger->info( $msgid . " $addr is blacklisted $squelch_reasons{ $reason }. Skipping" );
-                next;
+      ADDRESS:
+        for my $addr ( @{ $self->{$type} } ) {
+            for my $filter ( map {$_->{Callback}} @{$self->{RecipientFilter}} ) {
+                my $skip = $filter->($addr);
+                next unless $skip;
+                $RT::Logger->info( "$msgid $skip" );
+                next ADDRESS;
             }
             push @addrs, $addr;
         }
-        foreach my $addr ( @{ $self->{'NoSquelch'}{$type} || [] } ) {
-            # never send email to itself
-            if ( !RT::EmailParser->CullRTAddresses($addr) ) {
-                $RT::Logger->info( $msgid . "$addr appears to point to this RT instance. Skipping" );
-                next;
+
+      NOSQUELCH_ADDRESS:
+        for my $addr ( @{ $self->{NoSquelch}{$type} } ) {
+            for my $filter ( map {$_->{Callback}} grep {$_->{All}} @{$self->{RecipientFilter}} ) {
+                my $skip = $filter->($addr);
+                next unless $skip;
+                $RT::Logger->info( "$msgid $skip" );
+                next NOSQUELCH_ADDRESS;
             }
             push @addrs, $addr;
         }
+
         @{ $self->{$type} } = @addrs;
     }
 }
 
+=head2 RecipientFilter Callback => SUB, [All => 1]
+
+Registers a filter to be applied to addresses by
+L<RemoveInappropriateRecipients>.  The C<Callback> will be called with
+one address at a time, and should return false if the address should
+receive mail, or a message explaining why it should not be.  Passing a
+true value for C<All> will cause the filter to also be applied to
+NoSquelch (one-time Cc and Bcc) recipients as well.
+
+=cut
+
+sub RecipientFilter {
+    my $self = shift;
+    push @{ $self->{RecipientFilter}}, {@_};
+}
+
 =head2 SetReturnAddress is_comment => BOOLEAN
 
 Calculate and set From and Reply-To headers based on the is_comment flag.

commit 8a25085403b7e30cc29fd7cb12690d8979567009
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Mar 23 16:50:18 2012 -0400

    Use RecipientFilter to provide a log message when NotifyActor kicks in

diff --git a/lib/RT/Action/Notify.pm b/lib/RT/Action/Notify.pm
index f1aef40..c8a8500 100644
--- a/lib/RT/Action/Notify.pm
+++ b/lib/RT/Action/Notify.pm
@@ -131,24 +131,9 @@ sub SetRecipients {
         }
     }
 
-    my $creatorObj = $self->TransactionObj->CreatorObj;
-    my $creator = $creatorObj->EmailAddress() || '';
-
-    #Strip the sender out of the To, Cc and AdminCc and set the 
-    # recipients fields used to build the message by the superclass.
-    # unless a flag is set 
-    my $TransactionCurrentUser = RT::CurrentUser->new;
-    $TransactionCurrentUser->LoadByName($creatorObj->Name);
-    if (RT->Config->Get('NotifyActor',$TransactionCurrentUser)) {
-        @{ $self->{'To'} }  = @To;
-        @{ $self->{'Cc'} }  = @Cc;
-        @{ $self->{'Bcc'} } = @Bcc;
-    }
-    else {
-        @{ $self->{'To'} }  = grep ( lc $_ ne lc $creator, @To );
-        @{ $self->{'Cc'} }  = grep ( lc $_ ne lc $creator, @Cc );
-        @{ $self->{'Bcc'} } = grep ( lc $_ ne lc $creator, @Bcc );
-    }
+    @{ $self->{'To'} }       = @To;
+    @{ $self->{'Cc'} }       = @Cc;
+    @{ $self->{'Bcc'} }      = @Bcc;
     @{ $self->{'PseudoTo'} } = @PseudoTo;
 
     if ( $arg =~ /\bOtherRecipients\b/ ) {
@@ -161,6 +146,24 @@ sub SetRecipients {
     }
 }
 
+sub RemoveInappropriateRecipients {
+    my $self = shift;
+
+    my $creatorObj = $self->TransactionObj->CreatorObj;
+    my $creator = $creatorObj->EmailAddress() || '';
+    my $TransactionCurrentUser = RT::CurrentUser->new;
+    $TransactionCurrentUser->LoadByName($creatorObj->Name);
+
+    $self->RecipientFilter(
+        Callback => sub {
+            return unless lc $_[0] eq lc $creator;
+            return "not sending to $creator, creator of the transaction, due to NotifyActor setting";
+        },
+    ) unless RT->Config->Get('NotifyActor',$TransactionCurrentUser);
+
+    $self->SUPER::RemoveInappropriateRecipients();
+}
+
 RT::Base->_ImportOverlays();
 
 1;

commit 8715d68c46a2536a969acc0b8ff71289b2dd386a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Oct 25 23:25:37 2012 -0400

    Rewrite test to use terser RT::Test::Email mail_ok method

diff --git a/t/mail/one-time-recipients.t b/t/mail/one-time-recipients.t
index 985f955..5162802 100644
--- a/t/mail/one-time-recipients.t
+++ b/t/mail/one-time-recipients.t
@@ -3,7 +3,8 @@ use strict;
 use warnings;
 use utf8;
 
-use RT::Test tests => 38;
+use RT::Test tests => undef;
+use RT::Test::Email;
 
 my $queue = RT::Test->load_or_create_queue(
     Name              => 'General',
@@ -21,189 +22,118 @@ ok $user && $user->id, 'loaded or created user';
 diag "Reply to ticket with actor as one time cc";
 {
     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
-    my ($status, undef, $msg) = $ticket->Create(
-        Queue => $queue->id,
-        Subject => 'test',
-        Requestor => 'root at localhost',
-    );
-    ok $status, "created ticket";
-
-    my @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('To');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'root at localhost', 'got mail'
-    }
+    mail_ok {
+        my ($status, undef, $msg) = $ticket->Create(
+            Queue => $queue->id,
+            Subject => 'test',
+            Requestor => 'root at localhost',
+        );
+        ok $status, "created ticket";
+    } { To => 'root at localhost' };
 
     RT->Config->Set( NotifyActor => 1 );
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('To');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'root at localhost', 'got mail'
-    }
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+        );
+        ok $status, "replied to a ticket";
+    } { To => 'root at localhost' };
 
     RT->Config->Set( NotifyActor => 0 );
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok !@mails, "no mail - don't notify actor";
-
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-        CcMessageTo => 'root at localhost',
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('Cc');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'root at localhost', 'got mail'
-    }
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+        );
+        ok $status, "replied to a ticket";
+    };
+
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+            CcMessageTo => 'root at localhost',
+        );
+        ok $status, "replied to a ticket";
+    } { Cc => 'root at localhost' };
 }
 
 diag "Reply to ticket with requestor squelched";
 {
     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
-    my ($status, undef, $msg) = $ticket->Create(
-        Queue => $queue->id,
-        Subject => 'test',
-        Requestor => 'test at localhost',
-    );
-    ok $status, "created ticket";
-
-    my @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('To');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'test at localhost', 'got mail'
-    }
-
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('To');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'test at localhost', 'got mail'
-    }
+    mail_ok {
+        my ($status, undef, $msg) = $ticket->Create(
+            Queue => $queue->id,
+            Subject => 'test',
+            Requestor => 'test at localhost',
+        );
+        ok $status, "created ticket";
+    } { To => 'test at localhost' };
+
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+        );
+        ok $status, "replied to a ticket";
+    } { To => 'test at localhost' };
 
     $ticket->SquelchMailTo('test at localhost');
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok !@mails, "no mail - squelched";
-
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-        CcMessageTo => 'test at localhost',
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('Cc');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'test at localhost', 'got mail'
-    }
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+        );
+        ok $status, "replied to a ticket";
+    };
+
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+            CcMessageTo => 'test at localhost',
+        );
+        ok $status, "replied to a ticket";
+    } { Cc => 'test at localhost' };
 }
 
 diag "Reply to ticket with requestor squelched";
 {
     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
-    my ($status, undef, $msg) = $ticket->Create(
-        Queue => $queue->id,
-        Subject => 'test',
-        Requestor => 'test at localhost',
-    );
-    ok $status, "created ticket";
-
-    my @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('To');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'test at localhost', 'got mail'
-    }
-
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('To');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'test at localhost', 'got mail'
-    }
-
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-        SquelchMailTo => ['test at localhost'],
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok !@mails, "no mail - squelched";
-
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('To');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'test at localhost', 'got mail'
-    }
-
-    ($status, $msg) = $ticket->Correspond(
-        Content => 'test mail',
-        CcMessageTo => 'test at localhost',
-        SquelchMailTo => ['test at localhost'],
-    );
-    ok $status, "replied to a ticket";
-
-    @mails = RT::Test->fetch_caught_mails;
-    ok @mails, "got some outgoing emails";
-    foreach my $mail ( @mails ) {
-        my $entity = parse_mail( $mail );
-        my $to = $entity->head->get('Cc');
-        $to =~ s/^\s+|\s+$//; 
-        is $to, 'test at localhost', 'got mail'
-    }
+    mail_ok {
+        my ($status, undef, $msg) = $ticket->Create(
+            Queue => $queue->id,
+            Subject => 'test',
+            Requestor => 'test at localhost',
+        );
+        ok $status, "created ticket";
+    } { To => 'test at localhost' };
+
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+        );
+        ok $status, "replied to a ticket";
+    } { To => 'test at localhost' };
+
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+            SquelchMailTo => ['test at localhost'],
+        );
+        ok $status, "replied to a ticket";
+    };
+
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+        );
+        ok $status, "replied to a ticket";
+    } { To => 'test at localhost' };
+
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+            CcMessageTo => 'test at localhost',
+            SquelchMailTo => ['test at localhost'],
+        );
+        ok $status, "replied to a ticket";
+    }  { Cc => 'test at localhost' };
 }
+
+done_testing;

commit cfeae3c6a038839ad31aaf521079f6198aa5b0b3
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Oct 25 23:26:18 2012 -0400

    Ensure that no warnings are generated during the tests

diff --git a/t/mail/one-time-recipients.t b/t/mail/one-time-recipients.t
index 5162802..10cd1c0 100644
--- a/t/mail/one-time-recipients.t
+++ b/t/mail/one-time-recipients.t
@@ -5,6 +5,7 @@ use utf8;
 
 use RT::Test tests => undef;
 use RT::Test::Email;
+use Test::Warn;
 
 my $queue = RT::Test->load_or_create_queue(
     Name              => 'General',
@@ -20,7 +21,7 @@ my $user = RT::Test->load_or_create_user(
 ok $user && $user->id, 'loaded or created user';
 
 diag "Reply to ticket with actor as one time cc";
-{
+warnings_are {
     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
     mail_ok {
         my ($status, undef, $msg) = $ticket->Create(
@@ -54,10 +55,10 @@ diag "Reply to ticket with actor as one time cc";
         );
         ok $status, "replied to a ticket";
     } { Cc => 'root at localhost' };
-}
+} [];
 
 diag "Reply to ticket with requestor squelched";
-{
+warnings_are {
     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
     mail_ok {
         my ($status, undef, $msg) = $ticket->Create(
@@ -90,10 +91,10 @@ diag "Reply to ticket with requestor squelched";
         );
         ok $status, "replied to a ticket";
     } { Cc => 'test at localhost' };
-}
+} [];
 
 diag "Reply to ticket with requestor squelched";
-{
+warnings_are {
     my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
     mail_ok {
         my ($status, undef, $msg) = $ticket->Create(
@@ -134,6 +135,6 @@ diag "Reply to ticket with requestor squelched";
         );
         ok $status, "replied to a ticket";
     }  { Cc => 'test at localhost' };
-}
+} [];
 
 done_testing;

commit 90aa83610eae46b01f39a5e47aafdf9366956fb1
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu Oct 25 23:26:56 2012 -0400

    Add a test to ensure that RTAddressRegexps are always squelched, even when CC'd

diff --git a/t/mail/one-time-recipients.t b/t/mail/one-time-recipients.t
index 10cd1c0..69fde48 100644
--- a/t/mail/one-time-recipients.t
+++ b/t/mail/one-time-recipients.t
@@ -137,4 +137,33 @@ warnings_are {
     }  { Cc => 'test at localhost' };
 } [];
 
+diag "Requestor is an RT address";
+warnings_are {
+    my $ticket = RT::Ticket->new( RT::CurrentUser->new( $user ) );
+    mail_ok {
+        my ($status, undef, $msg) = $ticket->Create(
+            Queue => $queue->id,
+            Subject => 'test',
+            Requestor => 'rt-address at example.com',
+        );
+        ok $status, "created ticket";
+    } { To => 'rt-address at example.com' };
+
+    RT->Config->Set( RTAddressRegexp => qr/^rt-address\@example\.com$/i );
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+        );
+        ok $status, "replied to a ticket";
+    };
+
+    mail_ok {
+        my ($status, $msg) = $ticket->Correspond(
+            Content => 'test mail',
+            CcMessageTo => 'rt-address at example.com',
+        );
+        ok $status, "replied to a ticket";
+    };
+} [];
+
 done_testing;

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


More information about the Rt-commit mailing list