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 );
751 unless (defined $mail->head->get('Subject')) {
753 $subject = $txn->Subject if $txn;
754 $subject ||= $ticket->Subject if $ticket;
756 unless ( RT->Config->Get('ForwardFromUser') ) {
757 # XXX: what if want to forward txn of other object than ticket?
758 $subject = AddSubjectTag( $subject, $ticket );
761 $mail->head->set( Subject => EncodeToMIME( String => "Fwd: $subject" ) );
765 From => EncodeToMIME(
766 String => GetForwardFrom( Transaction => $txn, Ticket => $ticket )
770 my $status = RT->Config->Get('ForwardFromUser')
771 # never sign if we forward from User
772 ? SendEmail( %args, Entity => $mail, Sign => 0 )
773 : SendEmail( %args, Entity => $mail );
774 return (0, $ticket->loc("Couldn't send email")) unless $status;
775 return (1, $ticket->loc("Sent email successfully"));
778 =head2 GetForwardFrom Ticket => undef, Transaction => undef
780 Resolve the From field to use in forward mail
785 my %args = ( Ticket => undef, Transaction => undef, @_ );
786 my $txn = $args{Transaction};
787 my $ticket = $args{Ticket} || $txn->Object;
789 if ( RT->Config->Get('ForwardFromUser') ) {
790 return ( $txn || $ticket )->CurrentUser->UserObj->EmailAddress;
793 return $ticket->QueueObj->CorrespondAddress
794 || RT->Config->Get('CorrespondAddress');
798 =head2 SignEncrypt Entity => undef, Sign => 0, Encrypt => 0
800 Signs and encrypts message using L<RT::Crypt::GnuPG>, but as well
801 handle errors with users' keys.
803 If a recipient has no key or has other problems with it, then the
804 unction sends a error to him using 'Error: public key' template.
805 Also, notifies RT's owner using template 'Error to RT owner: public key'
806 to inform that there are problems with users' keys. Then we filter
807 all bad recipients and retry.
809 Returns 1 on success, 0 on error and -1 if all recipients are bad and
810 had been filtered out.
821 return 1 unless $args{'Sign'} || $args{'Encrypt'};
823 my $msgid = $args{'Entity'}->head->get('Message-ID') || '';
826 $RT::Logger->debug("$msgid Signing message") if $args{'Sign'};
827 $RT::Logger->debug("$msgid Encrypting message") if $args{'Encrypt'};
829 require RT::Crypt::GnuPG;
830 my %res = RT::Crypt::GnuPG::SignEncrypt( %args );
831 return 1 unless $res{'exit_code'};
833 my @status = RT::Crypt::GnuPG::ParseStatus( $res{'status'} );
836 foreach my $line ( @status ) {
837 # if the passphrase fails, either you have a bad passphrase
838 # or gpg-agent has died. That should get caught in Create and
839 # Update, but at least throw an error here
840 if (($line->{'Operation'}||'') eq 'PassphraseCheck'
841 && $line->{'Status'} =~ /^(?:BAD|MISSING)$/ ) {
842 $RT::Logger->error( "$line->{'Status'} PASSPHRASE: $line->{'Message'}" );
845 next unless ($line->{'Operation'}||'') eq 'RecipientsCheck';
846 next if $line->{'Status'} eq 'DONE';
847 $RT::Logger->error( $line->{'Message'} );
848 push @bad_recipients, $line;
850 return 0 unless @bad_recipients;
852 $_->{'AddressObj'} = (Email::Address->parse( $_->{'Recipient'} ))[0]
853 foreach @bad_recipients;
855 foreach my $recipient ( @bad_recipients ) {
856 my $status = SendEmailUsingTemplate(
857 To => $recipient->{'AddressObj'}->address,
858 Template => 'Error: public key',
861 TicketObj => $args{'Ticket'},
862 TransactionObj => $args{'Transaction'},
866 $RT::Logger->error("Couldn't send 'Error: public key'");
870 my $status = SendEmailUsingTemplate(
871 To => RT->Config->Get('OwnerEmail'),
872 Template => 'Error to RT owner: public key',
874 BadRecipients => \@bad_recipients,
875 TicketObj => $args{'Ticket'},
876 TransactionObj => $args{'Transaction'},
880 $RT::Logger->error("Couldn't send 'Error to RT owner: public key'");
883 DeleteRecipientsFromHead(
884 $args{'Entity'}->head,
885 map $_->{'AddressObj'}->address, @bad_recipients
888 unless ( $args{'Entity'}->head->get('To')
889 || $args{'Entity'}->head->get('Cc')
890 || $args{'Entity'}->head->get('Bcc') )
892 $RT::Logger->debug("$msgid No recipients that have public key, not sending");
896 # redo without broken recipients
897 %res = RT::Crypt::GnuPG::SignEncrypt( %args );
898 return 0 if $res{'exit_code'};
907 Takes a hash with a String and a Charset. Returns the string encoded
908 according to RFC2047, using B (base64 based) encoding.
910 String must be a perl string, octets are returned.
912 If Charset is not provided then $EmailOutputEncoding config option
913 is used, or "latin-1" if that is not set.
923 my $value = $args{'String'};
924 return $value unless $value; # 0 is perfect ascii
925 my $charset = $args{'Charset'} || RT->Config->Get('EmailOutputEncoding');
928 # using RFC2047 notation, sec 2.
929 # encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
931 # An 'encoded-word' may not be more than 75 characters long
933 # MIME encoding increases 4/3*(number of bytes), and always in multiples
934 # of 4. Thus we have to find the best available value of bytes available
937 # First we get the integer max which max*4/3 would fit on space.
938 # Then we find the greater multiple of 3 lower or equal than $max.
940 ( ( 75 - length( '=?' . $charset . '?' . $encoding . '?' . '?=' ) )
944 $max = int( $max / 3 ) * 3;
951 $RT::Logger->crit("Can't encode! Charset or encoding too big.");
955 return ($value) if $value =~ /^(?:[\t\x20-\x7e]|\x0D*\x0A[ \t])+$/s;
959 # we need perl string to split thing char by char
960 Encode::_utf8_on($value) unless Encode::is_utf8($value);
962 my ( $tmp, @chunks ) = ( '', () );
963 while ( length $value ) {
964 my $char = substr( $value, 0, 1, '' );
965 my $octets = Encode::encode( $charset, $char );
966 if ( length($tmp) + length($octets) > $max ) {
972 push @chunks, $tmp if length $tmp;
974 # encode an join chuncks
976 map MIME::Words::encode_mimeword( $_, $encoding, $charset ),
982 my ( $Username, $Address, $Name, $ErrorsTo, $entity ) = @_;
984 my $NewUser = RT::User->new( RT->SystemUser );
986 my ( $Val, $Message ) = $NewUser->Create(
987 Name => ( $Username || $Address ),
988 EmailAddress => $Address,
992 Comments => 'Autocreated on ticket submission',
997 # Deal with the race condition of two account creations at once
999 $NewUser->LoadByName($Username);
1002 unless ( $NewUser->Id ) {
1003 $NewUser->LoadByEmail($Address);
1006 unless ( $NewUser->Id ) {
1009 Subject => "User could not be created",
1011 "User creation failed in mailgateway: $Message",
1018 #Load the new user object
1019 my $CurrentUser = RT::CurrentUser->new;
1020 $CurrentUser->LoadByEmail( $Address );
1022 unless ( $CurrentUser->id ) {
1023 $RT::Logger->warning(
1024 "Couldn't load user '$Address'." . "giving up" );
1027 Subject => "User could not be loaded",
1029 "User '$Address' could not be loaded in the mail gateway",
1035 return $CurrentUser;
1040 =head2 ParseCcAddressesFromHead HASH
1042 Takes a hash containing QueueObj, Head and CurrentUser objects.
1043 Returns a list of all email addresses in the To and Cc
1044 headers b<except> the current Queue\'s email addresses, the CurrentUser\'s
1045 email address and anything that the configuration sub RT::IsRTAddress matches.
1049 sub ParseCcAddressesFromHead {
1053 CurrentUser => undef,
1057 my $current_address = lc $args{'CurrentUser'}->EmailAddress;
1058 my $user = $args{'CurrentUser'}->UserObj;
1061 grep { $_ ne $current_address
1062 && !RT::EmailParser->IsRTAddress( $_ )
1063 && !IgnoreCcAddress( $_ )
1065 map lc $user->CanonicalizeEmailAddress( $_->address ),
1066 map Email::Address->parse( $args{'Head'}->get( $_ ) ),
1070 =head2 IgnoreCcAddress ADDRESS
1072 Returns true if ADDRESS matches the $IgnoreCcRegexp config variable.
1076 sub IgnoreCcAddress {
1077 my $address = shift;
1078 if ( my $address_re = RT->Config->Get('IgnoreCcRegexp') ) {
1079 return 1 if $address =~ /$address_re/i;
1084 =head2 ParseSenderAddressFromHead HEAD
1086 Takes a MIME::Header object. Returns a tuple: (user@host, friendly name)
1087 of the From (evaluated in order of Reply-To:, From:, Sender)
1091 sub ParseSenderAddressFromHead {
1094 #Figure out who's sending this message.
1095 foreach my $header ('Reply-To', 'From', 'Sender') {
1096 my $addr_line = $head->get($header) || next;
1097 my ($addr, $name) = ParseAddressFromHeader( $addr_line );
1098 # only return if the address is not empty
1099 return ($addr, $name) if $addr;
1102 return (undef, undef);
1105 =head2 ParseErrorsToAddressFromHead HEAD
1107 Takes a MIME::Header object. Return a single value : user@host
1108 of the From (evaluated in order of Return-path:,Errors-To:,Reply-To:,
1113 sub ParseErrorsToAddressFromHead {
1116 #Figure out who's sending this message.
1118 foreach my $header ( 'Errors-To', 'Reply-To', 'From', 'Sender' ) {
1120 # If there's a header of that name
1121 my $headerobj = $head->get($header);
1123 my ( $addr, $name ) = ParseAddressFromHeader($headerobj);
1125 # If it's got actual useful content...
1126 return ($addr) if ($addr);
1133 =head2 ParseAddressFromHeader ADDRESS
1135 Takes an address from C<$head->get('Line')> and returns a tuple: user@host, friendly name
1139 sub ParseAddressFromHeader {
1142 # Some broken mailers send: ""Vincent, Jesse"" <jesse@fsck.com>. Hate
1143 $Addr =~ s/\"\"(.*?)\"\"/\"$1\"/g;
1144 my @Addresses = RT::EmailParser->ParseEmailAddress($Addr);
1146 my ($AddrObj) = grep ref $_, @Addresses;
1147 unless ( $AddrObj ) {
1148 return ( undef, undef );
1151 return ( $AddrObj->address, $AddrObj->phrase );
1154 =head2 DeleteRecipientsFromHead HEAD RECIPIENTS
1156 Gets a head object and list of addresses.
1157 Deletes addresses from To, Cc or Bcc fields.
1161 sub DeleteRecipientsFromHead {
1163 my %skip = map { lc $_ => 1 } @_;
1165 foreach my $field ( qw(To Cc Bcc) ) {
1166 $head->set( $field =>
1167 join ', ', map $_->format, grep !$skip{ lc $_->address },
1168 Email::Address->parse( $head->get( $field ) )
1177 ScripAction => undef,
1180 my $org = RT->Config->Get('Organization');
1181 my $ticket_id = ( ref $args{'Ticket'}? $args{'Ticket'}->id : $args{'Ticket'} ) || 0;
1182 my $scrip_id = ( ref $args{'Scrip'}? $args{'Scrip'}->id : $args{'Scrip'} ) || 0;
1183 my $sent = ( ref $args{'ScripAction'}? $args{'ScripAction'}->{'_Message_ID'} : 0 ) || 0;
1185 return "<rt-". $RT::VERSION ."-". $$ ."-". CORE::time() ."-". int(rand(2000)) .'.'
1186 . $ticket_id ."-". $scrip_id ."-". $sent ."@". $org .">" ;
1196 return unless $args{'Message'} && $args{'InReplyTo'};
1198 my $get_header = sub {
1200 if ( $args{'InReplyTo'}->isa('MIME::Entity') ) {
1201 @res = $args{'InReplyTo'}->head->get( shift );
1203 @res = $args{'InReplyTo'}->GetHeader( shift ) || '';
1205 return grep length, map { split /\s+/m, $_ } grep defined, @res;
1208 my @id = $get_header->('Message-ID');
1209 #XXX: custom header should begin with X- otherwise is violation of the standard
1210 my @rtid = $get_header->('RT-Message-ID');
1211 my @references = $get_header->('References');
1212 unless ( @references ) {
1213 @references = $get_header->('In-Reply-To');
1215 push @references, @id, @rtid;
1216 if ( $args{'Ticket'} ) {
1217 my $pseudo_ref = '<RT-Ticket-'. $args{'Ticket'}->id .'@'. RT->Config->Get('Organization') .'>';
1218 push @references, $pseudo_ref unless grep $_ eq $pseudo_ref, @references;
1220 @references = splice @references, 4, -6
1221 if @references > 10;
1223 my $mail = $args{'Message'};
1224 $mail->head->set( 'In-Reply-To' => join ' ', @rtid? (@rtid) : (@id) ) if @id || @rtid;
1225 $mail->head->set( 'References' => join ' ', @references );
1229 my $Subject = shift;
1231 my $rtname = RT->Config->Get('rtname');
1232 my $test_name = RT->Config->Get('EmailSubjectTagRegex') || qr/\Q$rtname\E/i;
1235 if ( $Subject =~ s/\[$test_name\s+\#(\d+)\s*\]//i ) {
1238 foreach my $tag ( RT->System->SubjectTag ) {
1239 next unless $Subject =~ s/\[\Q$tag\E\s+\#(\d+)\s*\]//i;
1244 return undef unless $id;
1246 $RT::Logger->debug("Found a ticket ID. It's $id");
1251 my $subject = shift;
1253 unless ( ref $ticket ) {
1254 my $tmp = RT::Ticket->new( RT->SystemUser );
1255 $tmp->Load( $ticket );
1258 my $id = $ticket->id;
1259 my $queue_tag = $ticket->QueueObj->SubjectTag;
1261 my $tag_re = RT->Config->Get('EmailSubjectTagRegex');
1262 unless ( $tag_re ) {
1263 my $tag = $queue_tag || RT->Config->Get('rtname');
1264 $tag_re = qr/\Q$tag\E/;
1265 } elsif ( $queue_tag ) {
1266 $tag_re = qr/$tag_re|\Q$queue_tag\E/;
1268 return $subject if $subject =~ /\[$tag_re\s+#$id\]/;
1270 $subject =~ s/(\r\n|\n|\s)/ /g;
1272 return "[". ($queue_tag || RT->Config->Get('rtname')) ." #$id] $subject";
1276 =head2 Gateway ARGSREF
1286 This performs all the "guts" of the mail rt-mailgate program, and is
1287 designed to be called from the web interface with a message, user
1290 Can also take an optional 'ticket' parameter; this ticket id overrides
1291 any ticket id found in the subject.
1297 (status code, message, optional ticket object)
1299 status code is a numeric value.
1301 for temporary failures, the status code should be -75
1303 for permanent failures which are handled by RT, the status code
1306 for succces, the status code should be 1
1313 my @mail_plugins = @_;
1316 foreach my $plugin (@mail_plugins) {
1317 if ( ref($plugin) eq "CODE" ) {
1319 } elsif ( !ref $plugin ) {
1320 my $Class = $plugin;
1321 $Class = "RT::Interface::Email::" . $Class
1322 unless $Class =~ /^RT::/;
1324 do { $RT::Logger->error("Couldn't load $Class: $@"); next };
1327 unless ( defined *{ $Class . "::GetCurrentUser" }{CODE} ) {
1328 $RT::Logger->crit( "No GetCurrentUser code found in $Class module");
1333 $RT::Logger->crit( "$plugin - is not class name or code reference");
1340 my $argsref = shift;
1342 action => 'correspond',
1352 # Validate the action
1353 my ( $status, @actions ) = IsCorrectAction( $args{'action'} );
1357 "Invalid 'action' parameter "
1365 my $parser = RT::EmailParser->new();
1366 $parser->SmartParseMIMEEntityFromScalar(
1367 Message => $args{'message'},
1372 my $Message = $parser->Entity();
1375 Subject => "RT Bounce: Unparseable message",
1376 Explanation => "RT couldn't process the message below",
1377 Attach => $args{'message'}
1381 "Failed to parse this message. Something is likely badly wrong with the message"
1385 my @mail_plugins = grep $_, RT->Config->Get('MailPlugins');
1386 push @mail_plugins, "Auth::MailFrom" unless @mail_plugins;
1387 @mail_plugins = _LoadPlugins( @mail_plugins );
1390 foreach my $class( grep !ref, @mail_plugins ) {
1391 # check if we should apply filter before decoding
1394 *{ $class . "::ApplyBeforeDecode" }{CODE};
1396 next unless defined $check_cb;
1397 next unless $check_cb->(
1398 Message => $Message,
1399 RawMessageRef => \$args{'message'},
1402 $skip_plugin{ $class }++;
1406 *{ $class . "::GetCurrentUser" }{CODE};
1408 my ($status, $msg) = $Code->(
1409 Message => $Message,
1410 RawMessageRef => \$args{'message'},
1412 next if $status > 0;
1414 if ( $status == -2 ) {
1415 return (1, $msg, undef);
1416 } elsif ( $status == -1 ) {
1417 return (0, $msg, undef);
1420 @mail_plugins = grep !$skip_plugin{"$_"}, @mail_plugins;
1421 $parser->_DecodeBodies;
1422 $parser->_PostProcessNewEntity;
1424 my $head = $Message->head;
1425 my $ErrorsTo = ParseErrorsToAddressFromHead( $head );
1427 my $MessageId = $head->get('Message-ID')
1428 || "<no-message-id-". time . rand(2000) .'@'. RT->Config->Get('Organization') .'>';
1430 #Pull apart the subject line
1431 my $Subject = $head->get('Subject') || '';
1434 # Lets check for mail loops of various sorts.
1435 my ($should_store_machine_generated_message, $IsALoop, $result);
1436 ( $should_store_machine_generated_message, $ErrorsTo, $result, $IsALoop ) =
1437 _HandleMachineGeneratedMail(
1438 Message => $Message,
1439 ErrorsTo => $ErrorsTo,
1440 Subject => $Subject,
1441 MessageId => $MessageId
1444 # Do not pass loop messages to MailPlugins, to make sure the loop
1445 # is broken, unless $RT::StoreLoops is set.
1446 if ($IsALoop && !$should_store_machine_generated_message) {
1447 return ( 0, $result, undef );
1451 $args{'ticket'} ||= ParseTicketId( $Subject );
1453 $SystemTicket = RT::Ticket->new( RT->SystemUser );
1454 $SystemTicket->Load( $args{'ticket'} ) if ( $args{'ticket'} ) ;
1455 if ( $SystemTicket->id ) {
1456 $Right = 'ReplyToTicket';
1458 $Right = 'CreateTicket';
1461 #Set up a queue object
1462 my $SystemQueueObj = RT::Queue->new( RT->SystemUser );
1463 $SystemQueueObj->Load( $args{'queue'} );
1465 # We can safely have no queue of we have a known-good ticket
1466 unless ( $SystemTicket->id || $SystemQueueObj->id ) {
1467 return ( -75, "RT couldn't find the queue: " . $args{'queue'}, undef );
1470 my ($AuthStat, $CurrentUser, $error) = GetAuthenticationLevel(
1471 MailPlugins => \@mail_plugins,
1472 Actions => \@actions,
1473 Message => $Message,
1474 RawMessageRef => \$args{message},
1475 SystemTicket => $SystemTicket,
1476 SystemQueue => $SystemQueueObj,
1479 # If authentication fails and no new user was created, get out.
1480 if ( !$CurrentUser || !$CurrentUser->id || $AuthStat == -1 ) {
1482 # If the plugins refused to create one, they lose.
1483 unless ( $AuthStat == -1 ) {
1484 _NoAuthorizedUserFound(
1486 Message => $Message,
1487 Requestor => $ErrorsTo,
1488 Queue => $args{'queue'}
1492 return ( 0, "Could not load a valid user", undef );
1495 # If we got a user, but they don't have the right to say things
1496 if ( $AuthStat == 0 ) {
1499 Subject => "Permission Denied",
1501 "You do not have permission to communicate with RT",
1506 "$ErrorsTo tried to submit a message to "
1508 . " without permission.",
1514 unless ($should_store_machine_generated_message) {
1515 return ( 0, $result, undef );
1518 # if plugin's updated SystemTicket then update arguments
1519 $args{'ticket'} = $SystemTicket->Id if $SystemTicket && $SystemTicket->Id;
1521 my $Ticket = RT::Ticket->new($CurrentUser);
1523 if ( !$args{'ticket'} && grep /^(comment|correspond)$/, @actions )
1527 my @Requestors = ( $CurrentUser->id );
1529 if (RT->Config->Get('ParseNewMessageForTicketCcs')) {
1530 @Cc = ParseCcAddressesFromHead(
1532 CurrentUser => $CurrentUser,
1533 QueueObj => $SystemQueueObj
1537 my ( $id, $Transaction, $ErrStr ) = $Ticket->Create(
1538 Queue => $SystemQueueObj->Id,
1539 Subject => $Subject,
1540 Requestor => \@Requestors,
1547 Subject => "Ticket creation failed: $Subject",
1548 Explanation => $ErrStr,
1551 return ( 0, "Ticket creation failed: $ErrStr", $Ticket );
1554 # strip comments&corresponds from the actions we don't need
1555 # to record them if we've created the ticket just now
1556 @actions = grep !/^(comment|correspond)$/, @actions;
1557 $args{'ticket'} = $id;
1559 } elsif ( $args{'ticket'} ) {
1561 $Ticket->Load( $args{'ticket'} );
1562 unless ( $Ticket->Id ) {
1563 my $error = "Could not find a ticket with id " . $args{'ticket'};
1566 Subject => "Message not recorded: $Subject",
1567 Explanation => $error,
1571 return ( 0, $error );
1573 $args{'ticket'} = $Ticket->id;
1575 return ( 1, "Success", $Ticket );
1580 my $unsafe_actions = RT->Config->Get('UnsafeEmailCommands');
1581 foreach my $action (@actions) {
1583 # If the action is comment, add a comment.
1584 if ( $action =~ /^(?:comment|correspond)$/i ) {
1585 my $method = ucfirst lc $action;
1586 my ( $status, $msg ) = $Ticket->$method( MIMEObj => $Message );
1589 #Warn the sender that we couldn't actually submit the comment.
1592 Subject => "Message not recorded: $Subject",
1593 Explanation => $msg,
1596 return ( 0, "Message not recorded: $msg", $Ticket );
1598 } elsif ($unsafe_actions) {
1599 my ( $status, $msg ) = _RunUnsafeAction(
1601 ErrorsTo => $ErrorsTo,
1602 Message => $Message,
1604 CurrentUser => $CurrentUser,
1606 return ($status, $msg, $Ticket) unless $status == 1;
1609 return ( 1, "Success", $Ticket );
1612 =head2 GetAuthenticationLevel
1614 # Authentication Level
1615 # -1 - Get out. this user has been explicitly declined
1616 # 0 - User may not do anything (Not used at the moment)
1618 # 2 - User is allowed to specify status updates etc. a la enhanced-mailgate
1622 sub GetAuthenticationLevel {
1627 RawMessageRef => undef,
1628 SystemTicket => undef,
1629 SystemQueue => undef,
1633 my ( $CurrentUser, $AuthStat, $error );
1635 # Initalize AuthStat so comparisons work correctly
1636 $AuthStat = -9999999;
1638 # if plugin returns AuthStat -2 we skip action
1639 # NOTE: this is experimental API and it would be changed
1640 my %skip_action = ();
1642 # Since this needs loading, no matter what
1643 foreach (@{ $args{MailPlugins} }) {
1644 my ($Code, $NewAuthStat);
1645 if ( ref($_) eq "CODE" ) {
1649 $Code = *{ $_ . "::GetCurrentUser" }{CODE};
1652 foreach my $action (@{ $args{Actions} }) {
1653 ( $CurrentUser, $NewAuthStat ) = $Code->(
1654 Message => $args{Message},
1655 RawMessageRef => $args{RawMessageRef},
1656 CurrentUser => $CurrentUser,
1657 AuthLevel => $AuthStat,
1659 Ticket => $args{SystemTicket},
1660 Queue => $args{SystemQueue},
1663 # You get the highest level of authentication you were assigned, unless you get the magic -1
1664 # If a module returns a "-1" then we discard the ticket, so.
1665 $AuthStat = $NewAuthStat
1666 if ( $NewAuthStat > $AuthStat or $NewAuthStat == -1 or $NewAuthStat == -2 );
1668 last if $AuthStat == -1;
1669 $skip_action{$action}++ if $AuthStat == -2;
1672 # strip actions we should skip
1673 @{$args{Actions}} = grep !$skip_action{$_}, @{$args{Actions}}
1675 last unless @{$args{Actions}};
1677 last if $AuthStat == -1;
1680 return $AuthStat if !wantarray;
1682 return ($AuthStat, $CurrentUser, $error);
1685 sub _RunUnsafeAction {
1691 CurrentUser => undef,
1695 if ( $args{'Action'} =~ /^take$/i ) {
1696 my ( $status, $msg ) = $args{'Ticket'}->SetOwner( $args{'CurrentUser'}->id );
1699 To => $args{'ErrorsTo'},
1700 Subject => "Ticket not taken",
1701 Explanation => $msg,
1702 MIMEObj => $args{'Message'}
1704 return ( 0, "Ticket not taken" );
1706 } elsif ( $args{'Action'} =~ /^resolve$/i ) {
1707 my ( $status, $msg ) = $args{'Ticket'}->SetStatus('resolved');
1710 #Warn the sender that we couldn't actually submit the comment.
1712 To => $args{'ErrorsTo'},
1713 Subject => "Ticket not resolved",
1714 Explanation => $msg,
1715 MIMEObj => $args{'Message'}
1717 return ( 0, "Ticket not resolved" );
1720 return ( 0, "Not supported unsafe action $args{'Action'}", $args{'Ticket'} );
1722 return ( 1, "Success" );
1725 =head2 _NoAuthorizedUserFound
1727 Emails the RT Owner and the requestor when the auth plugins return "No auth user found"
1731 sub _NoAuthorizedUserFound {
1740 # Notify the RT Admin of the failure.
1742 To => RT->Config->Get('OwnerEmail'),
1743 Subject => "Could not load a valid user",
1744 Explanation => <<EOT,
1745 RT could not load a valid user, and RT's configuration does not allow
1746 for the creation of a new user for this email (@{[$args{Requestor}]}).
1748 You might need to grant 'Everyone' the right '@{[$args{Right}]}' for the
1749 queue @{[$args{'Queue'}]}.
1752 MIMEObj => $args{'Message'},
1756 # Also notify the requestor that his request has been dropped.
1757 if ($args{'Requestor'} ne RT->Config->Get('OwnerEmail')) {
1759 To => $args{'Requestor'},
1760 Subject => "Could not load a valid user",
1761 Explanation => <<EOT,
1762 RT could not load a valid user, and RT's configuration does not allow
1763 for the creation of a new user for your email.
1766 MIMEObj => $args{'Message'},
1772 =head2 _HandleMachineGeneratedMail
1779 Checks the message to see if it's a bounce, if it looks like a loop, if it's autogenerated, etc.
1780 Returns a triple of ("Should we continue (boolean)", "New value for $ErrorsTo", "Status message",
1781 "This message appears to be a loop (boolean)" );
1785 sub _HandleMachineGeneratedMail {
1786 my %args = ( Message => undef, ErrorsTo => undef, Subject => undef, MessageId => undef, @_ );
1787 my $head = $args{'Message'}->head;
1788 my $ErrorsTo = $args{'ErrorsTo'};
1790 my $IsBounce = CheckForBounce($head);
1792 my $IsAutoGenerated = CheckForAutoGenerated($head);
1794 my $IsSuspiciousSender = CheckForSuspiciousSender($head);
1796 my $IsALoop = CheckForLoops($head);
1798 my $SquelchReplies = 0;
1800 my $owner_mail = RT->Config->Get('OwnerEmail');
1802 #If the message is autogenerated, we need to know, so we can not
1803 # send mail to the sender
1804 if ( $IsBounce || $IsSuspiciousSender || $IsAutoGenerated || $IsALoop ) {
1805 $SquelchReplies = 1;
1806 $ErrorsTo = $owner_mail;
1809 # Warn someone if it's a loop, before we drop it on the ground
1811 $RT::Logger->crit("RT Received mail (".$args{MessageId}.") from itself.");
1813 #Should we mail it to RTOwner?
1814 if ( RT->Config->Get('LoopsToRTOwner') ) {
1817 Subject => "RT Bounce: ".$args{'Subject'},
1818 Explanation => "RT thinks this message may be a bounce",
1819 MIMEObj => $args{Message}
1823 #Do we actually want to store it?
1824 return ( 0, $ErrorsTo, "Message Bounced", $IsALoop )
1825 unless RT->Config->Get('StoreLoops');
1828 # Squelch replies if necessary
1829 # Don't let the user stuff the RT-Squelch-Replies-To header.
1830 if ( $head->get('RT-Squelch-Replies-To') ) {
1832 'RT-Relocated-Squelch-Replies-To',
1833 $head->get('RT-Squelch-Replies-To')
1835 $head->delete('RT-Squelch-Replies-To');
1838 if ($SquelchReplies) {
1840 # Squelch replies to the sender, and also leave a clue to
1841 # allow us to squelch ALL outbound messages. This way we
1842 # can punt the logic of "what to do when we get a bounce"
1843 # to the scrip. We might want to notify nobody. Or just
1844 # the RT Owner. Or maybe all Privileged watchers.
1845 my ( $Sender, $junk ) = ParseSenderAddressFromHead($head);
1846 $head->replace( 'RT-Squelch-Replies-To', $Sender );
1847 $head->replace( 'RT-DetectedAutoGenerated', 'true' );
1849 return ( 1, $ErrorsTo, "Handled machine detection", $IsALoop );
1852 =head2 IsCorrectAction
1854 Returns a list of valid actions we've found for this message
1858 sub IsCorrectAction {
1860 my @actions = grep $_, split /-/, $action;
1861 return ( 0, '(no value)' ) unless @actions;
1862 foreach ( @actions ) {
1863 return ( 0, $_ ) unless /^(?:comment|correspond|take|resolve)$/;
1865 return ( 1, @actions );
1868 sub _RecordSendEmailFailure {
1871 $ticket->_RecordNote(
1872 NoteType => 'SystemError',
1873 Content => "Sending the previous mail has failed. Please contact your admin, they can find more details in the logs.",
1878 $RT::Logger->error( "Can't record send email failure as ticket is missing" );
1883 RT::Base->_ImportOverlays();