1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/copyleft/gpl.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
48 # Portions Copyright 2000 Tobias Brox <tobix@cpan.org>
50 package RT::Action::SendEmail;
51 require RT::Action::Generic;
55 @ISA = qw(RT::Action::Generic);
57 use MIME::Words qw(encode_mimeword);
61 use Date::Format qw(strftime);
65 RT::Action::SendEmail - An Action which users can use to send mail
66 or can subclassed for more specialized mail sending behavior.
67 RT::Action::AutoReply is a good example subclass.
71 require RT::Action::SendEmail;
72 @ISA = qw(RT::Action::SendEmail);
77 Basically, you create another module RT::Action::YourAction which ISA
78 RT::Action::SendEmail.
82 ok (require RT::Action::SendEmail);
89 Jesse Vincent <jesse@bestpractical.com> and Tobias Brox <tobix@cpan.org>
97 # {{{ Scrip methods (_Init, Commit, Prepare, IsApplicable)
103 # DO NOT SHIFT @_ in this subroutine. It breaks Hook::LexWrap's
104 # ability to pass @_ to a 'post' routine.
107 my ($ret) = $self->SendMessage( $self->TemplateObj->MIMEObj );
109 $self->RecordOutgoingMailTransaction( $self->TemplateObj->MIMEObj )
110 if ($RT::RecordOutgoingEmail);
122 my ( $result, $message ) = $self->TemplateObj->Parse(
123 Argument => $self->Argument,
124 TicketObj => $self->TicketObj,
125 TransactionObj => $self->TransactionObj
131 my $MIMEObj = $self->TemplateObj->MIMEObj;
134 $self->SetRTSpecialHeaders();
136 $self->RemoveInappropriateRecipients();
139 foreach my $type qw(To Cc Bcc) {
140 @{ $self->{ $type } } =
141 grep defined && length && !$seen{ lc $_ }++,
142 @{ $self->{ $type } };
145 # Go add all the Tos, Ccs and Bccs that we need to to the message to
146 # make it happy, but only if we actually have values in those arrays.
148 # TODO: We should be pulling the recipients out of the template and shove them into To, Cc and Bcc
150 $self->SetHeader( 'To', join ( ', ', @{ $self->{'To'} } ) )
151 if ( ! $MIMEObj->head->get('To') && $self->{'To'} && @{ $self->{'To'} } );
152 $self->SetHeader( 'Cc', join ( ', ', @{ $self->{'Cc'} } ) )
153 if ( !$MIMEObj->head->get('Cc') && $self->{'Cc'} && @{ $self->{'Cc'} } );
154 $self->SetHeader( 'Bcc', join ( ', ', @{ $self->{'Bcc'} } ) )
155 if ( !$MIMEObj->head->get('Bcc') && $self->{'Bcc'} && @{ $self->{'Bcc'} } );
157 # PseudoTo (fake to headers) shouldn't get matched for message recipients.
158 # If we don't have any 'To' header (but do have other recipients), drop in
159 # the pseudo-to header.
160 $self->SetHeader( 'To', join ( ', ', @{ $self->{'PseudoTo'} } ) )
161 if ( $self->{'PseudoTo'} && ( @{ $self->{'PseudoTo'} } )
162 and ( !$MIMEObj->head->get('To') ) ) and ( $MIMEObj->head->get('Cc') or $MIMEObj->head->get('Bcc'));
164 # We should never have to set the MIME-Version header
165 $self->SetHeader( 'MIME-Version', '1.0' );
167 # fsck.com #5959: Since RT sends 8bit mail, we should say so.
168 $self->SetHeader( 'Content-Transfer-Encoding','8bit');
170 # For security reasons, we only send out textual mails.
171 my @parts = $MIMEObj;
172 while (my $part = shift @parts) {
173 if ($part->is_multipart) {
174 push @parts, $part->parts;
177 if ( RT::I18N::IsTextualContentType( $part->mime_type ) ) {
178 $part->head->mime_attr( "Content-Type" => $part->mime_type )
180 $part->head->mime_attr( "Content-Type" => 'text/plain' );
182 $part->head->mime_attr( "Content-Type.charset" => 'utf-8' );
187 RT::I18N::SetMIMEEntityToEncoding( $MIMEObj, $RT::EmailOutputEncoding, 'mime_words_ok' );
189 # Build up a MIME::Entity that looks like the original message.
190 $self->AddAttachments() if ( $MIMEObj->head->get('RT-Attach-Message') );
204 Returns an array of Mail::Address objects containing all the To: recipients for this notification
210 return ($self->_AddressesFromHeader('To'));
215 Returns an array of Mail::Address objects containing all the Cc: recipients for this notification
221 return ($self->_AddressesFromHeader('Cc'));
226 Returns an array of Mail::Address objects containing all the Bcc: recipients for this notification
233 return ($self->_AddressesFromHeader('Bcc'));
237 sub _AddressesFromHeader {
240 my $header = $self->TemplateObj->MIMEObj->head->get($field);
241 my @addresses = Mail::Address->parse($header);
249 =head2 SendMessage MIMEObj
251 sends the message using RT's preferred API.
252 TODO: Break this out to a separate module
257 # DO NOT SHIFT @_ in this subroutine. It breaks Hook::LexWrap's
258 # ability to pass @_ to a 'post' routine.
259 my ( $self, $MIMEObj ) = @_;
261 my $msgid = $MIMEObj->head->get('Message-ID');
264 $self->ScripActionObj->{_Message_ID}++;
266 $RT::Logger->info( $msgid . " #"
267 . $self->TicketObj->id . "/"
268 . $self->TransactionObj->id
270 . $self->ScripObj->id . " "
271 . $self->ScripObj->Description );
273 #If we don't have any recipients to send to, don't send a message;
274 unless ( $MIMEObj->head->get('To')
275 || $MIMEObj->head->get('Cc')
276 || $MIMEObj->head->get('Bcc') )
278 $RT::Logger->info( $msgid . " No recipients found. Not sending.\n" );
282 unless ($MIMEObj->head->get('Date')) {
283 # We coerce localtime into an array since strftime has a flawed prototype that only accepts
285 $MIMEObj->head->replace(Date => strftime('%a, %d %b %Y %H:%M:%S %z', @{[localtime()]}));
288 return (0) unless ($self->OutputMIMEObject($MIMEObj));
290 my $success = $msgid . " sent ";
291 foreach( qw(To Cc Bcc) ) {
292 my $recipients = $MIMEObj->head->get($_);
293 $success .= " $_: ". $recipients if $recipients;
297 $RT::Logger->info($success);
303 =head2 OutputMIMEObject MIME::Entity
305 Sends C<MIME::Entity> as an email message according to RT's mailer configuration.
311 sub OutputMIMEObject {
315 my $msgid = $MIMEObj->head->get('Message-ID');
318 my $SendmailArguments = $RT::SendmailArguments;
319 if (defined $RT::VERPPrefix && defined $RT::VERPDomain) {
320 my $EnvelopeFrom = $self->TransactionObj->CreatorObj->EmailAddress;
321 $EnvelopeFrom =~ s/@/=/g;
322 $EnvelopeFrom =~ s/\s//g;
323 $SendmailArguments .= " -f ${RT::VERPPrefix}${EnvelopeFrom}\@${RT::VERPDomain}";
327 if ( $RT::MailCommand eq 'sendmailpipe' ) {
329 # don't ignore CHLD signal to get proper exit code
330 local $SIG{'CHLD'} = 'DEFAULT';
333 unless( open $mail, "|$RT::SendmailPath $SendmailArguments" ) {
334 die "Couldn't run $RT::SendmailPath: $!";
337 # if something wrong with $mail->print we will get PIPE signal, handle it
338 local $SIG{'PIPE'} = sub { die "$RT::SendmailPath closed pipe" };
339 $MIMEObj->print($mail);
341 unless ( close $mail ) {
342 die "Close failed: $!" if $!; # system error
343 # sendmail exit statuses mostly errors with data not software
344 # TODO: status parsing: core dump, exit on signal or EX_*
345 $RT::Logger->warning( "$RT::SendmailPath exitted with status $?" );
349 $RT::Logger->crit( $msgid . "Could not send mail: " . $@ );
354 my @mailer_args = ($RT::MailCommand);
356 local $ENV{MAILADDRESS};
358 if ( $RT::MailCommand eq 'sendmail' ) {
359 push @mailer_args, split(/\s+/, $SendmailArguments);
361 elsif ( $RT::MailCommand eq 'smtp' ) {
362 $ENV{MAILADDRESS} = $RT::SMTPFrom || $MIMEObj->head->get('From');
363 push @mailer_args, ( Server => $RT::SMTPServer );
364 push @mailer_args, ( Debug => $RT::SMTPDebug );
367 push @mailer_args, $RT::MailParams;
370 unless ( $MIMEObj->send(@mailer_args) ) {
371 $RT::Logger->crit( $msgid . "Could not send mail." );
382 =head2 AddAttachments
384 Takes any attachments to this transaction and attaches them to the message
393 my $MIMEObj = $self->TemplateObj->MIMEObj;
395 $MIMEObj->head->delete('RT-Attach-Message');
397 my $attachments = RT::Attachments->new($RT::SystemUser);
399 FIELD => 'TransactionId',
400 VALUE => $self->TransactionObj->Id
402 $attachments->OrderBy( FIELD => 'id');
404 my $transaction_content_obj = $self->TransactionObj->ContentObj;
406 # attach any of this transaction's attachments
407 while ( my $attach = $attachments->Next ) {
409 # Don't attach anything blank
410 next unless ( $attach->ContentLength );
412 # We want to make sure that we don't include the attachment that's being used as the "Content" of this message.
414 if ( $transaction_content_obj
415 && $transaction_content_obj->Id == $attach->Id
416 && $transaction_content_obj->ContentType =~ qr{text/plain}i );
417 $MIMEObj->make_multipart('mixed');
419 Type => $attach->ContentType,
420 Charset => $attach->OriginalEncoding,
421 Data => $attach->OriginalContent,
422 Filename => $self->MIMEEncodeString( $attach->Filename,
423 $RT::EmailOutputEncoding ),
424 'RT-Attachment:' => $self->TicketObj->Id."/".$self->TransactionObj->Id."/".$attach->id,
425 Encoding => '-SUGGEST'
433 # {{{ RecordOutgoingMailTransaction
435 =head2 RecordOutgoingMailTransaction MIMEObj
437 Record a transaction in RT with this outgoing message for future record-keeping purposes
443 sub RecordOutgoingMailTransaction {
448 my @parts = $MIMEObj->parts;
451 foreach my $part (@parts) {
452 my $attach = $part->head->get('RT-Attachment');
454 $RT::Logger->debug("We found an attachment. we want to not record it.");
455 push @attachments, $attach;
457 $RT::Logger->debug("We found a part. we want to record it.");
461 $MIMEObj->parts(\@keep);
462 foreach my $attachment (@attachments) {
463 $MIMEObj->head->add('RT-Attachment', $attachment);
466 RT::I18N::SetMIMEEntityToEncoding( $MIMEObj, 'utf-8', 'mime_words_ok' );
468 my $transaction = RT::Transaction->new($self->TransactionObj->CurrentUser);
470 # XXX: TODO -> Record attachments as references to things in the attachments table, maybe.
473 if ($self->TransactionObj->Type eq 'Comment') {
474 $type = 'CommentEmailRecord';
476 $type = 'EmailRecord';
479 my $msgid = $MIMEObj->head->get('Message-ID');
482 my ( $id, $msg ) = $transaction->Create(
483 Ticket => $self->TicketObj->Id,
491 $self->{'OutgoingMailTransaction'} = $id;
493 $RT::Logger->warning( "Could not record outgoing message transaction: $msg" );
501 # {{{ sub SetRTSpecialHeaders
503 =head2 SetRTSpecialHeaders
505 This routine adds all the random headers that RT wants in a mail message
506 that don't matter much to anybody else.
510 sub SetRTSpecialHeaders {
514 $self->SetSubjectToken();
515 $self->SetHeaderAsEncoding( 'Subject', $RT::EmailOutputEncoding )
516 if ($RT::EmailOutputEncoding);
517 $self->SetReturnAddress();
518 $self->SetReferencesHeaders();
520 unless ($self->TemplateObj->MIMEObj->head->get('Message-ID')) {
521 # Get Message-ID for this txn
523 $msgid = $self->TransactionObj->Message->First->GetHeader("RT-Message-ID")
524 || $self->TransactionObj->Message->First->GetHeader("Message-ID")
525 if $self->TransactionObj->Message && $self->TransactionObj->Message->First;
527 # If there is one, and we can parse it, then base our Message-ID on it
529 and $msgid =~ s/<(rt-.*?-\d+-\d+)\.(\d+)-\d+-\d+\@\Q$RT::Organization\E>$/
530 "<$1." . $self->TicketObj->id
531 . "-" . $self->ScripObj->id
532 . "-" . $self->ScripActionObj->{_Message_ID}
533 . "@" . $RT::Organization . ">"/eg
534 and $2 == $self->TicketObj->id) {
535 $self->SetHeader( "Message-ID" => $msgid );
537 $self->SetHeader( 'Message-ID',
542 . int(rand(2000)) . '.'
543 . $self->TicketObj->id . "-"
544 . $self->ScripObj->id . "-" # Scrip
545 . $self->ScripActionObj->{_Message_ID} . "@" # Email sent
551 $self->SetHeader( 'Precedence', "bulk" )
552 unless ( $self->TemplateObj->MIMEObj->head->get("Precedence") );
554 $self->SetHeader( 'X-RT-Loop-Prevention', $RT::rtname );
555 $self->SetHeader( 'RT-Ticket',
556 $RT::rtname . " #" . $self->TicketObj->id() );
557 $self->SetHeader( 'Managed-by',
558 "RT $RT::VERSION (http://www.bestpractical.com/rt/)" );
560 $self->SetHeader( 'RT-Originator',
561 $self->TransactionObj->CreatorObj->EmailAddress );
570 # {{{ RemoveInappropriateRecipients
572 =head2 RemoveInappropriateRecipients
574 Remove addresses that are RT addresses or that are on this transaction's blacklist
578 sub RemoveInappropriateRecipients {
581 my $msgid = $self->TemplateObj->MIMEObj->head->get ('Message-Id');
587 my @types = qw/To Cc Bcc/;
589 # Weed out any RT addresses. We really don't want to talk to ourselves!
590 foreach my $type (@types) {
591 @{ $self->{$type} } =
592 RT::EmailParser::CullRTAddresses( "", @{ $self->{$type} } );
595 # If there are no recipients, don't try to send the message.
596 # If the transaction has content and has the header RT-Squelch-Replies-To
598 if ( $self->TransactionObj->Attachments->First() ) {
600 $self->TransactionObj->Attachments->First->GetHeader(
601 'RT-DetectedAutoGenerated')
605 # What do we want to do with this? It's probably (?) a bounce
606 # caused by one of the watcher addresses being broken.
607 # Default ("true") is to redistribute, for historical reasons.
609 if ( !$RT::RedistributeAutoGeneratedMessages ) {
611 # Don't send to any watchers.
612 @{ $self->{'To'} } = ();
613 @{ $self->{'Cc'} } = ();
614 @{ $self->{'Bcc'} } = ();
616 $RT::Logger->info( $msgid . " The incoming message was autogenerated. Not redistributing this message based on site configuration.\n");
618 elsif ( $RT::RedistributeAutoGeneratedMessages eq 'privileged' ) {
620 # Only send to "privileged" watchers.
623 foreach my $type (@types) {
625 foreach my $addr ( @{ $self->{$type} } ) {
626 my $user = RT::User->new($RT::SystemUser);
627 $user->LoadByEmail($addr);
628 @{ $self->{$type} } =
629 grep ( !/^\Q$addr\E$/, @{ $self->{$type} } )
630 if ( !$user->Privileged );
634 $RT::Logger->info( $msgid . " The incoming message was autogenerated. Not redistributing this message to unprivileged users based on site configuration.\n");
641 $self->TransactionObj->Attachments->First->GetHeader(
642 'RT-Squelch-Replies-To');
645 @blacklist = split( /,/, $squelch );
649 # Let's grab the SquelchMailTo attribue and push those entries into the @blacklist
650 my @non_recipients = $self->TicketObj->SquelchMailTo;
651 foreach my $attribute (@non_recipients) {
652 push @blacklist, $attribute->Content;
655 # Cycle through the people we're sending to and pull out anyone on the
658 foreach my $person_to_yank (@blacklist) {
659 $person_to_yank =~ s/\s//g;
660 foreach my $type (@types) {
661 @{ $self->{$type} } =
662 grep ( !/^\Q$person_to_yank\E$/, @{ $self->{$type} } );
668 # {{{ sub SetReturnAddress
670 =head2 SetReturnAddress is_comment => BOOLEAN
672 Calculate and set From and Reply-To headers based on the is_comment flag.
676 sub SetReturnAddress {
685 # $args{is_comment} should be set if the comment address is to be used.
688 if ( $args{'is_comment'} ) {
689 $replyto = $self->TicketObj->QueueObj->CommentAddress
690 || $RT::CommentAddress;
693 $replyto = $self->TicketObj->QueueObj->CorrespondAddress
694 || $RT::CorrespondAddress;
697 unless ( $self->TemplateObj->MIMEObj->head->get('From') ) {
698 if ($RT::UseFriendlyFromLine) {
699 my $friendly_name = $self->TransactionObj->CreatorObj->RealName
700 || $self->TransactionObj->CreatorObj->Name;
701 if ( $friendly_name =~ /^"(.*)"$/ ) { # a quoted string
705 $friendly_name =~ s/"/\\"/g;
709 $RT::FriendlyFromLineFormat,
710 $self->MIMEEncodeString( $friendly_name,
711 $RT::EmailOutputEncoding ),
717 $self->SetHeader( 'From', $replyto );
721 unless ( $self->TemplateObj->MIMEObj->head->get('Reply-To') ) {
722 $self->SetHeader( 'Reply-To', "$replyto" );
731 =head2 SetHeader FIELD, VALUE
733 Set the FIELD of the current MIME object into VALUE.
744 $self->TemplateObj->MIMEObj->head->fold_length( $field, 10000 );
745 $self->TemplateObj->MIMEObj->head->replace( $field, $val );
746 return $self->TemplateObj->MIMEObj->head->get($field);
756 This routine sets the subject. it does not add the rt tag. that gets done elsewhere
757 If $self->{'Subject'} is already defined, it uses that. otherwise, it tries to get
758 the transaction's subject.
766 my $message = $self->TransactionObj->Attachments;
767 if ( $self->TemplateObj->MIMEObj->head->get('Subject') ) {
770 if ( $self->{'Subject'} ) {
771 $subject = $self->{'Subject'};
773 elsif ( ( $message->First() ) && ( $message->First->Headers ) ) {
774 my $header = $message->First->Headers();
775 $header =~ s/\n\s+/ /g;
776 if ( $header =~ /^Subject: (.*?)$/m ) {
780 $subject = $self->TicketObj->Subject();
785 $subject = $self->TicketObj->Subject();
788 $subject =~ s/(\r\n|\n|\s)/ /gi;
791 $self->SetHeader( 'Subject', $subject );
797 # {{{ sub SetSubjectToken
799 =head2 SetSubjectToken
801 This routine fixes the RT tag in the subject. It's unlikely that you want to overwrite this.
805 sub SetSubjectToken {
807 my $sub = $self->TemplateObj->MIMEObj->head->get('Subject');
808 my $id = $self->TicketObj->id;
810 my $token_re = $RT::EmailSubjectTagRegex;
811 $token_re = qr/\Q$RT::rtname\E/o unless $token_re;
812 return if $sub =~ /\[$token_re\s+#$id\]/;
814 $sub =~ s/(\r\n|\n|\s)/ /gi;
816 $self->TemplateObj->MIMEObj->head->replace(
817 Subject => "[$RT::rtname #$id] $sub",
823 =head2 SetReferencesHeaders
825 Set References and In-Reply-To headers for this message.
829 sub SetReferencesHeaders {
832 my ( @in_reply_to, @references, @msgid );
834 my $attachments = $self->TransactionObj->Message;
836 if ( my $top = $attachments->First() ) {
837 @in_reply_to = split(/\s+/m, $top->GetHeader('In-Reply-To') || '');
838 @references = split(/\s+/m, $top->GetHeader('References') || '' );
839 @msgid = split(/\s+/m, $top->GetHeader('Message-ID') || '');
845 # There are two main cases -- this transaction was created with
846 # the RT Web UI, and hence we want to *not* append its Message-ID
847 # to the References and In-Reply-To. OR it came from an outside
848 # source, and we should treat it as per the RFC
849 if ( "@msgid" =~ /<(rt-.*?-\d+-\d+)\.(\d+-0-0)\@$RT::Organization>/) {
851 # Make all references which are internal be to version which we
853 for (@references, @in_reply_to) {
854 s/<(rt-.*?-\d+-\d+)\.(\d+-0-0)\@$RT::Organization>$/
855 "<$1." . $self->TicketObj->id .
856 "-" . $self->ScripObj->id .
857 "-" . $self->ScripActionObj->{_Message_ID} .
858 "@" . $RT::Organization . ">"/eg
861 # In reply to whatever the internal message was in reply to
862 $self->SetHeader( 'In-Reply-To', join( " ", ( @in_reply_to )));
864 # Default the references to whatever we're in reply to
865 @references = @in_reply_to unless @references;
867 # References are unchanged from internal
869 # In reply to that message
870 $self->SetHeader( 'In-Reply-To', join( " ", ( @msgid )));
872 # Default the references to whatever we're in reply to
873 @references = @in_reply_to unless @references;
875 # Push that message onto the end of the references
876 push @references, @msgid;
879 # Push pseudo-ref to the front
880 my $pseudo_ref = $self->PseudoReference;
881 @references = ($pseudo_ref, grep { $_ ne $pseudo_ref } @references);
883 # If there are more than 10 references headers, remove all but the
884 # first four and the last six (Gotta keep this from growing
886 splice(@references, 4, -6) if ($#references >= 10);
888 # Add on the references
889 $self->SetHeader( 'References', join( " ", @references) );
890 $self->TemplateObj->MIMEObj->head->fold_length( 'References', 80 );
896 =head2 PseudoReference
898 Returns a fake Message-ID: header for the ticket to allow a base level of threading
902 sub PseudoReference {
905 my $pseudo_ref = '<RT-Ticket-'.$self->TicketObj->id .'@'.$RT::Organization .'>';
910 # {{{ SetHeadingAsEncoding
912 =head2 SetHeaderAsEncoding($field_name, $charset_encoding)
914 This routine converts the field into specified charset encoding.
918 sub SetHeaderAsEncoding {
920 my ( $field, $enc ) = ( shift, shift );
922 if ($field eq 'From' and $RT::SMTPFrom) {
923 $self->TemplateObj->MIMEObj->head->replace( $field, $RT::SMTPFrom );
927 my $value = $self->TemplateObj->MIMEObj->head->get($field);
929 $value = $self->MIMEEncodeString($value, $enc);
931 $self->TemplateObj->MIMEObj->head->replace( $field, $value );
937 # {{{ MIMEEncodeString
939 =head2 MIMEEncodeString STRING ENCODING
941 Takes a string and a possible encoding and returns the string wrapped in MIME goo.
945 sub MIMEEncodeString {
948 # using RFC2047 notation, sec 2.
949 # encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
952 # An 'encoded-word' may not be more than 75 characters long
954 # MIME encoding increases 4/3*(number of bytes), and always in multiples
955 # of 4. Thus we have to find the best available value of bytes available
958 # First we get the integer max which max*4/3 would fit on space.
959 # Then we find the greater multiple of 3 lower or equal than $max.
960 my $max = int(((75-length('=?'.$charset.'?'.$encoding.'?'.'?='))*3)/4);
961 $max = int($max/3)*3;
967 $RT::Logger->crit("Can't encode! Charset or encoding too big.\n");
971 return ($value) unless $value =~ /[^\x20-\x7e]/;
975 # we need perl string to split thing char by char
976 Encode::_utf8_on($value) unless Encode::is_utf8( $value );
978 my ($tmp, @chunks) = ('', ());
979 while ( length $value ) {
980 my $char = substr($value, 0, 1, '');
981 my $octets = Encode::encode( $charset, $char );
982 if ( length($tmp) + length($octets) > $max ) {
988 push @chunks, $tmp if length $tmp;
990 # encode an join chuncks
992 map encode_mimeword( $_, $encoding, $charset ), @chunks ;
998 eval "require RT::Action::SendEmail_Vendor";
999 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/SendEmail_Vendor.pm});
1000 eval "require RT::Action::SendEmail_Local";
1001 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Action/SendEmail_Local.pm});