X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FInterface%2FEmail.pm;h=04539a3a6532060bc7f89db0a0344c1a97a9c0eb;hb=d39d52aac8f38ea9115628039f0df5aa3ac826de;hp=241f5f35c5bfd359c0253cab0de16d2af8de43eb;hpb=289340780927b5bac2c7604d7317c3063c6dd8cc;p=freeside.git diff --git a/rt/lib/RT/Interface/Email.pm b/rt/lib/RT/Interface/Email.pm index 241f5f35c..04539a3a6 100755 --- a/rt/lib/RT/Interface/Email.pm +++ b/rt/lib/RT/Interface/Email.pm @@ -1,8 +1,14 @@ -# BEGIN LICENSE BLOCK +# {{{ BEGIN BPS TAGGED BLOCK # -# Copyright (c) 1996-2003 Jesse Vincent +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC +# # -# (Except where explictly superceded by other copyright notices) +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: # # This work is made available to you under the terms of Version 2 of # the GNU General Public License. A copy of that license should have @@ -14,13 +20,29 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # -# Unless otherwise specified, all modifications, corrections or -# extensions to this work which alter its source code become the -# property of Best Practical Solutions, LLC when submitted for -# inclusion in the work. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) # +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. # -# END LICENSE BLOCK +# }}} END BPS TAGGED BLOCK package RT::Interface::Email; use strict; @@ -34,7 +56,7 @@ BEGIN { use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); # set the version for version checking - $VERSION = do { my @r = (q$Revision: 1.1.1.2 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker + $VERSION = do { my @r = (q$Revision: 1.1.1.4 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; # must be all one line, for MakeMaker @ISA = qw(Exporter); @@ -57,7 +79,7 @@ BEGIN { =head1 NAME - RT::Interface::CLI - helper functions for creating a commandline RT interface + RT::Interface::Email - helper functions for parsing email sent to RT =head1 SYNOPSIS @@ -166,6 +188,7 @@ sub MailError { Bcc => $args{'Bcc'}, To => $args{'To'}, Subject => $args{'Subject'}, + Precedence => 'bulk', 'X-RT-Loop-Prevention' => $RT::rtname, ); @@ -182,14 +205,13 @@ sub MailError { } - if ($RT::MailCommand eq 'sendmailpipe') { open (MAIL, "|$RT::SendmailPath $RT::SendmailArguments") || return(0); print MAIL $entity->as_string; close(MAIL); } else { - $entity->send($RT::MailCommand, $RT::MailParams); + $entity->send($RT::MailCommand, $RT::MailParams); } } @@ -376,6 +398,9 @@ This performs all the "guts" of the mail rt-mailgate program, and is designed to be called from the web interface with a message, user object, and so on. +Can also take an optional 'ticket' parameter; this ticket id overrides +any ticket id found in the subject. + Returns: An array of: @@ -413,37 +438,8 @@ sub Gateway { } my $parser = RT::EmailParser->new(); - my ( $fh, $temp_file ); - for ( 1 .. 10 ) { - - # on NFS and NTFS, it is possible that tempfile() conflicts - # with other processes, causing a race condition. we try to - # accommodate this by pausing and retrying. - last if ( $fh, $temp_file ) = eval { File::Temp::tempfile(undef, UNLINK => 0) }; - sleep 1; - } - if ($fh) { - binmode $fh; #thank you, windows - $fh->autoflush(1); - print $fh $args{'message'}; - close($fh); - - if ( -f $temp_file ) { - $parser->ParseMIMEEntityFromFile($temp_file); - File::Temp::unlink0( $fh, $temp_file ); - if ($parser->Entity) { - delete $args{'message'}; - } - } - - } - - #If for some reason we weren't able to parse the message using a temp file - # try it with a scalar - if ($args{'message'}) { - $parser->ParseMIMEEntityFromScalar($args{'message'}); - } + $parser->SmartParseMIMEEntityFromScalar( Message => $args{'message'}); if (!$parser->Entity()) { MailError( @@ -476,9 +472,12 @@ sub Gateway { $args{'ticket'} ||= $parser->ParseTicketId($Subject); my $SystemTicket; + my $Right = 'CreateTicket'; if ( $args{'ticket'} ) { $SystemTicket = RT::Ticket->new($RT::SystemUser); $SystemTicket->Load( $args{'ticket'} ); + # if there's an existing ticket, this must be a reply + $Right = 'ReplyToTicket'; } #Set up a queue object @@ -500,28 +499,29 @@ sub Gateway { # Since this needs loading, no matter what - for (@RT::MailPlugins) { + foreach (@RT::MailPlugins) { my $Code; my $NewAuthStat; if ( ref($_) eq "CODE" ) { $Code = $_; } else { - $_ = "RT::Interface::Email::$_" unless /^RT::Interface::Email::/; + $_ = "RT::Interface::Email::".$_ unless $_ =~ /^RT::Interface::Email::/; eval "require $_;"; if ($@) { - die ("Couldn't load module $_: $@"); + $RT::Logger->crit("Couldn't load module '$_': $@"); next; } no strict 'refs'; if ( !defined( $Code = *{ $_ . "::GetCurrentUser" }{CODE} ) ) { - die ("No GetCurrentUser code found in $_ module"); + $RT::Logger->crit("No GetCurrentUser code found in $_ module"); next; } } ( $CurrentUser, $NewAuthStat ) = $Code->( Message => $Message, + RawMessageRef => \$args{'message'}, CurrentUser => $CurrentUser, AuthLevel => $AuthStat, Action => $args{'action'}, @@ -529,6 +529,7 @@ sub Gateway { Queue => $SystemQueueObj ); + # If a module returns a "-1" then we discard the ticket, so. $AuthStat = -1 if $NewAuthStat == -1; @@ -552,7 +553,7 @@ sub Gateway { RT could not load a valid user, and RT's configuration does not allow for the creation of a new user for this email ($ErrorsTo). -You might need to grant 'Everyone' the right 'CreateTicket' for the +You might need to grant 'Everyone' the right '$Right' for the queue @{[$args{'queue'}]}. EOT @@ -621,10 +622,10 @@ EOT Explanation => "RT thinks this message may be a bounce", MIMEObj => $Message ); - - #Do we actually want to store it? - return ( 0, "Message Bounced", undef ) unless ($RT::StoreLoops); } + + #Do we actually want to store it? + return ( 0, "Message Bounced", undef ) unless ($RT::StoreLoops); } # }}} @@ -752,6 +753,7 @@ EOT return ( 1, "Success", $Ticket ); } + eval "require RT::Interface::Email_Vendor"; die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/Email_Vendor.pm}); eval "require RT::Interface::Email_Local";