1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC
6 # <sales@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/licenses/old-licenses/gpl-2.0.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 }}}
49 package RT::Interface::Email;
58 use UNIVERSAL::require;
60 use Text::ParseWords qw/shellwords/;
64 use vars qw ( @EXPORT_OK);
66 # set the version for version checking
69 # your exported package globals go here,
70 # as well as any optionally exported functions
75 &CheckForSuspiciousSender
76 &CheckForAutoGenerated
79 &ParseCcAddressesFromHead
80 &ParseSenderAddressFromHead
81 &ParseErrorsToAddressFromHead
82 &ParseAddressFromHeader
89 RT::Interface::Email - helper functions for parsing email sent to RT
93 use lib "!!RT_LIB_PATH!!";
94 use lib "!!RT_ETC_PATH!!";
96 use RT::Interface::Email qw(Gateway CreateUser);
105 =head2 CheckForLoops HEAD
107 Takes a HEAD object of L<MIME::Head> class and returns true if the
108 message's been sent by this RT instance. Uses "X-RT-Loop-Prevention"
109 field of the head for test.
116 # If this instance of RT sent it our, we don't want to take it in
117 my $RTLoop = $head->get("X-RT-Loop-Prevention") || "";
118 chomp ($RTLoop); # remove that newline
119 if ( $RTLoop eq RT->Config->Get('rtname') ) {
123 # TODO: We might not trap the case where RT instance A sends a mail
124 # to RT instance B which sends a mail to ...
128 =head2 CheckForSuspiciousSender HEAD
130 Takes a HEAD object of L<MIME::Head> class and returns true if sender
131 is suspicious. Suspicious means mailer daemon.
133 See also L</ParseSenderAddressFromHead>.
137 sub CheckForSuspiciousSender {
140 #if it's from a postmaster or mailer daemon, it's likely a bounce.
142 #TODO: better algorithms needed here - there is no standards for
143 #bounces, so it's very difficult to separate them from anything
144 #else. At the other hand, the Return-To address is only ment to be
145 #used as an error channel, we might want to put up a separate
146 #Return-To address which is treated differently.
148 #TODO: search through the whole email and find the right Ticket ID.
150 my ( $From, $junk ) = ParseSenderAddressFromHead($head);
152 if ( ( $From =~ /^mailer-daemon\@/i )
153 or ( $From =~ /^postmaster\@/i )
163 =head2 CheckForAutoGenerated HEAD
165 Takes a HEAD object of L<MIME::Head> class and returns true if message
166 is autogenerated. Checks 'Precedence' and 'X-FC-Machinegenerated'
167 fields of the head in tests.
171 sub CheckForAutoGenerated {
174 my $Precedence = $head->get("Precedence") || "";
175 if ( $Precedence =~ /^(bulk|junk)/i ) {
179 # Per RFC3834, any Auto-Submitted header which is not "no" means
180 # it is auto-generated.
181 my $AutoSubmitted = $head->get("Auto-Submitted") || "";
182 if ( length $AutoSubmitted and $AutoSubmitted ne "no" ) {
186 # First Class mailer uses this as a clue.
187 my $FCJunk = $head->get("X-FC-Machinegenerated") || "";
188 if ( $FCJunk =~ /^true/i ) {
199 my $ReturnPath = $head->get("Return-path") || "";
200 return ( $ReturnPath =~ /<>/ );
204 =head2 MailError PARAM HASH
206 Sends an error message. Takes a param hash:
210 =item From - sender's address, by default is 'CorrespondAddress';
212 =item To - recipient, by default is 'OwnerEmail';
214 =item Bcc - optional Bcc recipients;
216 =item Subject - subject of the message, default is 'There has been an error';
218 =item Explanation - main content of the error, default value is 'Unexplained error';
220 =item MIMEObj - optional MIME entity that's attached to the error mail, as well we
221 add 'In-Reply-To' field to the error that points to this message.
223 =item Attach - optional text that attached to the error as 'message/rfc822' part.
225 =item LogLevel - log level under which we should write explanation message into the
226 log, by default we log it as critical.
234 To => RT->Config->Get('OwnerEmail'),
236 From => RT->Config->Get('CorrespondAddress'),
237 Subject => 'There has been an error',
238 Explanation => 'Unexplained error',
246 level => $args{'LogLevel'},
247 message => $args{'Explanation'}
248 ) if $args{'LogLevel'};
250 # the colons are necessary to make ->build include non-standard headers
252 Type => "multipart/mixed",
253 From => $args{'From'},
256 Subject => $args{'Subject'},
257 'X-RT-Loop-Prevention:' => RT->Config->Get('rtname'),
260 # only set precedence if the sysadmin wants us to
261 if (defined(RT->Config->Get('DefaultErrorMailPrecedence'))) {
262 $entity_args{'Precedence:'} = RT->Config->Get('DefaultErrorMailPrecedence');
265 my $entity = MIME::Entity->build(%entity_args);
266 SetInReplyTo( Message => $entity, InReplyTo => $args{'MIMEObj'} );
268 $entity->attach( Data => $args{'Explanation'} . "\n" );
270 if ( $args{'MIMEObj'} ) {
271 $args{'MIMEObj'}->sync_headers;
272 $entity->add_part( $args{'MIMEObj'} );
275 if ( $args{'Attach'} ) {
276 $entity->attach( Data => $args{'Attach'}, Type => 'message/rfc822' );
280 SendEmail( Entity => $entity, Bounce => 1 );
284 =head2 SendEmail Entity => undef, [ Bounce => 0, Ticket => undef, Transaction => undef ]
286 Sends an email (passed as a L<MIME::Entity> object C<ENTITY>) using
287 RT's outgoing mail configuration. If C<BOUNCE> is passed, and is a
288 true value, the message will be marked as an autogenerated error, if
289 possible. Sets Date field of the head to now if it's not set.
291 If the C<X-RT-Squelch> header is set to any true value, the mail will
292 not be sent. One use is to let extensions easily cancel outgoing mail.
294 Ticket and Transaction arguments are optional. If Transaction is
295 specified and Ticket is not then ticket of the transaction is
296 used, but only if the transaction belongs to a ticket.
298 Returns 1 on success, 0 on error or -1 if message has no recipients
299 and hasn't been sent.
301 =head3 Signing and Encrypting
303 This function as well signs and/or encrypts the message according to
304 headers of a transaction's attachment or properties of a ticket's queue.
305 To get full access to the configuration Ticket and/or Transaction
306 arguments must be provided, but you can force behaviour using Sign
307 and/or Encrypt arguments.
309 The following precedence of arguments are used to figure out if
310 the message should be encrypted and/or signed:
312 * if Sign or Encrypt argument is defined then its value is used
314 * else if Transaction's first attachment has X-RT-Sign or X-RT-Encrypt
315 header field then it's value is used
317 * else properties of a queue of the Ticket are used.
326 Transaction => undef,
330 my $TicketObj = $args{'Ticket'};
331 my $TransactionObj = $args{'Transaction'};
333 foreach my $arg( qw(Entity Bounce) ) {
334 next unless defined $args{ lc $arg };
336 $RT::Logger->warning("'". lc($arg) ."' argument is deprecated, use '$arg' instead");
337 $args{ $arg } = delete $args{ lc $arg };
340 unless ( $args{'Entity'} ) {
341 $RT::Logger->crit( "Could not send mail without 'Entity' object" );
345 my $msgid = $args{'Entity'}->head->get('Message-ID') || '';
348 # If we don't have any recipients to send to, don't send a message;
349 unless ( $args{'Entity'}->head->get('To')
350 || $args{'Entity'}->head->get('Cc')
351 || $args{'Entity'}->head->get('Bcc') )
353 $RT::Logger->info( $msgid . " No recipients found. Not sending." );
357 if ($args{'Entity'}->head->get('X-RT-Squelch')) {
358 $RT::Logger->info( $msgid . " Squelch header found. Not sending." );
362 if ( $TransactionObj && !$TicketObj
363 && $TransactionObj->ObjectType eq 'RT::Ticket' )
365 $TicketObj = $TransactionObj->Object;
368 if ( RT->Config->Get('GnuPG')->{'Enable'} ) {
372 $attachment = $TransactionObj->Attachments->First
375 foreach my $argument ( qw(Sign Encrypt) ) {
376 next if defined $args{ $argument };
378 if ( $attachment && defined $attachment->GetHeader("X-RT-$argument") ) {
379 $crypt{$argument} = $attachment->GetHeader("X-RT-$argument");
380 } elsif ( $TicketObj ) {
381 $crypt{$argument} = $TicketObj->QueueObj->$argument();
385 my $res = SignEncrypt( %args, %crypt );
386 return $res unless $res > 0;
389 unless ( $args{'Entity'}->head->get('Date') ) {
391 my $date = RT::Date->new( RT->SystemUser );
393 $args{'Entity'}->head->set( 'Date', $date->RFC2822( Timezone => 'server' ) );
396 my $mail_command = RT->Config->Get('MailCommand');
398 if ($mail_command eq 'testfile' and not $Mail::Mailer::testfile::config{outfile}) {
399 $Mail::Mailer::testfile::config{outfile} = File::Temp->new;
400 $RT::Logger->info("Storing outgoing emails in $Mail::Mailer::testfile::config{outfile}");
403 # if it is a sub routine, we just return it;
404 return $mail_command->($args{'Entity'}) if UNIVERSAL::isa( $mail_command, 'CODE' );
406 if ( $mail_command eq 'sendmailpipe' ) {
407 my $path = RT->Config->Get('SendmailPath');
408 my @args = shellwords(RT->Config->Get('SendmailArguments'));
410 # SetOutgoingMailFrom and bounces conflict, since they both want -f
411 if ( $args{'Bounce'} ) {
412 push @args, shellwords(RT->Config->Get('SendmailBounceArguments'));
413 } elsif ( RT->Config->Get('SetOutgoingMailFrom') ) {
414 my $OutgoingMailAddress;
417 my $QueueName = $TicketObj->QueueObj->Name;
418 my $QueueAddressOverride = RT->Config->Get('OverrideOutgoingMailFrom')->{$QueueName};
420 if ($QueueAddressOverride) {
421 $OutgoingMailAddress = $QueueAddressOverride;
423 $OutgoingMailAddress = $TicketObj->QueueObj->CorrespondAddress;
427 $OutgoingMailAddress ||= RT->Config->Get('OverrideOutgoingMailFrom')->{'Default'};
429 push @args, "-f", $OutgoingMailAddress
430 if $OutgoingMailAddress;
434 if ( $TransactionObj and
435 my $prefix = RT->Config->Get('VERPPrefix') and
436 my $domain = RT->Config->Get('VERPDomain') )
438 my $from = $TransactionObj->CreatorObj->EmailAddress;
441 push @args, "-f", "$prefix$from\@$domain";
445 # don't ignore CHLD signal to get proper exit code
446 local $SIG{'CHLD'} = 'DEFAULT';
448 # if something wrong with $mail->print we will get PIPE signal, handle it
449 local $SIG{'PIPE'} = sub { die "program unexpectedly closed pipe" };
453 my $pid = IPC::Open2::open2( $stdout, $mail, $path, @args )
454 or die "couldn't execute program: $!";
456 $args{'Entity'}->print($mail);
457 close $mail or die "close pipe failed: $!";
461 # sendmail exit statuses mostly errors with data not software
462 # TODO: status parsing: core dump, exit on signal or EX_*
463 my $msg = "$msgid: `$path @args` exited with code ". ($?>>8);
464 $msg = ", interrupted by signal ". ($?&127) if $?&127;
465 $RT::Logger->error( $msg );
470 $RT::Logger->crit( "$msgid: Could not send mail with command `$path @args`: " . $@ );
472 _RecordSendEmailFailure( $TicketObj );
477 elsif ( $mail_command eq 'smtp' ) {
479 my $smtp = do { local $@; eval { Net::SMTP->new(
480 Host => RT->Config->Get('SMTPServer'),
481 Debug => RT->Config->Get('SMTPDebug'),
484 $RT::Logger->crit( "Could not connect to SMTP server.");
486 _RecordSendEmailFailure( $TicketObj );
491 # duplicate head as we want drop Bcc field
492 my $head = $args{'Entity'}->head->dup;
493 my @recipients = map $_->address, map
494 Email::Address->parse($head->get($_)), qw(To Cc Bcc);
495 $head->delete('Bcc');
497 my $sender = RT->Config->Get('SMTPFrom')
498 || $args{'Entity'}->head->get('From');
501 my $status = $smtp->mail( $sender )
502 && $smtp->recipient( @recipients );
506 my $fh = $smtp->tied_fh;
509 $args{'Entity'}->print_body( $fh );
515 $RT::Logger->crit( "$msgid: Could not send mail via SMTP." );
517 _RecordSendEmailFailure( $TicketObj );
523 local ($ENV{'MAILADDRESS'}, $ENV{'PERL_MAILERS'});
525 my @mailer_args = ($mail_command);
526 if ( $mail_command eq 'sendmail' ) {
527 $ENV{'PERL_MAILERS'} = RT->Config->Get('SendmailPath');
528 push @mailer_args, split(/\s+/, RT->Config->Get('SendmailArguments'));
531 push @mailer_args, RT->Config->Get('MailParams');
534 unless ( $args{'Entity'}->send( @mailer_args ) ) {
535 $RT::Logger->crit( "$msgid: Could not send mail." );
537 _RecordSendEmailFailure( $TicketObj );
545 =head2 PrepareEmailUsingTemplate Template => '', Arguments => {}
547 Loads a template. Parses it using arguments if it's not empty.
548 Returns a tuple (L<RT::Template> object, error message).
550 Note that even if a template object is returned MIMEObj method
551 may return undef for empty templates.
555 sub PrepareEmailUsingTemplate {
562 my $template = RT::Template->new( RT->SystemUser );
563 $template->LoadGlobalTemplate( $args{'Template'} );
564 unless ( $template->id ) {
565 return (undef, "Couldn't load template '". $args{'Template'} ."'");
567 return $template if $template->IsEmpty;
569 my ($status, $msg) = $template->Parse( %{ $args{'Arguments'} } );
570 return (undef, $msg) unless $status;
575 =head2 SendEmailUsingTemplate Template => '', Arguments => {}, From => CorrespondAddress, To => '', Cc => '', Bcc => ''
577 Sends email using a template, takes name of template, arguments for it and recipients.
581 sub SendEmailUsingTemplate {
588 From => RT->Config->Get('CorrespondAddress'),
594 my ($template, $msg) = PrepareEmailUsingTemplate( %args );
595 return (0, $msg) unless $template;
597 my $mail = $template->MIMEObj;
599 $RT::Logger->info("Message is not sent as template #". $template->id ." is empty");
603 $mail->head->set( $_ => Encode::encode_utf8( $args{ $_ } ) )
604 foreach grep defined $args{$_}, qw(To Cc Bcc From);
606 $mail->head->set( $_ => $args{ExtraHeaders}{$_} )
607 foreach keys %{ $args{ExtraHeaders} };
609 SetInReplyTo( Message => $mail, InReplyTo => $args{'InReplyTo'} );
611 return SendEmail( Entity => $mail );
614 =head2 ForwardTransaction TRANSACTION, To => '', Cc => '', Bcc => ''
616 Forwards transaction with all attachments as 'message/rfc822'.
620 sub ForwardTransaction {
622 my %args = ( To => '', Cc => '', Bcc => '', @_ );
624 my $entity = $txn->ContentAsMIME;
626 my ( $ret, $msg ) = SendForward( %args, Entity => $entity, Transaction => $txn );
628 my $ticket = $txn->TicketObj;
629 my ( $ret, $msg ) = $ticket->_NewTransaction(
630 Type => 'Forward Transaction',
632 Data => join ', ', grep { length } $args{To}, $args{Cc}, $args{Bcc},
635 $RT::Logger->error("Failed to create transaction: $msg");
638 return ( $ret, $msg );
641 =head2 ForwardTicket TICKET, To => '', Cc => '', Bcc => ''
643 Forwards a ticket's Create and Correspond Transactions and their Attachments as 'message/rfc822'.
649 my %args = ( To => '', Cc => '', Bcc => '', @_ );
651 my $txns = $ticket->Transactions;
655 ) for qw(Create Correspond);
657 my $entity = MIME::Entity->build(
658 Type => 'multipart/mixed',
659 Description => 'forwarded ticket',
661 $entity->add_part( $_ ) foreach
662 map $_->ContentAsMIME,
663 @{ $txns->ItemsArrayRef };
665 my ( $ret, $msg ) = SendForward(
669 Template => 'Forward Ticket',
673 my ( $ret, $msg ) = $ticket->_NewTransaction(
674 Type => 'Forward Ticket',
675 Field => $ticket->id,
676 Data => join ', ', grep { length } $args{To}, $args{Cc}, $args{Bcc},
679 $RT::Logger->error("Failed to create transaction: $msg");
683 return ( $ret, $msg );
687 =head2 SendForward Entity => undef, Ticket => undef, Transaction => undef, Template => undef, To => '', Cc => '', Bcc => ''
689 Forwards an Entity representing Ticket or Transaction as 'message/rfc822'. Entity is wrapped into Template.
697 Transaction => undef,
698 Template => 'Forward',
699 To => '', Cc => '', Bcc => '',
703 my $txn = $args{'Transaction'};
704 my $ticket = $args{'Ticket'};
705 $ticket ||= $txn->Object if $txn;
707 my $entity = $args{'Entity'};
710 $RT::Logger->error(Carp::longmess("No entity provided"));
711 return (0, $ticket->loc("Couldn't send email"));
714 my ($template, $msg) = PrepareEmailUsingTemplate(
715 Template => $args{'Template'},
724 $mail = $template->MIMEObj;
726 $RT::Logger->warning($msg);
729 $RT::Logger->warning("Couldn't generate email using template '$args{Template}'");
732 unless ( $args{'Transaction'} ) {
733 $description = 'This is forward of ticket #'. $ticket->id;
735 $description = 'This is forward of transaction #'
736 . $txn->id ." of a ticket #". $txn->ObjectId;
738 $mail = MIME::Entity->build(
739 Type => 'text/plain',
740 Data => $description,
744 $mail->head->set( $_ => EncodeToMIME( String => $args{$_} ) )
745 foreach grep defined $args{$_}, qw(To Cc Bcc);
747 $mail->make_multipart unless $mail->is_multipart;
748 $mail->add_part( $entity );
752 $subject = $txn->Subject if $txn;
753 $subject ||= $ticket->Subject if $ticket;
755 unless ( RT->Config->Get('ForwardFromUser') ) {
756 # XXX: what if want to forward txn of other object than ticket?
757 $subject = AddSubjectTag( $subject, $ticket );
760 $mail->head->set( Subject => EncodeToMIME( String => "Fwd: $subject" ) );
762 From => EncodeToMIME(
763 String => GetForwardFrom( Transaction => $txn, Ticket => $ticket )
767 my $status = RT->Config->Get('ForwardFromUser')
768 # never sign if we forward from User
769 ? SendEmail( %args, Entity => $mail, Sign => 0 )
770 : SendEmail( %args, Entity => $mail );
771 return (0, $ticket->loc("Couldn't send email")) unless $status;
772 return (1, $ticket->loc("Sent email successfully"));
775 =head2 GetForwardFrom Ticket => undef, Transaction => undef
777 Resolve the From field to use in forward mail
782 my %args = ( Ticket => undef, Transaction => undef, @_ );
783 my $txn = $args{Transaction};
784 my $ticket = $args{Ticket} || $txn->Object;
786 if ( RT->Config->Get('ForwardFromUser') ) {
787 return ( $txn || $ticket )->CurrentUser->UserObj->EmailAddress;
790 return $ticket->QueueObj->CorrespondAddress
791 || RT->Config->Get('CorrespondAddress');
795 =head2 SignEncrypt Entity => undef, Sign => 0, Encrypt => 0
797 Signs and encrypts message using L<RT::Crypt::GnuPG>, but as well
798 handle errors with users' keys.
800 If a recipient has no key or has other problems with it, then the
801 unction sends a error to him using 'Error: public key' template.
802 Also, notifies RT's owner using template 'Error to RT owner: public key'
803 to inform that there are problems with users' keys. Then we filter
804 all bad recipients and retry.
806 Returns 1 on success, 0 on error and -1 if all recipients are bad and
807 had been filtered out.
818 return 1 unless $args{'Sign'} || $args{'Encrypt'};
820 my $msgid = $args{'Entity'}->head->get('Message-ID') || '';
823 $RT::Logger->debug("$msgid Signing message") if $args{'Sign'};
824 $RT::Logger->debug("$msgid Encrypting message") if $args{'Encrypt'};
826 require RT::Crypt::GnuPG;
827 my %res = RT::Crypt::GnuPG::SignEncrypt( %args );
828 return 1 unless $res{'exit_code'};
830 my @status = RT::Crypt::GnuPG::ParseStatus( $res{'status'} );
833 foreach my $line ( @status ) {
834 # if the passphrase fails, either you have a bad passphrase
835 # or gpg-agent has died. That should get caught in Create and
836 # Update, but at least throw an error here
837 if (($line->{'Operation'}||'') eq 'PassphraseCheck'
838 && $line->{'Status'} =~ /^(?:BAD|MISSING)$/ ) {
839 $RT::Logger->error( "$line->{'Status'} PASSPHRASE: $line->{'Message'}" );
842 next unless ($line->{'Operation'}||'') eq 'RecipientsCheck';
843 next if $line->{'Status'} eq 'DONE';
844 $RT::Logger->error( $line->{'Message'} );
845 push @bad_recipients, $line;
847 return 0 unless @bad_recipients;
849 $_->{'AddressObj'} = (Email::Address->parse( $_->{'Recipient'} ))[0]
850 foreach @bad_recipients;
852 foreach my $recipient ( @bad_recipients ) {
853 my $status = SendEmailUsingTemplate(
854 To => $recipient->{'AddressObj'}->address,
855 Template => 'Error: public key',
858 TicketObj => $args{'Ticket'},
859 TransactionObj => $args{'Transaction'},
863 $RT::Logger->error("Couldn't send 'Error: public key'");
867 my $status = SendEmailUsingTemplate(
868 To => RT->Config->Get('OwnerEmail'),
869 Template => 'Error to RT owner: public key',
871 BadRecipients => \@bad_recipients,
872 TicketObj => $args{'Ticket'},
873 TransactionObj => $args{'Transaction'},
877 $RT::Logger->error("Couldn't send 'Error to RT owner: public key'");
880 DeleteRecipientsFromHead(
881 $args{'Entity'}->head,
882 map $_->{'AddressObj'}->address, @bad_recipients
885 unless ( $args{'Entity'}->head->get('To')
886 || $args{'Entity'}->head->get('Cc')
887 || $args{'Entity'}->head->get('Bcc') )
889 $RT::Logger->debug("$msgid No recipients that have public key, not sending");
893 # redo without broken recipients
894 %res = RT::Crypt::GnuPG::SignEncrypt( %args );
895 return 0 if $res{'exit_code'};
904 Takes a hash with a String and a Charset. Returns the string encoded
905 according to RFC2047, using B (base64 based) encoding.
907 String must be a perl string, octets are returned.
909 If Charset is not provided then $EmailOutputEncoding config option
910 is used, or "latin-1" if that is not set.
920 my $value = $args{'String'};
921 return $value unless $value; # 0 is perfect ascii
922 my $charset = $args{'Charset'} || RT->Config->Get('EmailOutputEncoding');
925 # using RFC2047 notation, sec 2.
926 # encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
928 # An 'encoded-word' may not be more than 75 characters long
930 # MIME encoding increases 4/3*(number of bytes), and always in multiples
931 # of 4. Thus we have to find the best available value of bytes available
934 # First we get the integer max which max*4/3 would fit on space.
935 # Then we find the greater multiple of 3 lower or equal than $max.
937 ( ( 75 - length( '=?' . $charset . '?' . $encoding . '?' . '?=' ) )
941 $max = int( $max / 3 ) * 3;
948 $RT::Logger->crit("Can't encode! Charset or encoding too big.");
952 return ($value) if $value =~ /^(?:[\t\x20-\x7e]|\x0D*\x0A[ \t])+$/s;
956 # we need perl string to split thing char by char
957 Encode::_utf8_on($value) unless Encode::is_utf8($value);
959 my ( $tmp, @chunks ) = ( '', () );
960 while ( length $value ) {
961 my $char = substr( $value, 0, 1, '' );
962 my $octets = Encode::encode( $charset, $char );
963 if ( length($tmp) + length($octets) > $max ) {
969 push @chunks, $tmp if length $tmp;
971 # encode an join chuncks
973 map MIME::Words::encode_mimeword( $_, $encoding, $charset ),
979 my ( $Username, $Address, $Name, $ErrorsTo, $entity ) = @_;
981 my $NewUser = RT::User->new( RT->SystemUser );
983 my ( $Val, $Message ) = $NewUser->Create(
984 Name => ( $Username || $Address ),
985 EmailAddress => $Address,
989 Comments => 'Autocreated on ticket submission',
994 # Deal with the race condition of two account creations at once
996 $NewUser->LoadByName($Username);
999 unless ( $NewUser->Id ) {
1000 $NewUser->LoadByEmail($Address);
1003 unless ( $NewUser->Id ) {
1006 Subject => "User could not be created",
1008 "User creation failed in mailgateway: $Message",
1015 #Load the new user object
1016 my $CurrentUser = RT::CurrentUser->new;
1017 $CurrentUser->LoadByEmail( $Address );
1019 unless ( $CurrentUser->id ) {
1020 $RT::Logger->warning(
1021 "Couldn't load user '$Address'." . "giving up" );
1024 Subject => "User could not be loaded",
1026 "User '$Address' could not be loaded in the mail gateway",
1032 return $CurrentUser;
1037 =head2 ParseCcAddressesFromHead HASH
1039 Takes a hash containing QueueObj, Head and CurrentUser objects.
1040 Returns a list of all email addresses in the To and Cc
1041 headers b<except> the current Queue\'s email addresses, the CurrentUser\'s
1042 email address and anything that the configuration sub RT::IsRTAddress matches.
1046 sub ParseCcAddressesFromHead {
1050 CurrentUser => undef,
1054 my $current_address = lc $args{'CurrentUser'}->EmailAddress;
1055 my $user = $args{'CurrentUser'}->UserObj;
1058 grep $_ ne $current_address && !RT::EmailParser->IsRTAddress( $_ ),
1059 map lc $user->CanonicalizeEmailAddress( $_->address ),
1060 map Email::Address->parse( $args{'Head'}->get( $_ ) ),
1066 =head2 ParseSenderAddressFromHead HEAD
1068 Takes a MIME::Header object. Returns a tuple: (user@host, friendly name)
1069 of the From (evaluated in order of Reply-To:, From:, Sender)
1073 sub ParseSenderAddressFromHead {
1076 #Figure out who's sending this message.
1077 foreach my $header ('Reply-To', 'From', 'Sender') {
1078 my $addr_line = $head->get($header) || next;
1079 my ($addr, $name) = ParseAddressFromHeader( $addr_line );
1080 # only return if the address is not empty
1081 return ($addr, $name) if $addr;
1084 return (undef, undef);
1087 =head2 ParseErrorsToAddressFromHead HEAD
1089 Takes a MIME::Header object. Return a single value : user@host
1090 of the From (evaluated in order of Return-path:,Errors-To:,Reply-To:,
1095 sub ParseErrorsToAddressFromHead {
1098 #Figure out who's sending this message.
1100 foreach my $header ( 'Errors-To', 'Reply-To', 'From', 'Sender' ) {
1102 # If there's a header of that name
1103 my $headerobj = $head->get($header);
1105 my ( $addr, $name ) = ParseAddressFromHeader($headerobj);
1107 # If it's got actual useful content...
1108 return ($addr) if ($addr);
1115 =head2 ParseAddressFromHeader ADDRESS
1117 Takes an address from C<$head->get('Line')> and returns a tuple: user@host, friendly name
1121 sub ParseAddressFromHeader {
1124 # Some broken mailers send: ""Vincent, Jesse"" <jesse@fsck.com>. Hate
1125 $Addr =~ s/\"\"(.*?)\"\"/\"$1\"/g;
1126 my @Addresses = RT::EmailParser->ParseEmailAddress($Addr);
1128 my ($AddrObj) = grep ref $_, @Addresses;
1129 unless ( $AddrObj ) {
1130 return ( undef, undef );
1133 return ( $AddrObj->address, $AddrObj->phrase );
1136 =head2 DeleteRecipientsFromHead HEAD RECIPIENTS
1138 Gets a head object and list of addresses.
1139 Deletes addresses from To, Cc or Bcc fields.
1143 sub DeleteRecipientsFromHead {
1145 my %skip = map { lc $_ => 1 } @_;
1147 foreach my $field ( qw(To Cc Bcc) ) {
1148 $head->set( $field =>
1149 join ', ', map $_->format, grep !$skip{ lc $_->address },
1150 Email::Address->parse( $head->get( $field ) )
1159 ScripAction => undef,
1162 my $org = RT->Config->Get('Organization');
1163 my $ticket_id = ( ref $args{'Ticket'}? $args{'Ticket'}->id : $args{'Ticket'} ) || 0;
1164 my $scrip_id = ( ref $args{'Scrip'}? $args{'Scrip'}->id : $args{'Scrip'} ) || 0;
1165 my $sent = ( ref $args{'ScripAction'}? $args{'ScripAction'}->{'_Message_ID'} : 0 ) || 0;
1167 return "<rt-". $RT::VERSION ."-". $$ ."-". CORE::time() ."-". int(rand(2000)) .'.'
1168 . $ticket_id ."-". $scrip_id ."-". $sent ."@". $org .">" ;
1178 return unless $args{'Message'} && $args{'InReplyTo'};
1180 my $get_header = sub {
1182 if ( $args{'InReplyTo'}->isa('MIME::Entity') ) {
1183 @res = $args{'InReplyTo'}->head->get( shift );
1185 @res = $args{'InReplyTo'}->GetHeader( shift ) || '';
1187 return grep length, map { split /\s+/m, $_ } grep defined, @res;
1190 my @id = $get_header->('Message-ID');
1191 #XXX: custom header should begin with X- otherwise is violation of the standard
1192 my @rtid = $get_header->('RT-Message-ID');
1193 my @references = $get_header->('References');
1194 unless ( @references ) {
1195 @references = $get_header->('In-Reply-To');
1197 push @references, @id, @rtid;
1198 if ( $args{'Ticket'} ) {
1199 my $pseudo_ref = '<RT-Ticket-'. $args{'Ticket'}->id .'@'. RT->Config->Get('Organization') .'>';
1200 push @references, $pseudo_ref unless grep $_ eq $pseudo_ref, @references;
1202 @references = splice @references, 4, -6
1203 if @references > 10;
1205 my $mail = $args{'Message'};
1206 $mail->head->set( 'In-Reply-To' => join ' ', @rtid? (@rtid) : (@id) ) if @id || @rtid;
1207 $mail->head->set( 'References' => join ' ', @references );
1211 my $Subject = shift;
1213 my $rtname = RT->Config->Get('rtname');
1214 my $test_name = RT->Config->Get('EmailSubjectTagRegex') || qr/\Q$rtname\E/i;
1217 if ( $Subject =~ s/\[$test_name\s+\#(\d+)\s*\]//i ) {
1220 foreach my $tag ( RT->System->SubjectTag ) {
1221 next unless $Subject =~ s/\[\Q$tag\E\s+\#(\d+)\s*\]//i;
1226 return undef unless $id;
1228 $RT::Logger->debug("Found a ticket ID. It's $id");
1233 my $subject = shift;
1235 unless ( ref $ticket ) {
1236 my $tmp = RT::Ticket->new( RT->SystemUser );
1237 $tmp->Load( $ticket );
1240 my $id = $ticket->id;
1241 my $queue_tag = $ticket->QueueObj->SubjectTag;
1243 my $tag_re = RT->Config->Get('EmailSubjectTagRegex');
1244 unless ( $tag_re ) {
1245 my $tag = $queue_tag || RT->Config->Get('rtname');
1246 $tag_re = qr/\Q$tag\E/;
1247 } elsif ( $queue_tag ) {
1248 $tag_re = qr/$tag_re|\Q$queue_tag\E/;
1250 return $subject if $subject =~ /\[$tag_re\s+#$id\]/;
1252 $subject =~ s/(\r\n|\n|\s)/ /g;
1254 return "[". ($queue_tag || RT->Config->Get('rtname')) ." #$id] $subject";
1258 =head2 Gateway ARGSREF
1268 This performs all the "guts" of the mail rt-mailgate program, and is
1269 designed to be called from the web interface with a message, user
1272 Can also take an optional 'ticket' parameter; this ticket id overrides
1273 any ticket id found in the subject.
1279 (status code, message, optional ticket object)
1281 status code is a numeric value.
1283 for temporary failures, the status code should be -75
1285 for permanent failures which are handled by RT, the status code
1288 for succces, the status code should be 1
1295 my @mail_plugins = @_;
1298 foreach my $plugin (@mail_plugins) {
1299 if ( ref($plugin) eq "CODE" ) {
1301 } elsif ( !ref $plugin ) {
1302 my $Class = $plugin;
1303 $Class = "RT::Interface::Email::" . $Class
1304 unless $Class =~ /^RT::/;
1306 do { $RT::Logger->error("Couldn't load $Class: $@"); next };
1309 unless ( defined *{ $Class . "::GetCurrentUser" }{CODE} ) {
1310 $RT::Logger->crit( "No GetCurrentUser code found in $Class module");
1315 $RT::Logger->crit( "$plugin - is not class name or code reference");
1322 my $argsref = shift;
1324 action => 'correspond',
1334 # Validate the action
1335 my ( $status, @actions ) = IsCorrectAction( $args{'action'} );
1339 "Invalid 'action' parameter "
1347 my $parser = RT::EmailParser->new();
1348 $parser->SmartParseMIMEEntityFromScalar(
1349 Message => $args{'message'},
1354 my $Message = $parser->Entity();
1357 Subject => "RT Bounce: Unparseable message",
1358 Explanation => "RT couldn't process the message below",
1359 Attach => $args{'message'}
1363 "Failed to parse this message. Something is likely badly wrong with the message"
1367 my @mail_plugins = grep $_, RT->Config->Get('MailPlugins');
1368 push @mail_plugins, "Auth::MailFrom" unless @mail_plugins;
1369 @mail_plugins = _LoadPlugins( @mail_plugins );
1372 foreach my $class( grep !ref, @mail_plugins ) {
1373 # check if we should apply filter before decoding
1376 *{ $class . "::ApplyBeforeDecode" }{CODE};
1378 next unless defined $check_cb;
1379 next unless $check_cb->(
1380 Message => $Message,
1381 RawMessageRef => \$args{'message'},
1384 $skip_plugin{ $class }++;
1388 *{ $class . "::GetCurrentUser" }{CODE};
1390 my ($status, $msg) = $Code->(
1391 Message => $Message,
1392 RawMessageRef => \$args{'message'},
1394 next if $status > 0;
1396 if ( $status == -2 ) {
1397 return (1, $msg, undef);
1398 } elsif ( $status == -1 ) {
1399 return (0, $msg, undef);
1402 @mail_plugins = grep !$skip_plugin{"$_"}, @mail_plugins;
1403 $parser->_DecodeBodies;
1404 $parser->_PostProcessNewEntity;
1406 my $head = $Message->head;
1407 my $ErrorsTo = ParseErrorsToAddressFromHead( $head );
1409 my $MessageId = $head->get('Message-ID')
1410 || "<no-message-id-". time . rand(2000) .'@'. RT->Config->Get('Organization') .'>';
1412 #Pull apart the subject line
1413 my $Subject = $head->get('Subject') || '';
1416 # Lets check for mail loops of various sorts.
1417 my ($should_store_machine_generated_message, $IsALoop, $result);
1418 ( $should_store_machine_generated_message, $ErrorsTo, $result, $IsALoop ) =
1419 _HandleMachineGeneratedMail(
1420 Message => $Message,
1421 ErrorsTo => $ErrorsTo,
1422 Subject => $Subject,
1423 MessageId => $MessageId
1426 # Do not pass loop messages to MailPlugins, to make sure the loop
1427 # is broken, unless $RT::StoreLoops is set.
1428 if ($IsALoop && !$should_store_machine_generated_message) {
1429 return ( 0, $result, undef );
1433 $args{'ticket'} ||= ParseTicketId( $Subject );
1435 $SystemTicket = RT::Ticket->new( RT->SystemUser );
1436 $SystemTicket->Load( $args{'ticket'} ) if ( $args{'ticket'} ) ;
1437 if ( $SystemTicket->id ) {
1438 $Right = 'ReplyToTicket';
1440 $Right = 'CreateTicket';
1443 #Set up a queue object
1444 my $SystemQueueObj = RT::Queue->new( RT->SystemUser );
1445 $SystemQueueObj->Load( $args{'queue'} );
1447 # We can safely have no queue of we have a known-good ticket
1448 unless ( $SystemTicket->id || $SystemQueueObj->id ) {
1449 return ( -75, "RT couldn't find the queue: " . $args{'queue'}, undef );
1452 my ($AuthStat, $CurrentUser, $error) = GetAuthenticationLevel(
1453 MailPlugins => \@mail_plugins,
1454 Actions => \@actions,
1455 Message => $Message,
1456 RawMessageRef => \$args{message},
1457 SystemTicket => $SystemTicket,
1458 SystemQueue => $SystemQueueObj,
1461 # If authentication fails and no new user was created, get out.
1462 if ( !$CurrentUser || !$CurrentUser->id || $AuthStat == -1 ) {
1464 # If the plugins refused to create one, they lose.
1465 unless ( $AuthStat == -1 ) {
1466 _NoAuthorizedUserFound(
1468 Message => $Message,
1469 Requestor => $ErrorsTo,
1470 Queue => $args{'queue'}
1474 return ( 0, "Could not load a valid user", undef );
1477 # If we got a user, but they don't have the right to say things
1478 if ( $AuthStat == 0 ) {
1481 Subject => "Permission Denied",
1483 "You do not have permission to communicate with RT",
1488 "$ErrorsTo tried to submit a message to "
1490 . " without permission.",
1496 unless ($should_store_machine_generated_message) {
1497 return ( 0, $result, undef );
1500 # if plugin's updated SystemTicket then update arguments
1501 $args{'ticket'} = $SystemTicket->Id if $SystemTicket && $SystemTicket->Id;
1503 my $Ticket = RT::Ticket->new($CurrentUser);
1505 if ( !$args{'ticket'} && grep /^(comment|correspond)$/, @actions )
1509 my @Requestors = ( $CurrentUser->id );
1511 if (RT->Config->Get('ParseNewMessageForTicketCcs')) {
1512 @Cc = ParseCcAddressesFromHead(
1514 CurrentUser => $CurrentUser,
1515 QueueObj => $SystemQueueObj
1519 my ( $id, $Transaction, $ErrStr ) = $Ticket->Create(
1520 Queue => $SystemQueueObj->Id,
1521 Subject => $Subject,
1522 Requestor => \@Requestors,
1529 Subject => "Ticket creation failed: $Subject",
1530 Explanation => $ErrStr,
1533 return ( 0, "Ticket creation failed: $ErrStr", $Ticket );
1536 # strip comments&corresponds from the actions we don't need
1537 # to record them if we've created the ticket just now
1538 @actions = grep !/^(comment|correspond)$/, @actions;
1539 $args{'ticket'} = $id;
1541 } elsif ( $args{'ticket'} ) {
1543 $Ticket->Load( $args{'ticket'} );
1544 unless ( $Ticket->Id ) {
1545 my $error = "Could not find a ticket with id " . $args{'ticket'};
1548 Subject => "Message not recorded: $Subject",
1549 Explanation => $error,
1553 return ( 0, $error );
1555 $args{'ticket'} = $Ticket->id;
1557 return ( 1, "Success", $Ticket );
1562 my $unsafe_actions = RT->Config->Get('UnsafeEmailCommands');
1563 foreach my $action (@actions) {
1565 # If the action is comment, add a comment.
1566 if ( $action =~ /^(?:comment|correspond)$/i ) {
1567 my $method = ucfirst lc $action;
1568 my ( $status, $msg ) = $Ticket->$method( MIMEObj => $Message );
1571 #Warn the sender that we couldn't actually submit the comment.
1574 Subject => "Message not recorded: $Subject",
1575 Explanation => $msg,
1578 return ( 0, "Message not recorded: $msg", $Ticket );
1580 } elsif ($unsafe_actions) {
1581 my ( $status, $msg ) = _RunUnsafeAction(
1583 ErrorsTo => $ErrorsTo,
1584 Message => $Message,
1586 CurrentUser => $CurrentUser,
1588 return ($status, $msg, $Ticket) unless $status == 1;
1591 return ( 1, "Success", $Ticket );
1594 =head2 GetAuthenticationLevel
1596 # Authentication Level
1597 # -1 - Get out. this user has been explicitly declined
1598 # 0 - User may not do anything (Not used at the moment)
1600 # 2 - User is allowed to specify status updates etc. a la enhanced-mailgate
1604 sub GetAuthenticationLevel {
1609 RawMessageRef => undef,
1610 SystemTicket => undef,
1611 SystemQueue => undef,
1615 my ( $CurrentUser, $AuthStat, $error );
1617 # Initalize AuthStat so comparisons work correctly
1618 $AuthStat = -9999999;
1620 # if plugin returns AuthStat -2 we skip action
1621 # NOTE: this is experimental API and it would be changed
1622 my %skip_action = ();
1624 # Since this needs loading, no matter what
1625 foreach (@{ $args{MailPlugins} }) {
1626 my ($Code, $NewAuthStat);
1627 if ( ref($_) eq "CODE" ) {
1631 $Code = *{ $_ . "::GetCurrentUser" }{CODE};
1634 foreach my $action (@{ $args{Actions} }) {
1635 ( $CurrentUser, $NewAuthStat ) = $Code->(
1636 Message => $args{Message},
1637 RawMessageRef => $args{RawMessageRef},
1638 CurrentUser => $CurrentUser,
1639 AuthLevel => $AuthStat,
1641 Ticket => $args{SystemTicket},
1642 Queue => $args{SystemQueue},
1645 # You get the highest level of authentication you were assigned, unless you get the magic -1
1646 # If a module returns a "-1" then we discard the ticket, so.
1647 $AuthStat = $NewAuthStat
1648 if ( $NewAuthStat > $AuthStat or $NewAuthStat == -1 or $NewAuthStat == -2 );
1650 last if $AuthStat == -1;
1651 $skip_action{$action}++ if $AuthStat == -2;
1654 # strip actions we should skip
1655 @{$args{Actions}} = grep !$skip_action{$_}, @{$args{Actions}}
1657 last unless @{$args{Actions}};
1659 last if $AuthStat == -1;
1662 return $AuthStat if !wantarray;
1664 return ($AuthStat, $CurrentUser, $error);
1667 sub _RunUnsafeAction {
1673 CurrentUser => undef,
1677 if ( $args{'Action'} =~ /^take$/i ) {
1678 my ( $status, $msg ) = $args{'Ticket'}->SetOwner( $args{'CurrentUser'}->id );
1681 To => $args{'ErrorsTo'},
1682 Subject => "Ticket not taken",
1683 Explanation => $msg,
1684 MIMEObj => $args{'Message'}
1686 return ( 0, "Ticket not taken" );
1688 } elsif ( $args{'Action'} =~ /^resolve$/i ) {
1689 my ( $status, $msg ) = $args{'Ticket'}->SetStatus('resolved');
1692 #Warn the sender that we couldn't actually submit the comment.
1694 To => $args{'ErrorsTo'},
1695 Subject => "Ticket not resolved",
1696 Explanation => $msg,
1697 MIMEObj => $args{'Message'}
1699 return ( 0, "Ticket not resolved" );
1702 return ( 0, "Not supported unsafe action $args{'Action'}", $args{'Ticket'} );
1704 return ( 1, "Success" );
1707 =head2 _NoAuthorizedUserFound
1709 Emails the RT Owner and the requestor when the auth plugins return "No auth user found"
1713 sub _NoAuthorizedUserFound {
1722 # Notify the RT Admin of the failure.
1724 To => RT->Config->Get('OwnerEmail'),
1725 Subject => "Could not load a valid user",
1726 Explanation => <<EOT,
1727 RT could not load a valid user, and RT's configuration does not allow
1728 for the creation of a new user for this email (@{[$args{Requestor}]}).
1730 You might need to grant 'Everyone' the right '@{[$args{Right}]}' for the
1731 queue @{[$args{'Queue'}]}.
1734 MIMEObj => $args{'Message'},
1738 # Also notify the requestor that his request has been dropped.
1739 if ($args{'Requestor'} ne RT->Config->Get('OwnerEmail')) {
1741 To => $args{'Requestor'},
1742 Subject => "Could not load a valid user",
1743 Explanation => <<EOT,
1744 RT could not load a valid user, and RT's configuration does not allow
1745 for the creation of a new user for your email.
1748 MIMEObj => $args{'Message'},
1754 =head2 _HandleMachineGeneratedMail
1761 Checks the message to see if it's a bounce, if it looks like a loop, if it's autogenerated, etc.
1762 Returns a triple of ("Should we continue (boolean)", "New value for $ErrorsTo", "Status message",
1763 "This message appears to be a loop (boolean)" );
1767 sub _HandleMachineGeneratedMail {
1768 my %args = ( Message => undef, ErrorsTo => undef, Subject => undef, MessageId => undef, @_ );
1769 my $head = $args{'Message'}->head;
1770 my $ErrorsTo = $args{'ErrorsTo'};
1772 my $IsBounce = CheckForBounce($head);
1774 my $IsAutoGenerated = CheckForAutoGenerated($head);
1776 my $IsSuspiciousSender = CheckForSuspiciousSender($head);
1778 my $IsALoop = CheckForLoops($head);
1780 my $SquelchReplies = 0;
1782 my $owner_mail = RT->Config->Get('OwnerEmail');
1784 #If the message is autogenerated, we need to know, so we can not
1785 # send mail to the sender
1786 if ( $IsBounce || $IsSuspiciousSender || $IsAutoGenerated || $IsALoop ) {
1787 $SquelchReplies = 1;
1788 $ErrorsTo = $owner_mail;
1791 # Warn someone if it's a loop, before we drop it on the ground
1793 $RT::Logger->crit("RT Received mail (".$args{MessageId}.") from itself.");
1795 #Should we mail it to RTOwner?
1796 if ( RT->Config->Get('LoopsToRTOwner') ) {
1799 Subject => "RT Bounce: ".$args{'Subject'},
1800 Explanation => "RT thinks this message may be a bounce",
1801 MIMEObj => $args{Message}
1805 #Do we actually want to store it?
1806 return ( 0, $ErrorsTo, "Message Bounced", $IsALoop )
1807 unless RT->Config->Get('StoreLoops');
1810 # Squelch replies if necessary
1811 # Don't let the user stuff the RT-Squelch-Replies-To header.
1812 if ( $head->get('RT-Squelch-Replies-To') ) {
1814 'RT-Relocated-Squelch-Replies-To',
1815 $head->get('RT-Squelch-Replies-To')
1817 $head->delete('RT-Squelch-Replies-To');
1820 if ($SquelchReplies) {
1822 # Squelch replies to the sender, and also leave a clue to
1823 # allow us to squelch ALL outbound messages. This way we
1824 # can punt the logic of "what to do when we get a bounce"
1825 # to the scrip. We might want to notify nobody. Or just
1826 # the RT Owner. Or maybe all Privileged watchers.
1827 my ( $Sender, $junk ) = ParseSenderAddressFromHead($head);
1828 $head->replace( 'RT-Squelch-Replies-To', $Sender );
1829 $head->replace( 'RT-DetectedAutoGenerated', 'true' );
1831 return ( 1, $ErrorsTo, "Handled machine detection", $IsALoop );
1834 =head2 IsCorrectAction
1836 Returns a list of valid actions we've found for this message
1840 sub IsCorrectAction {
1842 my @actions = grep $_, split /-/, $action;
1843 return ( 0, '(no value)' ) unless @actions;
1844 foreach ( @actions ) {
1845 return ( 0, $_ ) unless /^(?:comment|correspond|take|resolve)$/;
1847 return ( 1, @actions );
1850 sub _RecordSendEmailFailure {
1853 $ticket->_RecordNote(
1854 NoteType => 'SystemError',
1855 Content => "Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.",
1860 $RT::Logger->error( "Can't record send email failure as ticket is missing" );
1865 RT::Base->_ImportOverlays();