[Rt-commit] rt branch, 4.0/sendmail-action-logs, created. rt-4.0.2-61-g8c1d00e
Ruslan Zakirov
ruz at bestpractical.com
Fri Sep 9 10:00:21 EDT 2011
The branch, 4.0/sendmail-action-logs has been created
at 8c1d00edafdab3215638b5c3142484f8f5d3301f (commit)
- Log -----------------------------------------------------------------
commit 54fbfda5e69d67370ae081c56bb004ae6c1a6a72
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Fri Sep 9 14:49:36 2011 +0400
save lenghty call into a variable
diff --git a/lib/RT/Action/SendEmail.pm b/lib/RT/Action/SendEmail.pm
index 553b736..4057351 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -762,7 +762,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);
@@ -770,9 +772,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 183d883577a5106d5ed4ebe052ad02718fc1a508
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 4057351..d38c4dc 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -790,7 +790,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 2c2aee60eef8b67cede4437e91e73d51406f63b4
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 d38c4dc..e93a484 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -748,7 +748,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
@@ -779,7 +779,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
@@ -790,20 +791,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} } ) {
@@ -814,7 +822,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 8c1d00edafdab3215638b5c3142484f8f5d3301f
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 e93a484..136b58f 100644
--- a/lib/RT/Action/SendEmail.pm
+++ b/lib/RT/Action/SendEmail.pm
@@ -745,6 +745,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;
@@ -822,8 +833,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;
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list