[Bps-public-commit] rt-extension-futuremailgate branch, master, updated. 0a2c8bf650db91dc86d2b71b6e3d80b8151e69ed

Shawn Moore shawn at bestpractical.com
Fri Sep 9 11:48:49 EDT 2016


The branch, master has been updated
       via  0a2c8bf650db91dc86d2b71b6e3d80b8151e69ed (commit)
       via  d6a19195415477cba360069381500de20c75fd88 (commit)
       via  d39e98c7cb71faa12dfebc1d1ffe2842c18db724 (commit)
       via  5ddb44788a568be86bc7921412efe6e7b5badb3a (commit)
       via  4edc5d3427f47969e4080e8dcb970e1d820948ea (commit)
      from  7865ab3d416c70502ccebea91be0a6344d8fc349 (commit)

Summary of changes:
 lib/RT/Interface/Email/Action/Defaults.pm |  7 ++--
 lib/RT/Interface/Email/Action/Resolve.pm  |  2 +-
 lib/RT/Interface/Email/Action/Take.pm     |  2 +-
 lib/RT/Interface/Email_Local.pm           | 56 +++++++++++++++++--------------
 4 files changed, 36 insertions(+), 31 deletions(-)

- Log -----------------------------------------------------------------
commit 4edc5d3427f47969e4080e8dcb970e1d820948ea
Author: Christian Loos <cloos at netcologne.de>
Date:   Mon Aug 29 10:11:43 2016 +0200

    Ensure all MIME::Entity headers are UTF-8 encoded bytes
    
    Integrate changes from
    https://github.com/bestpractical/rt/commit/41d084f

diff --git a/lib/RT/Interface/Email/Action/Defaults.pm b/lib/RT/Interface/Email/Action/Defaults.pm
index 97ae938..d359337 100644
--- a/lib/RT/Interface/Email/Action/Defaults.pm
+++ b/lib/RT/Interface/Email/Action/Defaults.pm
@@ -94,14 +94,15 @@ sub _HandleCreate {
         @Cc =
             grep $_ ne $current_address && !RT::EmailParser->IsRTAddress( $_ ),
             map lc $user->CanonicalizeEmailAddress( $_->address ),
-            map $cleanup->( Email::Address->parse( $head->get( $_ ) ) ),
+            map $cleanup->( Email::Address->parse(
+                  Encode::decode( "UTF-8", $head->get( $_ ) ) ) ),
             qw(To Cc);
     }
 
     $head->replace('X-RT-Interface' => 'Email');
 
     # ExtractTicketId may have been overridden, and edited the Subject
-    my $subject = $head->get('Subject');
+    my $subject = Encode::decode( "UTF-8", $head->get('Subject') );
     chomp $subject;
 
     my ( $id, $Transaction, $ErrStr ) = $args{Ticket}->Create(
diff --git a/lib/RT/Interface/Email/Action/Resolve.pm b/lib/RT/Interface/Email/Action/Resolve.pm
index 452a01b..bc0058d 100644
--- a/lib/RT/Interface/Email/Action/Resolve.pm
+++ b/lib/RT/Interface/Email/Action/Resolve.pm
@@ -118,7 +118,7 @@ sub HandleResolve {
         );
     }
 
-    my $From = $args{Message}->head->get("From");
+    my $From = Encode::decode( "UTF-8", $args{Message}->head->get("From") );
 
     my $new_status = $args{'Ticket'}->FirstInactiveStatus;
     return unless $new_status;
diff --git a/lib/RT/Interface/Email/Action/Take.pm b/lib/RT/Interface/Email/Action/Take.pm
index f7e2191..1813a94 100644
--- a/lib/RT/Interface/Email/Action/Take.pm
+++ b/lib/RT/Interface/Email/Action/Take.pm
@@ -110,7 +110,7 @@ sub HandleTake {
         @_,
     );
 
-    my $From = $args{Message}->head->get("From");
+    my $From = Encode::decode( "UTF-8", $args{Message}->head->get("From") );
 
     my ( $status, $msg ) = $args{'Ticket'}->SetOwner( $args{Ticket}->CurrentUser->id );
     return if $status;
diff --git a/lib/RT/Interface/Email_Local.pm b/lib/RT/Interface/Email_Local.pm
index 0a8b6ed..3a077f4 100644
--- a/lib/RT/Interface/Email_Local.pm
+++ b/lib/RT/Interface/Email_Local.pm
@@ -188,11 +188,11 @@ sub Gateway {
     $parser->_PostProcessNewEntity;
 
     my $head = $Message->head;
-    my $From = $head->get("From");
+    my $From = Encode::decode( "UTF-8", $head->get("From") );
     chomp $From if defined $From;
 
     #Pull apart the subject line
-    my $Subject = $head->get('Subject') || '';
+    my $Subject = Encode::decode( "UTF-8", $head->get('Subject') || '');
     chomp $Subject;
 
     # Lets check for mail loops of various sorts.
@@ -439,7 +439,7 @@ sub ParseSenderAddressFromHead {
     my @errors;  # Accumulate any errors
 
     foreach my $header ( 'Reply-To', 'From', 'Sender' ) {
-        my $addr_line = $head->get($header) || next;
+        my $addr_line = Encode::decode( "UTF-8", $head->get($header) ) || next;
         my ($addr) = RT::EmailParser->ParseEmailAddress( $addr_line );
         return ($addr->address, $addr->phrase, @errors) if $addr;
 
@@ -461,7 +461,7 @@ sub ParseErrorsToAddressFromHead {
     my $head = shift;
 
     foreach my $header ( 'Errors-To', 'Reply-To', 'From', 'Sender' ) {
-        my $value = $head->get($header);
+        my $value = Encode::decode( "UTF-8", $head->get($header) );
         next unless $value;
 
         my ( $email ) = RT::EmailParser->ParseEmailAddress($value);
@@ -497,7 +497,7 @@ sub IsMachineGeneratedMail {
 
     # Warn someone if it's a loop, before we drop it on the ground
     if ($IsALoop) {
-        my $MessageId = $head->get('Message-ID');
+        my $MessageId = Encode::decode( "UTF-8", $head->get('Message-ID') );
         $RT::Logger->crit("RT Received mail ($MessageId) from itself.");
 
         #Should we mail it to RTOwner?
@@ -519,7 +519,7 @@ sub IsMachineGeneratedMail {
     # to the scrip. We might want to notify nobody. Or just
     # the RT Owner. Or maybe all Privileged watchers.
     my ( $Sender ) = ParseSenderAddressFromHead($head);
-    $head->replace( 'RT-Squelch-Replies-To',    $Sender );
+    $head->replace( 'RT-Squelch-Replies-To',    Encode::encode("UTF-8", $Sender ) );
     $head->replace( 'RT-DetectedAutoGenerated', 'true' );
 
     return 1;
@@ -536,7 +536,7 @@ sub CheckForLoops {
     my $head = shift;
 
     # If this instance of RT sent it our, we don't want to take it in
-    my $RTLoop = $head->get("X-RT-Loop-Prevention") || "";
+    my $RTLoop = Encode::decode( "UTF-8", $head->get("X-RT-Loop-Prevention") || "" );
     chomp ($RTLoop); # remove that newline
     if ( $RTLoop eq RT->Config->Get('rtname') ) {
         return 1;
@@ -602,7 +602,7 @@ will be used during ticket creation.
 sub ExtractTicketId {
     my $entity = shift;
 
-    my $subject = $entity->head->get('Subject') || '';
+    my $subject = Encode::decode( "UTF-8", $entity->head->get('Subject') || '' );
     chomp $subject;
     return ParseTicketId( $subject );
 }
@@ -700,21 +700,26 @@ sub MailError {
     # the colons are necessary to make ->build include non-standard headers
     my %entity_args = (
         Type                    => "multipart/mixed",
-        From                    => $args{'From'},
-        To                      => $args{'To'},
-        Subject                 => $args{'Subject'},
-        'X-RT-Loop-Prevention:' => RT->Config->Get('rtname'),
+        From                    => Encode::encode( "UTF-8", $args{'From'} ),
+        To                      => Encode::encode( "UTF-8", $args{'To'} ),
+        Subject                 => EncodeToMIME( String => $args{'Subject'} ),
+        'X-RT-Loop-Prevention:' => Encode::encode( "UTF-8", RT->Config->Get('rtname') ),
     );
 
     # only set precedence if the sysadmin wants us to
     if (defined(RT->Config->Get('DefaultErrorMailPrecedence'))) {
-        $entity_args{'Precedence:'} = RT->Config->Get('DefaultErrorMailPrecedence');
+        $entity_args{'Precedence:'} =
+            Encode::encode( "UTF-8", RT->Config->Get('DefaultErrorMailPrecedence') );
     }
 
     my $entity = MIME::Entity->build(%entity_args);
     SetInReplyTo( Message => $entity, InReplyTo => $args{'MIMEObj'} );
 
-    $entity->attach( Data => $args{'Explanation'} . "\n" );
+    $entity->attach(
+        Type    => "text/plain",
+        Charset => "UTF-8",
+        Data    => Encode::encode( "UTF-8", $args{'Explanation'} . "\n" ),
+    );
 
     if ( $args{'MIMEObj'} ) {
         $args{'MIMEObj'}->sync_headers;
@@ -722,7 +727,7 @@ sub MailError {
     }
 
     if ( $args{'Attach'} ) {
-        $entity->attach( Data => $args{'Attach'}, Type => 'message/rfc822' );
+        $entity->attach( Data => Encode::encode( "UTF-8", $args{'Attach'} ), Type => 'message/rfc822' );
 
     }
 

commit 5ddb44788a568be86bc7921412efe6e7b5badb3a
Author: Christian Loos <cloos at netcologne.de>
Date:   Mon Aug 29 10:41:36 2016 +0200

    Pass CurrentUser to HandleAction methods
    
    Integrate changes from
    https://github.com/bestpractical/rt/commit/0ead601

diff --git a/lib/RT/Interface/Email_Local.pm b/lib/RT/Interface/Email_Local.pm
index 3a077f4..3ff2f43 100644
--- a/lib/RT/Interface/Email_Local.pm
+++ b/lib/RT/Interface/Email_Local.pm
@@ -244,6 +244,7 @@ sub Gateway {
             Action      => $action,
             Subject     => $Subject,
             Message     => $Message,
+            CurrentUser => $CurrentUser,
             Ticket      => $Ticket,
             TicketId    => $args{ticket},
             Queue       => $SystemQueueObj,

commit d39e98c7cb71faa12dfebc1d1ffe2842c18db724
Author: Christian Loos <cloos at netcologne.de>
Date:   Mon Aug 29 10:48:44 2016 +0200

    Detect auto-generated mail correctly when there are multiple Precedence headers
    
    Integrate changes from
    https://github.com/bestpractical/rt/commit/3ca5dc4

diff --git a/lib/RT/Interface/Email_Local.pm b/lib/RT/Interface/Email_Local.pm
index 3ff2f43..cc55147 100644
--- a/lib/RT/Interface/Email_Local.pm
+++ b/lib/RT/Interface/Email_Local.pm
@@ -571,8 +571,7 @@ sub CheckForAutoGenerated {
     return 1 if defined $From and $From eq "";
 
     # Bulk or junk messages are auto-generated
-    my $Precedence = $head->get("Precedence") || "";
-    return 1 if $Precedence =~ /^(bulk|junk)/i;
+    return 1 if grep {/^(bulk|junk)/i} $head->get_all("Precedence");
 
     # Per RFC3834, any Auto-Submitted header which is not "no" means
     # it is auto-generated.

commit d6a19195415477cba360069381500de20c75fd88
Author: Christian Loos <cloos at netcologne.de>
Date:   Mon Aug 29 11:47:31 2016 +0200

    remove last differences between core RT and this extension

diff --git a/lib/RT/Interface/Email/Action/Defaults.pm b/lib/RT/Interface/Email/Action/Defaults.pm
index d359337..88259b1 100644
--- a/lib/RT/Interface/Email/Action/Defaults.pm
+++ b/lib/RT/Interface/Email/Action/Defaults.pm
@@ -99,8 +99,6 @@ sub _HandleCreate {
             qw(To Cc);
     }
 
-    $head->replace('X-RT-Interface' => 'Email');
-
     # ExtractTicketId may have been overridden, and edited the Subject
     my $subject = Encode::decode( "UTF-8", $head->get('Subject') );
     chomp $subject;
diff --git a/lib/RT/Interface/Email_Local.pm b/lib/RT/Interface/Email_Local.pm
index cc55147..608bdde 100644
--- a/lib/RT/Interface/Email_Local.pm
+++ b/lib/RT/Interface/Email_Local.pm
@@ -61,7 +61,7 @@ use Mail::Mailer ();
 use Text::ParseWords qw/shellwords/;
 use MIME::Words ();
 use Scope::Upper qw/unwind HERE/;
-use 5.010_001;
+use 5.010;
 
 =head1 NAME
 
@@ -81,8 +81,8 @@ Takes parameters:
 
 A C<-> separated list of actions to run.  Standard actions, as detailed
 in L<bin/rt-mailgate>, are C<comment> and C<correspond>.  The
-L<RT::Interface::Email::Actions::Take> and
-L<RT::Interface::Email::Actions::Resolve> plugins can be added to
+L<RT::Interface::Email::Action::Take> and
+L<RT::Interface::Email::Action::Resolve> plugins can be added to
 L<RT_Config/@MailPlugins> to provide C<take> and C<resolve> actions,
 respectively.
 
@@ -236,6 +236,8 @@ sub Gateway {
         Queue         => $SystemQueueObj,
     );
 
+    $head->replace('X-RT-Interface' => 'Email');
+
     my $Ticket = RT::Ticket->new($CurrentUser);
     $Ticket->Load( $SystemTicket->Id );
 
@@ -286,7 +288,7 @@ sub Plugins {
                     do { $RT::Logger->error("Couldn't load $Class: $@"); next };
 
                 unless ( $Class->DOES( "RT::Interface::Email::Role" ) ) {
-                    $RT::Logger->crit( "$Class is not an RT::Interface::Email::Role");
+                    $RT::Logger->crit( "$Class does not implement RT::Interface::Email::Role.  Mail plugins from RT 4.2 and earlier are not forward-compatible with RT 4.4.");
                     next;
                 }
                 push @PLUGINS, $Class;
@@ -550,10 +552,9 @@ sub CheckForLoops {
 
 =head3 CheckForAutoGenerated HEAD
 
-Takes a HEAD object of L<MIME::Head> class and returns true if message
-is autogenerated.  This includes bounces, RFC3834 C<Auto-Submitted>
-headers, as well as heuristics including C<Precedence> and
-C<X-FC-Machinegenerated> headers.
+Takes a HEAD object of L<MIME::Head> class and returns true if message is
+autogenerated. Checks C<Precedence>, RFC3834 C<Auto-Submitted>, and
+C<X-FC-Machinegenerated> fields of the head in tests.
 
 =cut
 

commit 0a2c8bf650db91dc86d2b71b6e3d80b8151e69ed
Merge: 7865ab3 d6a1919
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Fri Sep 9 11:48:47 2016 -0400

    Merge branch 'sync-to-core-rt'


-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list