X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FAction%2FSendEmail.pm;h=0f11cc1416ee16189f8589f9d1aed7d8a2f3ad2b;hb=b8988e1d3ac75af63c85e8563e57701030315a9e;hp=4ae1a8b66d6f5c46075a310352c3fe08715a1515;hpb=f3c4966ed1f6ec3db7accd6dcdd3a5a3821d72a7;p=freeside.git diff --git a/rt/lib/RT/Action/SendEmail.pm b/rt/lib/RT/Action/SendEmail.pm index 4ae1a8b66..0f11cc141 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-2012 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -99,47 +99,31 @@ activated in the config. sub Commit { my $self = shift; - $self->DeferDigestRecipients() if RT->Config->Get('RecordOutgoingEmail'); + return abs $self->SendMessage( $self->TemplateObj->MIMEObj ) + unless RT->Config->Get('RecordOutgoingEmail'); + + $self->DeferDigestRecipients(); my $message = $self->TemplateObj->MIMEObj; my $orig_message; - if ( RT->Config->Get('RecordOutgoingEmail') - && RT->Config->Get('GnuPG')->{'Enable'} ) - { - - # it's hacky, but we should know if we're going to crypt things - my $attachment = $self->TransactionObj->Attachments->First; - - my %crypt; - foreach my $argument (qw(Sign Encrypt)) { - if ( $attachment - && defined $attachment->GetHeader("X-RT-$argument") ) - { - $crypt{$argument} = $attachment->GetHeader("X-RT-$argument"); - } else { - $crypt{$argument} = $self->TicketObj->QueueObj->$argument(); - } - } - if ( $crypt{'Sign'} || $crypt{'Encrypt'} ) { - $orig_message = $message->dup; - } - } + $orig_message = $message->dup if RT::Interface::Email::WillSignEncrypt( + Attachment => $self->TransactionObj->Attachments->First, + Ticket => $self->TicketObj, + ); my ($ret) = $self->SendMessage($message); - if ( $ret > 0 && RT->Config->Get('RecordOutgoingEmail') ) { - if ($orig_message) { - $message->attach( - Type => 'application/x-rt-original-message', - Disposition => 'inline', - Data => $orig_message->as_string, - ); - } - $self->RecordOutgoingMailTransaction($message); - $self->RecordDeferredRecipients(); - } + return abs( $ret ) if $ret <= 0; - - return ( abs $ret ); + if ($orig_message) { + $message->attach( + Type => 'application/x-rt-original-message', + Disposition => 'inline', + Data => $orig_message->as_string, + ); + } + $self->RecordOutgoingMailTransaction($message); + $self->RecordDeferredRecipients(); + return 1; } =head2 Prepare @@ -398,7 +382,7 @@ sub AddAttachments { =head2 AddAttachment $attachment -Takes one attachment object of L class and attaches it to the message +Takes one attachment object of L class and attaches it to the message we're building. =cut @@ -413,14 +397,15 @@ sub AddAttachment { and $attach->TransactionObj->CurrentUserCanSee; # ->attach expects just the disposition type; extract it if we have the header + # or default to "attachment" my $disp = ($attach->GetHeader('Content-Disposition') || '') - =~ /^\s*(inline|attachment)/i ? $1 : undef; + =~ /^\s*(inline|attachment)/i ? $1 : "attachment"; $MIMEObj->attach( Type => $attach->ContentType, Charset => $attach->OriginalEncoding, Data => $attach->OriginalContent, - Disposition => $disp, # a false value defaults to inline in MIME::Entity + Disposition => $disp, Filename => $self->MIMEEncodeString( $attach->Filename ), 'RT-Attachment:' => $self->TicketObj->Id . "/" . $self->TransactionObj->Id . "/" @@ -887,21 +872,25 @@ sub SetFrom { my $self = shift; my %args = @_; + my $from = $args{From}; + if ( RT->Config->Get('UseFriendlyFromLine') ) { my $friendly_name = $self->GetFriendlyName(%args); - $self->SetHeader( - 'From', + $from = sprintf( RT->Config->Get('FriendlyFromLineFormat'), $self->MIMEEncodeString( $friendly_name, RT->Config->Get('EmailOutputEncoding') ), $args{From} - ), - ); - } else { - $self->SetHeader( 'From', $args{From} ); + ); } + + $self->SetHeader( 'From', $from ); + + #also set Sender:, otherwise MTAs add a nonsensical value like rt@machine, + #and then Outlook prepends "rt@machine on behalf of" to the From: header + $self->SetHeader( 'Sender', $from ); } =head2 GetFriendlyName @@ -987,7 +976,7 @@ sub SetSubject { $subject =~ s/(\r\n|\n|\s)/ /g; - $self->SetHeader( 'Subject', $subject ); + $self->SetHeader( 'Subject', Encode::encode_utf8( $subject ) ); } @@ -1001,11 +990,14 @@ sub SetSubjectToken { my $self = shift; my $head = $self->TemplateObj->MIMEObj->head; - $head->replace( - Subject => RT::Interface::Email::AddSubjectTag( - Encode::decode_utf8( $head->get('Subject') ), - $self->TicketObj, - ), + $self->SetHeader( + Subject => + Encode::encode_utf8( + RT::Interface::Email::AddSubjectTag( + Encode::decode_utf8( $head->get('Subject') ), + $self->TicketObj, + ), + ), ); }