[Rt-commit] rt branch, 4.0/sendmail-action-logs, updated. rt-4.0.2-65-ge959ea9
Alex Vandiver
alexmv at bestpractical.com
Fri Mar 23 17:07:59 EDT 2012
The branch, 4.0/sendmail-action-logs has been updated
via e959ea9596f9f5416782ee2f4fd85678b22637fb (commit)
via e0fd7a1d29469e1a2ab5062ef9f089ff6de75f5d (commit)
via c1c12682695dd73cd2c367752331023eab90d16f (commit)
via b9494fca52d7a2c1f3dc87b3c8ffb94d82165a7e (commit)
from 8c1d00edafdab3215638b5c3142484f8f5d3301f (commit)
Summary of changes:
lib/RT/Action/Notify.pm | 39 ++++++++++++----------
lib/RT/Action/SendEmail.pm | 76 ++++++++++++++++++++++++++++++++-----------
2 files changed, 77 insertions(+), 38 deletions(-)
- Log -----------------------------------------------------------------
commit b9494fca52d7a2c1f3dc87b3c8ffb94d82165a7e
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 136b58f..a7c5424 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -746,13 +746,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 c1c12682695dd73cd2c367752331023eab90d16f
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 a7c5424..bb9ade9 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -766,6 +766,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 e0fd7a1d29469e1a2ab5062ef9f089ff6de75f5d
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 bb9ade9..c57f5c9 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -825,35 +825,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 if RT::EmailParser->CullRTAddresses( $_[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;
+
+ NOQUELCH_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 e959ea9596f9f5416782ee2f4fd85678b22637fb
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 2dbad8e..b8a9f42 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;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list