[Rt-commit] rt branch 5.0/outlook-rfc822-attachment-name created. rt-5.0.5-35-g4f86547751

BPS Git Server git at git.bestpractical.com
Tue Nov 28 20:51:06 UTC 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/outlook-rfc822-attachment-name has been created
        at  4f865477512bd06c751b2458f77b59ded8e37558 (commit)

- Log -----------------------------------------------------------------
commit 4f865477512bd06c751b2458f77b59ded8e37558
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Oct 26 12:14:16 2023 -0400

    Set filename of rfc822 attachments when it's absent for Outlook
    
    Outlook on Windows doesn't include filename when attaching .msg files in
    generated emails, which broke RT's logic to render them as downloadable
    attachments.
    
    This commit fixes it by setting the filename to the subject header of
    the .msg file plus .eml suffix, which is also consistent with gmail's
    behavior.

diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index 8dce9a9c19..2451083b22 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -675,7 +675,12 @@ in it.  it's cool to have a 'text/plain' part, but the problem is the part is
 not so right: all the "\n" in your main message will become "\n\n" :/
 
 this method will fix this bug, i.e. replaces "\n\n" to "\n".
-return 1 if it does find the problem in the entity and get it fixed.
+
+Outlook on Windows has another weird behavior that it drops the filename
+when attaching .msg files. This method sets the absent filename to the
+Subject header of attached .msg files with suffix ".eml".
+
+return 1 if it finds some problems above in the entity and get it fixed.
 
 =cut
 
@@ -686,6 +691,7 @@ sub RescueOutlook {
 
     return unless $mime && $self->LooksLikeMSEmail($mime);
 
+    my $changed;
     my $text_part;
     if ( $mime->head->get('Content-Type') =~ m{multipart/mixed} ) {
         my $first = $mime->parts(0);
@@ -727,7 +733,7 @@ sub RescueOutlook {
                 $io->close;
                 $RT::Logger->debug(
                     "Removed extra newlines from MS Outlook message.");
-                return 1;
+                $changed = 1;
             }
             else {
                 $RT::Logger->error("Can't write to body to fix newlines");
@@ -735,7 +741,38 @@ sub RescueOutlook {
         }
     }
 
-    return;
+    # Fix the absent filename of rfc822 attachments
+    for my $part ( $mime->parts ) {
+        my $head = $part->head;
+        my $type = $head->get('Content-Type') // '';
+
+        my $disposition = $head->get('Content-Disposition') // '';
+        if (   $type =~ m{message/rfc822}
+            && $type        !~ /name=\S/
+            && $disposition =~ /attachment/
+            && $disposition !~ /filename=\S/ )
+        {
+            my $subject;
+            for my $line ( @{ $part->body } ) {
+                if ( $line =~ /^Subject:\s*(.*\S)/ ) {
+                    $subject = $1;
+                    last;
+                }
+            }
+
+            if ($subject) {
+                $disposition =~ s!\s+$!!;
+                $head->replace( 'Content-Disposition', qq{$disposition; filename="$subject.eml"} );
+                $changed = 1;
+            }
+            else {
+                $RT::Logger->warning("Can't find email subject when replacing missing filename in Outlook attachment");
+            }
+        }
+
+    }
+
+    return $changed;
 }
 
 =head1 LooksLikeMSEmail

commit 423667891983ad71fa7fb9590c2fc428041d1a88
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Oct 26 12:14:11 2023 -0400

    Test rfc822 attachments for Outlook on windows
    
    This is to make sure rfc822 attachments have filename set.

diff --git a/t/data/emails/outlook-rfc822 b/t/data/emails/outlook-rfc822
new file mode 100644
index 0000000000..01d3bb9ca8
--- /dev/null
+++ b/t/data/emails/outlook-rfc822
@@ -0,0 +1,117 @@
+Delivered-To: rt at example.com
+Received: by 2002:a59:cdd0:0:b0:3fe:a390:5dd8 with SMTP id t16csp775209vqm;
+        Tue, 17 Oct 2023 10:10:16 -0700 (PDT)
+X-Received: by 2002:a17:90a:e395:b0:27d:1339:9176 with SMTP id b21-20020a17090ae39500b0027d13399176mr2814426pjz.25.1697562615803;
+        Tue, 17 Oct 2023 10:10:15 -0700 (PDT)
+Return-Path: <root at localhost>
+From: "root at localhost" <root at localhost>
+To: "rt at example.com" <rt at example.com>
+Subject: msg attachment
+Thread-Topic: msg attachment
+Thread-Index: AdoBHLGUtaY+wvYtQv2Hq3qNQkYWnA==
+Date: Tue, 17 Oct 2023 17:10:11 +0000
+Message-ID:
+ <MN6PR12MB8566625839C42BCD2B16AC1B8FD6A at MN6PR12MB8566.namprd12.prod.outlook.com>
+Accept-Language: en-US
+Content-Language: en-US
+X-MS-Has-Attach: yes
+X-MS-TNEF-Correlator:
+x-tmn: [29MKDC21mxOxQSnVorVlrV/NMPchKAjb]
+x-ms-publictraffictype: Email
+x-ms-traffictypediagnostic: MN6PR12MB8566:EE_|LV8PR12MB9357:EE_
+x-ms-office365-filtering-correlation-id: e59601fe-db89-4a57-07a4-08dbcf33ec02
+x-microsoft-antispam: BCL:0;
+x-microsoft-antispam-message-info:
+ TiFLTXuibn2exfoLdhUlGA8CkdG/H4PiplxHcPDdrbsuen1r8B6AQQbjqz+xC+Fd9TNd15mSeLdvw+YEm3XQnRKGox97jpBHnGEGWEzhBc+KDmYPhgDozZeiI2RvDYx8UgUBOUcBkf1YNR1Ghb2fMvhwNwNSQKhQmflO4IfKrKl5jh8om/K06b0KAheAmwUJDVcr/60sRQ8toTk1R3K5QTQP0svkhhdmWBGbRtfI5wAec3bb430GQPRmy7prn8GxFROQsmDQUbg2hMMAbty0gQryAClsocYbai5rrJhVbIwhjqMNAhJPHo8p7Ym34OQX5MaK36tyZpQ7TpPkQZLvyvGt+dyL0RSN/LKHPaB/DwrcaSgkRmhMt4E0ZHSpdhSvgjik5KfdMJIzwxHyP6hiuxtNHTln/1MbMwCgLph4MZlNeDjDVp7SBe3fQJuRPl1h9rgmbFcKL9UIthK4Wp8mErvCevrxL3x8MeJG3Ep0EhKIi8/JzYbeWOBjtsPEIXtH90LpZoqDh+OAG8nDnujw3xCKSD07OWkxXpNlwlCbKOO1MTbGOuzE1MzpHrOmuGWV
+x-ms-exchange-antispam-messagedata-chunkcount: 1
+Content-Type: multipart/mixed;
+	boundary="_004_MN6PR12MB8566625839C42BCD2B16AC1B8FD6AMN6PR12MB8566namp_"
+MIME-Version: 1.0
+X-OriginatorOrg: outlook.com
+X-MS-Exchange-CrossTenant-AuthAs: Internal
+X-MS-Exchange-CrossTenant-AuthSource: MN6PR12MB8566.namprd12.prod.outlook.com
+X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000
+X-MS-Exchange-CrossTenant-Network-Message-Id: e59601fe-db89-4a57-07a4-08dbcf33ec02
+X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Oct 2023 17:10:11.2717
+ (UTC)
+X-MS-Exchange-CrossTenant-fromentityheader: Hosted
+X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa
+X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000
+X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9357
+
+--_004_MN6PR12MB8566625839C42BCD2B16AC1B8FD6AMN6PR12MB8566namp_
+Content-Type: multipart/alternative;
+	boundary="_000_MN6PR12MB8566625839C42BCD2B16AC1B8FD6AMN6PR12MB8566namp_"
+
+--_000_MN6PR12MB8566625839C42BCD2B16AC1B8FD6AMN6PR12MB8566namp_
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: base64
+
+Q291bGQgdGhpcyBsb29rIG1vcmUgc3BhbW15PyDigJxDaGVjayBvdXQgdGhlIGF0dGFjaGVkIGZp
+bGUu4oCdIPCfmIoNCg0K
+
+--_000_MN6PR12MB8566625839C42BCD2B16AC1B8FD6AMN6PR12MB8566namp_
+Content-Type: text/html; charset="utf-8"
+Content-Transfer-Encoding: base64
+
+Q291bGQgdGhpcyBsb29rIG1vcmUgc3BhbW15PyDigJxDaGVjayBvdXQgdGhlIGF0dGFjaGVkIGZp
+bGUu4oCdIPCfmIoNCg0K
+
+--_000_MN6PR12MB8566625839C42BCD2B16AC1B8FD6AMN6PR12MB8566namp_--
+
+--_004_MN6PR12MB8566625839C42BCD2B16AC1B8FD6AMN6PR12MB8566namp_
+Content-Type: message/rfc822
+Content-Disposition: attachment;
+	creation-date="Tue, 17 Oct 2023 17:10:09 GMT";
+	modification-date="Tue, 17 Oct 2023 17:10:10 GMT"
+
+From: Microsoft <foo at example.com>
+To: "root at localhost" <root at localhost>
+Subject: Updates to our terms of use
+Thread-Topic: Updates to our terms of use
+Thread-Index: AQHZ3G6S2NqlTMxGqEWck31pLpqTxw==
+Date: Thu, 31 Aug 2023 15:51:33 +0000
+Message-ID:
+ <[dd32db759b6e4b39ab644f715129f3be-JFBVALKQOJXWILKNK4YVA7CDIRXECRLNMFUWYUDMMF2GM33SNV6EGRDOIF6EK6DPKNWXI4A=@microsoft.com]>
+Content-Language: en-US
+X-MS-Exchange-Organization-AuthSource:
+ DM6NAM04FT067.eop-NAM04.prod.protection.outlook.com
+X-MS-Has-Attach:
+X-MS-Exchange-Organization-Network-Message-Id:
+ d60238f0-f29d-47ea-db6b-08dbaa3a2771
+X-MS-Exchange-Organization-PCL: 2
+X-MS-TNEF-Correlator:
+X-MS-Exchange-Organization-RecordReviewCfmType: 0
+received-spf: Pass (protection.outlook.com: domain of
+ communication.microsoft.com designates 40.92.18.248 as permitted sender)
+ receiver=protection.outlook.com; client-ip=40.92.18.248;
+ helo=NAM11-CO1-obe.outbound.protection.outlook.com; pr=C
+x-ms-exchange-organization-originalclientipaddress: 40.92.18.248
+x-ms-exchange-organization-originalserveripaddress: 10.13.158.202
+x-ms-publictraffictype: Email
+X-Microsoft-Antispam-Mailbox-Delivery:
+ ucf:0;jmr:0;ex:0;auth:1;dest:I;ENG:(5062000305)(920221119095)(90000117)(920221120095)(90005022)(91005020)(91035115)(9050020)(9100341)(944500132)(4810010)(4910033)(9910022)(9510006)(10110021)(9320005)(120001);
+X-Message-Info:
+ qZelhIiYnPmhz5sW4zcU6pjCrw8JfJTU7pT5XA+pJQU1CnmxgHrud8DFgWds+/2b0Br2JClH1DJgMh/YZ6BsF7FkZkMiV5c98RQrmUC5jpKuBD0m9TlvhjOulTQ64MO1Px6pID6hK1ZiUbU2Byk0TrOzCJFNcm4zQ2hiOduA16eNxfIGXdwTFRjfWN8fNuCkBinv3xWTW7g=
+X-Message-Delivery: Vj0xLjE7dXM9MDtsPTA7YT0xO0Q9MTtHRD0xO1NDTD0tMQ==
+
+Content-Type: multipart/alternative;
+	boundary="_000_dd32db759b6e4b39ab644f715129f3beJFBVALKQOJXWILKNK4YVA7C_"
+MIME-Version: 1.0
+
+--_000_dd32db759b6e4b39ab644f715129f3beJFBVALKQOJXWILKNK4YVA7C_
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: base64
+
+dGhpcyBpcyBhIHRlc3QK
+
+--_000_dd32db759b6e4b39ab644f715129f3beJFBVALKQOJXWILKNK4YVA7C_
+Content-Type: text/html; charset="utf-8"
+Content-ID: <24a78fe7-14e9-4290-a638-c39b2828575c>
+Content-Transfer-Encoding: base64
+
+PHA+dGhpcyBpcyBhIHRlc3Q8L3AKPg==
+
+--_000_dd32db759b6e4b39ab644f715129f3beJFBVALKQOJXWILKNK4YVA7C_--
+
+--_004_MN6PR12MB8566625839C42BCD2B16AC1B8FD6AMN6PR12MB8566namp_--
diff --git a/t/mail/outlook.t b/t/mail/outlook.t
index 8f3b71bc8b..bea0c6ed18 100644
--- a/t/mail/outlook.t
+++ b/t/mail/outlook.t
@@ -1,9 +1,10 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 66;
+use RT::Test tests => undef;
 
 RT->Config->Set('CheckMoreMSMailHeaders', 1);
+RT->Config->Set('TreatAttachedEmailAsFiles', 1);
 
 # 12.0 is outlook 2007, 14.0 is 2010
 for my $mailer ( 'Microsoft Office Outlook 12.0', 'Microsoft Outlook 14.0' ) {
@@ -386,8 +387,17 @@ EOF
                     'Another sample multipart message with Exchange headers' );
 }
 
+test_email( 'outlook-rfc822', 'rfc822:Updates to our terms of use.eml', 'Set the rfc822 attachment filename' );
+
 sub test_email {
     my ( $text, $content, $msg ) = @_;
+
+    # Get the real content if it's a filename
+    if ( $text =~ /^[-.\w]+$/ ) {
+        my $path = RT::Test::get_relocatable_file( $text, ( File::Spec->updir(), 'data', 'emails' ) );
+        $text = RT::Test->file_content($path);
+    }
+
     my ( $status, $id ) = RT::Test->send_via_mailgate($text);
     is( $status >> 8, 0, "The mail gateway exited normally" );
     ok( $id, "Created ticket" );
@@ -395,11 +405,23 @@ sub test_email {
     my $ticket = RT::Test->last_ticket;
     isa_ok( $ticket, 'RT::Ticket' );
     is( $ticket->Id, $id, "correct ticket id" );
-    is( $ticket->Subject, 'outlook basic test', "subject of ticket $id" );
-    my $txns = $ticket->Transactions;
-    $txns->Limit( FIELD => 'Type', VALUE => 'Create' );
-    my $txn     = $txns->First;
 
-    is( $txn->Content, $content, $msg );
+    if ( $content =~ /^rfc822:(.+)/ ) {
+        my $name        = $1;
+        my $attachments = $ticket->Attachments;
+        $attachments->Limit( FIELD => 'ContentType', VALUE => 'message/rfc822' );
+        my $rfc822 = $attachments->First;
+        ok( $rfc822, 'Found rfc822 attachment' );
+        is( $rfc822->Filename, $name, $msg );
+    }
+    else {
+        is( $ticket->Subject, 'outlook basic test', "subject of ticket $id" );
+
+        my $txns = $ticket->Transactions;
+        $txns->Limit( FIELD => 'Type', VALUE => 'Create' );
+        my $txn = $txns->First;
+        is( $txn->Content, $content, $msg );
+    }
 }
 
+done_testing;

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list