[Rt-commit] [svn] r1345 - in rt/branches/3.3-TESTING/lib/RT: .
Action Interface
alexmv at pallas.eruditorum.org
alexmv at pallas.eruditorum.org
Tue Aug 17 22:42:50 EDT 2004
Author: alexmv
Date: Tue Aug 17 22:42:49 2004
New Revision: 1345
Modified:
rt/branches/3.3-TESTING/lib/RT/Action/SendEmail.pm
rt/branches/3.3-TESTING/lib/RT/EmailParser.pm
rt/branches/3.3-TESTING/lib/RT/I18N.pm
rt/branches/3.3-TESTING/lib/RT/Interface/Email.pm
rt/branches/3.3-TESTING/lib/RT/Queue_Overlay.pm
rt/branches/3.3-TESTING/lib/RT/User_Overlay.pm
Log:
RT-Ticket: 5716
RT-Status: resolved
RT-Update: correspond
* Duplicate code change backed out of 3.2 and checked into 3.3
Modified: rt/branches/3.3-TESTING/lib/RT/Action/SendEmail.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/Action/SendEmail.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/Action/SendEmail.pm Tue Aug 17 22:42:49 2004
@@ -54,7 +54,7 @@
use MIME::Words qw(encode_mimeword);
-use RT::EmailParser;
+use RT::Interface::Email;
use Mail::Address;
=head1 NAME
@@ -484,11 +484,11 @@
# Weed out any RT addresses. We really don't want to talk to ourselves!
@{ $self->{'To'} } =
- RT::EmailParser::CullRTAddresses( "", @{ $self->{'To'} } );
+ RT::Interface::Email::CullRTAddresses( @{ $self->{'To'} } );
@{ $self->{'Cc'} } =
- RT::EmailParser::CullRTAddresses( "", @{ $self->{'Cc'} } );
+ RT::Interface::Email::CullRTAddresses( @{ $self->{'Cc'} } );
@{ $self->{'Bcc'} } =
- RT::EmailParser::CullRTAddresses( "", @{ $self->{'Bcc'} } );
+ RT::Interface::Email::CullRTAddresses( @{ $self->{'Bcc'} } );
# If there are no recipients, don't try to send the message.
# If the transaction has content and has the header RT-Squelch-Replies-To
Modified: rt/branches/3.3-TESTING/lib/RT/EmailParser.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/EmailParser.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/EmailParser.pm Tue Aug 17 22:42:49 2004
@@ -89,96 +89,12 @@
}
-
-# {{{ sub debug
-
-sub debug {
- my $val = shift;
- my ($debug);
- if ($val) {
- $RT::Logger->debug( $val . "\n" );
- if ($debug) {
- print STDERR "$val\n";
- }
- }
- if ($debug) {
- return (1);
- }
-}
-
-# }}}
-
-# {{{ sub CheckForLoops
-
-sub CheckForLoops {
- my $self = shift;
-
- my $head = $self->Head;
-
- #If this instance of RT sent it our, we don't want to take it in
- my $RTLoop = $head->get("X-RT-Loop-Prevention") || "";
- chomp($RTLoop); #remove that newline
- if ( $RTLoop =~ /^\Q$RT::rtname\E/o ) {
- return (1);
- }
-
- # TODO: We might not trap the case where RT instance A sends a mail
- # to RT instance B which sends a mail to ...
- return (undef);
-}
-
-# }}}
-
-# {{{ sub CheckForSuspiciousSender
-
-sub CheckForSuspiciousSender {
- my $self = shift;
-
- #if it's from a postmaster or mailer daemon, it's likely a bounce.
-
- #TODO: better algorithms needed here - there is no standards for
- #bounces, so it's very difficult to separate them from anything
- #else. At the other hand, the Return-To address is only ment to be
- #used as an error channel, we might want to put up a separate
- #Return-To address which is treated differently.
-
- #TODO: search through the whole email and find the right Ticket ID.
-
- my ( $From, $junk ) = $self->ParseSenderAddressFromHead();
-
- if ( ( $From =~ /^mailer-daemon/i ) or ( $From =~ /^postmaster/i ) ) {
- return (1);
-
- }
-
- return (undef);
-
-}
-
-# }}}
-
-# {{{ sub CheckForAutoGenerated
-sub CheckForAutoGenerated {
- my $self = shift;
- my $head = $self->Head;
-
- my $Precedence = $head->get("Precedence") || "";
- if ( $Precedence =~ /^(bulk|junk)/i ) {
- return (1);
- }
- else {
- return (undef);
- }
-}
-
-# }}}
-
+# {{{ sub SmartParseMIMEEntityFromScalar
=head2 SmartParseMIMEEntityFromScalar { Message => SCALAR_REF, Decode => BOOL }
Parse a message stored in a scalar from scalar_ref
-
=cut
sub SmartParseMIMEEntityFromScalar {
@@ -223,8 +139,16 @@
}
+# }}}
+
# {{{ sub ParseMIMEEntityFromSTDIN
+=head2 ParseMIMEEntityFromSTDIN
+
+Parse a message from standard input
+
+=cut
+
sub ParseMIMEEntityFromSTDIN {
my $self = shift;
my $postprocess = (@_ ? shift : 1);
@@ -233,6 +157,8 @@
# }}}
+# {{{ ParseMIMEEntityFromScalar
+
=head2 ParseMIMEEntityFromScalar $message
Takes either a scalar or a reference to a scalr which contains a stringified MIME message.
@@ -241,7 +167,6 @@
Returns true if it wins.
Returns false if it loses.
-
=cut
sub ParseMIMEEntityFromScalar {
@@ -251,6 +176,7 @@
$self->_ParseMIMEEntity($message,'parse_data', $postprocess);
}
+# }}}
# {{{ ParseMIMEEntityFromFilehandle *FH
@@ -285,8 +211,8 @@
}
# }}}
-#
-# {{{ _ParseMIMEEntity {
+
+# {{{ _ParseMIMEEntity
sub _ParseMIMEEntity {
my $self = shift;
my $message = shift;
@@ -314,7 +240,6 @@
}
-
# }}}
# {{{ _PostProcessNewEntity
@@ -342,214 +267,6 @@
# }}}
-# {{{ sub ParseTicketId
-
-sub ParseTicketId {
- my $self = shift;
-
- my $Subject = shift;
-
- if ( $Subject =~ s/\[\Q$RT::rtname\E\s+\#(\d+)\s*\]//i ) {
- my $id = $1;
- $RT::Logger->debug("Found a ticket ID. It's $id");
- return ($id);
- }
- else {
- return (undef);
- }
-}
-
-# }}}
-
-
-
-# {{{ ParseCcAddressesFromHead
-
-=head2 ParseCcAddressesFromHead HASHREF
-
-Takes a hashref object containing QueueObj, Head and CurrentUser objects.
-Returns a list of all email addresses in the To and Cc
-headers b<except> the current Queue\'s email addresses, the CurrentUser\'s
-email address and anything that the $RTAddressRegexp matches.
-
-=cut
-
-sub ParseCcAddressesFromHead {
-
- my $self = shift;
-
- my %args = (
- QueueObj => undef,
- CurrentUser => undef,
- @_
- );
-
- my (@Addresses);
-
- my @ToObjs = Mail::Address->parse( $self->Head->get('To') );
- my @CcObjs = Mail::Address->parse( $self->Head->get('Cc') );
-
- foreach my $AddrObj ( @ToObjs, @CcObjs ) {
- my $Address = $AddrObj->address;
- my $user = RT::User->new($RT::SystemUser);
- $Address = $user->CanonicalizeEmailAddress($Address);
- next if ( $args{'CurrentUser'}->EmailAddress =~ /^$Address$/i );
- next if ( $args{'QueueObj'}->CorrespondAddress =~ /^$Address$/i );
- next if ( $args{'QueueObj'}->CommentAddress =~ /^$Address$/i );
- next if ( IsRTAddress($Address) );
-
- push ( @Addresses, $Address );
- }
- return (@Addresses);
-}
-
-# }}}
-
-# {{{ ParseSenderAdddressFromHead
-
-=head2 ParseSenderAddressFromHead
-
-Takes a MIME::Header object. Returns a tuple: (user at host, friendly name)
-of the From (evaluated in order of Reply-To:, From:, Sender)
-
-=cut
-
-sub ParseSenderAddressFromHead {
- my $self = shift;
-
- #Figure out who's sending this message.
- my $From = $self->Head->get('Reply-To')
- || $self->Head->get('From')
- || $self->Head->get('Sender');
- return ( $self->ParseAddressFromHeader($From) );
-}
-
-# }}}
-
-# {{{ ParseErrorsToAdddressFromHead
-
-=head2 ParseErrorsToAddressFromHead
-
-Takes a MIME::Header object. Return a single value : user at host
-of the From (evaluated in order of Errors-To:,Reply-To:, From:, Sender)
-
-=cut
-
-sub ParseErrorsToAddressFromHead {
- my $self = shift;
-
- #Figure out who's sending this message.
-
- foreach my $header ( 'Errors-To', 'Reply-To', 'From', 'Sender' ) {
-
- # If there's a header of that name
- my $headerobj = $self->Head->get($header);
- if ($headerobj) {
- my ( $addr, $name ) = $self->ParseAddressFromHeader($headerobj);
-
- # If it's got actual useful content...
- return ($addr) if ($addr);
- }
- }
-}
-
-# }}}
-
-# {{{ ParseAddressFromHeader
-
-=head2 ParseAddressFromHeader ADDRESS
-
-Takes an address from $self->Head->get('Line') and returns a tuple: user at host, friendly name
-
-=cut
-
-sub ParseAddressFromHeader {
- my $self = shift;
- my $Addr = shift;
-
- my @Addresses = Mail::Address->parse($Addr);
-
- my $AddrObj = $Addresses[0];
-
- unless ( ref($AddrObj) ) {
- return ( undef, undef );
- }
-
- my $Name = ( $AddrObj->phrase || $AddrObj->comment || $AddrObj->address );
-
- #Lets take the from and load a user object.
- my $Address = $AddrObj->address;
-
- return ( $Address, $Name );
-}
-
-# }}}
-
-# {{{ IsRTAddress
-
-=item IsRTaddress ADDRESS
-
-Takes a single parameter, an email address.
-Returns true if that address matches the $RTAddressRegexp.
-Returns false, otherwise.
-
-=begin testing
-
-is(RT::EmailParser::IsRTAddress("","rt\@example.com"),1, "Regexp matched rt address" );
-is(RT::EmailParser::IsRTAddress("","frt\@example.com"),undef, "Regexp didn't match non-rt address" );
-
-=end testing
-
-=cut
-
-sub IsRTAddress {
- my $self = shift;
- my $address = shift;
-
- # Example: the following rule would tell RT not to Cc
- # "tickets at noc.example.com"
- if ( defined($RT::RTAddressRegexp) &&
- $address =~ /$RT::RTAddressRegexp/ ) {
- return(1);
- } else {
- return (undef);
- }
-}
-
-# }}}
-
-
-# {{{ CullRTAddresses
-
-=item CullRTAddresses ARRAY
-
-Takes a single argument, an array of email addresses.
-Returns the same array with any IsRTAddress()es weeded out.
-
-=begin testing
-
- at before = ("rt\@example.com", "frt\@example.com");
- at after = ("frt\@example.com");
-ok(eq_array(RT::EmailParser::CullRTAddresses("", at before), at after), "CullRTAddresses only culls RT addresses");
-
-=end testing
-
-=cut
-
-sub CullRTAddresses {
- my $self = shift;
- my @addresses= (@_);
- my @addrlist;
-
- foreach my $addr( @addresses ) {
- push (@addrlist, $addr) unless IsRTAddress("", $addr);
- }
- return (@addrlist);
-}
-
-# }}}
-
-
# {{{ LookupExternalUserInfo
@@ -639,6 +356,7 @@
}
# }}}
+
# {{{ _SetupMIMEParser
=head2 _SetupMIMEParser $parser
@@ -684,7 +402,6 @@
# Temp files should never be recycled, especially when running under perl taint checking
$parser->tmp_recycling(0);
-
}
Modified: rt/branches/3.3-TESTING/lib/RT/I18N.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/I18N.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/I18N.pm Tue Aug 17 22:42:49 2004
@@ -360,7 +360,6 @@
# }}}
-
# {{{ _GuessCharset
=head2 _GuessCharset STRING
@@ -426,6 +425,7 @@
return if $charset eq $enc and $preserve_words;
foreach my $tag ( $head->tags ) {
+ next unless $tag; # seen in wild: headers with no name
my @values = $head->get_all($tag);
$head->delete($tag);
foreach my $value (@values) {
Modified: rt/branches/3.3-TESTING/lib/RT/Interface/Email.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/Interface/Email.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/Interface/Email.pm Tue Aug 17 22:42:49 2004
@@ -64,15 +64,15 @@
# as well as any optionally exported functions
@EXPORT_OK = qw(
&CreateUser
- &GetMessageContent
- &CheckForLoops
- &CheckForSuspiciousSender
- &CheckForAutoGenerated
- &MailError
- &ParseCcAddressesFromHead
- &ParseSenderAddressFromHead
- &ParseErrorsToAddressFromHead
- &ParseAddressFromHeader
+ &GetMessageContent
+ &CheckForLoops
+ &CheckForSuspiciousSender
+ &CheckForAutoGenerated
+ &MailError
+ &ParseCcAddressesFromHead
+ &ParseSenderAddressFromHead
+ &ParseErrorsToAddressFromHead
+ &ParseAddressFromHeader
&Gateway);
}
@@ -166,6 +166,51 @@
# }}}
+# {{{ IsRTAddress
+
+=item IsRTAddress ADDRESS
+
+Takes a single parameter, an email address.
+Returns true if that address matches the $RTAddressRegexp.
+Returns false, otherwise.
+
+=cut
+
+sub IsRTAddress {
+ my $address = shift;
+
+ # Example: the following rule would tell RT not to Cc
+ # "tickets at noc.example.com"
+ if ( defined($RT::RTAddressRegexp) &&
+ $address =~ /$RT::RTAddressRegexp/ ) {
+ return(1);
+ } else {
+ return (undef);
+ }
+}
+
+# }}}
+
+# {{{ CullRTAddresses
+
+=item CullRTAddresses ARRAY
+
+Takes a single argument, an array of email addresses.
+Returns the same array with any IsRTAddress()es weeded out.
+
+=cut
+
+sub CullRTAddresses {
+ my @addresses = (@_);
+ my @addrlist;
+
+ foreach my $addr( @addresses ) {
+ push (@addrlist, $addr) unless IsRTAddress($addr);
+ }
+ return (@addrlist);
+}
+
+# }}}
# {{{ sub MailError
sub MailError {
@@ -270,7 +315,8 @@
return $CurrentUser;
}
-# }}}
+# }}}
+
# {{{ ParseCcAddressesFromHead
=head2 ParseCcAddressesFromHead HASHREF
@@ -299,7 +345,7 @@
next if ($args{'CurrentUser'}->EmailAddress =~ /^$Address$/i);
next if ($args{'QueueObj'}->CorrespondAddress =~ /^$Address$/i);
next if ($args{'QueueObj'}->CommentAddress =~ /^$Address$/i);
- next if (RT::EmailParser::IsRTAddress(undef, $Address));
+ next if (IsRTAddress($Address));
push (@Addresses, $Address);
}
@@ -365,6 +411,8 @@
sub ParseAddressFromHeader{
my $Addr = shift;
+ # Perl 5.8.0 breaks when doing regex matches on utf8
+ Encode::_utf8_off($Addr) if $] == 5.008;
my @Addresses = Mail::Address->parse($Addr);
my $AddrObj = $Addresses[0];
@@ -382,6 +430,22 @@
}
# }}}
+# {{{ sub ParseTicketId
+
+sub ParseTicketId {
+ my $Subject = shift;
+
+ if ( $Subject =~ s/\[\Q$RT::rtname\E\s+\#(\d+)\s*\]//i ) {
+ my $id = $1;
+ $RT::Logger->debug("Found a ticket ID. It's $id");
+ return ($id);
+ }
+ else {
+ return (undef);
+ }
+}
+
+# }}}
=head2 Gateway ARGSREF
@@ -469,7 +533,7 @@
my $Subject = $head->get('Subject') || '';
chomp $Subject;
- $args{'ticket'} ||= $parser->ParseTicketId($Subject);
+ $args{'ticket'} ||= ParseTicketId($Subject);
my $SystemTicket;
my $Right = 'CreateTicket';
Modified: rt/branches/3.3-TESTING/lib/RT/Queue_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/Queue_Overlay.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/Queue_Overlay.pm Tue Aug 17 22:42:49 2004
@@ -70,7 +70,7 @@
use vars qw(@STATUS @ACTIVE_STATUS @INACTIVE_STATUS $RIGHTS);
use RT::Groups;
use RT::ACL;
-use RT::EmailParser;
+use RT::Interface::Email;
@ACTIVE_STATUS = qw(new open stalled);
@@ -682,7 +682,7 @@
my $new_user = RT::User->new($RT::SystemUser);
my ( $Address, $Name ) =
- RT::EmailParser::ParseAddressFromHeader('', $args{'Email'});
+ RT::Interface::Email::ParseAddressFromHeader($args{'Email'});
my ( $Val, $Message ) = $new_user->Create(
Name => $Address,
Modified: rt/branches/3.3-TESTING/lib/RT/User_Overlay.pm
==============================================================================
--- rt/branches/3.3-TESTING/lib/RT/User_Overlay.pm (original)
+++ rt/branches/3.3-TESTING/lib/RT/User_Overlay.pm Tue Aug 17 22:42:49 2004
@@ -75,7 +75,7 @@
use Digest::MD5;
use RT::Principals;
use RT::ACE;
-use RT::EmailParser;
+use RT::Interface::Email;
# {{{ sub _Accessible
@@ -582,7 +582,7 @@
my ($val, $message);
my ( $Address, $Name ) =
- RT::EmailParser::ParseAddressFromHeader('', $email);
+ RT::Interface::Email::ParseAddressFromHeader($email);
$email = $Address;
$self->LoadByEmail($email);
More information about the Rt-commit
mailing list