diff options
Diffstat (limited to 'rt/lib/RT/Action/SendEmail.pm')
-rwxr-xr-x | rt/lib/RT/Action/SendEmail.pm | 104 |
1 files changed, 26 insertions, 78 deletions
diff --git a/rt/lib/RT/Action/SendEmail.pm b/rt/lib/RT/Action/SendEmail.pm index d8ebbd87b..1ebcb0ccd 100755 --- a/rt/lib/RT/Action/SendEmail.pm +++ b/rt/lib/RT/Action/SendEmail.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC # <jesse@bestpractical.com> # # (Except where explicitly superseded by other copyright notices) @@ -22,9 +22,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -# 02110-1301 or visit their web page on the internet at -# http://www.gnu.org/copyleft/gpl.html. +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # # CONTRIBUTION SUBMISSION POLICY: @@ -58,7 +56,6 @@ use MIME::Words qw(encode_mimeword); use RT::EmailParser; use Mail::Address; -use Date::Format qw(strftime); =head1 NAME @@ -102,12 +99,7 @@ perl(1). sub Commit { my $self = shift; - my ($ret) = $self->SendMessage( $self->TemplateObj->MIMEObj ); - if ( $ret > 0 ) { - $self->RecordOutgoingMailTransaction( $self->TemplateObj->MIMEObj ) - if ($RT::RecordOutgoingEmail); - } - return (abs $ret); + return($self->SendMessage($self->TemplateObj->MIMEObj)); } # }}} @@ -255,51 +247,7 @@ sub SendMessage { || $MIMEObj->head->get('Bcc') ) { $RT::Logger->info( $msgid . " No recipients found. Not sending.\n" ); - return (-1); - } - - unless ($MIMEObj->head->get('Date')) { - # We coerce localtime into an array since strftime has a flawed prototype that only accepts - # a list - $MIMEObj->head->replace(Date => strftime('%a, %d %b %Y %H:%M:%S %z', @{[localtime()]})); - } - - return (0) unless ($self->OutputMIMEObject($MIMEObj)); - - my $success = $msgid . " sent "; - foreach( qw(To Cc Bcc) ) { - my $recipients = $MIMEObj->head->get($_); - $success .= " $_: ". $recipients if $recipients; - } - $success =~ s/\n//g; - - $RT::Logger->info($success); - - return (1); -} - - -=head2 OutputMIMEObject MIME::Entity - -Sends C<MIME::Entity> as an email message according to RT's mailer configuration. - -=cut - - - -sub OutputMIMEObject { - my $self = shift; - my $MIMEObj = shift; - - my $msgid = $MIMEObj->head->get('Message-ID'); - chomp $msgid; - - my $SendmailArguments = $RT::SendmailArguments; - if (defined $RT::VERPPrefix && defined $RT::VERPDomain) { - my $EnvelopeFrom = $self->TransactionObj->CreatorObj->EmailAddress; - $EnvelopeFrom =~ s/@/=/g; - $EnvelopeFrom =~ s/\s//g; - $SendmailArguments .= " -f ${RT::VERPPrefix}${EnvelopeFrom}\@${RT::VERPDomain}"; + return (1); } @@ -309,7 +257,7 @@ sub OutputMIMEObject { local $SIG{'CHLD'} = 'DEFAULT'; my $mail; - unless( open $mail, "|$RT::SendmailPath $SendmailArguments" ) { + unless( open $mail, "|$RT::SendmailPath $RT::SendmailArguments" ) { die "Couldn't run $RT::SendmailPath: $!"; } @@ -335,7 +283,7 @@ sub OutputMIMEObject { local $ENV{MAILADDRESS}; if ( $RT::MailCommand eq 'sendmail' ) { - push @mailer_args, split(/\s+/, $SendmailArguments); + push @mailer_args, split(/\s+/, $RT::SendmailArguments); } elsif ( $RT::MailCommand eq 'smtp' ) { $ENV{MAILADDRESS} = $RT::SMTPFrom || $MIMEObj->head->get('From'); @@ -351,7 +299,19 @@ sub OutputMIMEObject { return (0); } } - return 1; + + my $success = "$msgid sent"; + foreach (qw(To Cc Bcc)) { + next unless my $addresses = $MIMEObj->head->get($_); + $success .= " $_: ". $addresses; + } + $success =~ s/\n//g; + + $self->RecordOutgoingMailTransaction($MIMEObj) if ($RT::RecordOutgoingEmail); + + $RT::Logger->info($success); + + return (1); } # }}} @@ -552,10 +512,6 @@ Remove addresses that are RT addresses or that are on this transaction's blackli sub RemoveInappropriateRecipients { my $self = shift; - my $msgid = $self->TemplateObj->MIMEObj->head->get ('Message-Id'); - - - my @blacklist; my @types = qw/To Cc Bcc/; @@ -587,7 +543,6 @@ sub RemoveInappropriateRecipients { @{ $self->{'Cc'} } = (); @{ $self->{'Bcc'} } = (); - $RT::Logger->info( $msgid . " The incoming message was autogenerated. Not redistributing this message based on site configuration.\n"); } elsif ( $RT::RedistributeAutoGeneratedMessages eq 'privileged' ) { @@ -605,7 +560,6 @@ sub RemoveInappropriateRecipients { } } - $RT::Logger->info( $msgid . " The incoming message was autogenerated. Not redistributing this message to unprivileged users based on site configuration.\n"); } @@ -670,8 +624,7 @@ sub SetReturnAddress { unless ( $self->TemplateObj->MIMEObj->head->get('From') ) { if ($RT::UseFriendlyFromLine) { - my $friendly_name = $self->TransactionObj->CreatorObj->RealName - || $self->TransactionObj->CreatorObj->Name; + my $friendly_name = $self->TransactionObj->CreatorObj->RealName; if ( $friendly_name =~ /^"(.*)"$/ ) { # a quoted string $friendly_name = $1; } @@ -778,18 +731,13 @@ This routine fixes the RT tag in the subject. It's unlikely that you want to ove sub SetSubjectToken { my $self = shift; + my $tag = "[$RT::rtname #" . $self->TicketObj->id . "]"; my $sub = $self->TemplateObj->MIMEObj->head->get('Subject'); - my $id = $self->TicketObj->id; - - my $token_re = $RT::EmailSubjectTagRegex; - $token_re = qr/\Q$RT::rtname\E/o unless $token_re; - return if $sub =~ /\[$token_re\s+#$id\]/; - - $sub =~ s/(\r\n|\n|\s)/ /gi; - chomp $sub; - $self->TemplateObj->MIMEObj->head->replace( - Subject => "[$RT::rtname #$id] $sub", - ); + unless ( $sub =~ /\Q$tag\E/ ) { + $sub =~ s/(\r\n|\n|\s)/ /gi; + chomp $sub; + $self->TemplateObj->MIMEObj->head->replace( 'Subject', "$tag $sub" ); + } } # }}} |