[Rt-commit] rt branch, 4.4/rescue-outlook-html, updated. rt-4.4.3-57-gd4481468c

Gergely Nagy algernon at bestpractical.com
Tue Nov 6 05:38:49 EST 2018


The branch, 4.4/rescue-outlook-html has been updated
       via  d4481468c75387e8fc554d83777209e45dbc88c3 (commit)
      from  20aac9475bfae38670910546b49717c3c7a6409f (commit)

Summary of changes:
 lib/RT/EmailParser.pm |   3 +-
 t/mail/outlook.t      | 151 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 151 insertions(+), 3 deletions(-)

- Log -----------------------------------------------------------------
commit d4481468c75387e8fc554d83777209e45dbc88c3
Author: Gergely Nagy <algernon at bestpractical.com>
Date:   Tue Nov 6 11:36:54 2018 +0100

    Add a new RescueOutlook test case, and improve the cleanup logic
    
    Found a test case in RT that did not get cleaned up, because it turns out, extra
    paragraphs may not have a "<br>" element inside them. Added a new test case, and
    made the line break within the otherwise empty paragraph optional.

diff --git a/lib/RT/EmailParser.pm b/lib/RT/EmailParser.pm
index 3f8ad8ada..796e89c68 100644
--- a/lib/RT/EmailParser.pm
+++ b/lib/RT/EmailParser.pm
@@ -709,8 +709,7 @@ sub RescueOutlook {
         # use the unencoded string
         my $html_content = $html_part->bodyhandle->as_string;
 
-        if ( $html_content =~ s{<p(\s+style="[^"]*")?><br>\n?</p>}{}mg ) {
-
+        if ( $html_content =~ s{<p(\s+style="[^"]*")?>(<br>)?\n?</p>}{}mg ) {
             # only write only if we did change the content
             if ( my $io = $html_part->open("w") ) {
                 $io->print($html_content);
diff --git a/t/mail/outlook.t b/t/mail/outlook.t
index b6538d877..888634e3e 100644
--- a/t/mail/outlook.t
+++ b/t/mail/outlook.t
@@ -7,6 +7,155 @@ RT->Config->Set('CheckMoreMSMailHeaders', 1);
 
 # 12.0 is outlook 2007, 14.0 is 2010
 for my $mailer ( 'Microsoft Office Outlook 12.0', 'Microsoft Outlook 14.0' ) {
+    diag "Test mail with multipart/alternative (in-the-wild case)";
+    {
+        my $text = <<EOF;
+From: root\@localhost
+X-Mailer: $mailer
+To: rt\@@{[RT->Config->Get('rtname')]}
+Subject: outlook basic test
+Content-Type: multipart/alternative;
+\tboundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
+
+------=_NextPart_000_0004_01CB045C.A5A075D0
+content-type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+Hi,
+
+
+What's the best way to add a new line in the below callback, I tried adding \\n but it didn't work.
+
+
+
+
+package RT::Transaction;
+use strict;
+use warnings;
+no warnings 'redefine';
+
+sub QuoteHeader {
+    my \$self = shift;
+    if (\$self->Object->isa('RT::Ticket')) {
+       return \$self->loc("On [_1], [_2] wrote:\nTo: [_3]\nCc: [_4]", \$self->CreatedAsString, \$self->Object->QueueObj->CorrespondAddress,\$self->TicketObj->RequestorAddresses,\$self->TicketObj->CcAddresses);
+    }
+    return \$self->loc("On [_1], [_2] wrote:\nTo: [_3]\nCc: [_4]", \$self->CreatedAsString, \$self->CreatorObj->Name,\$self->TicketObj->RequestorAddresses,\$self->TicketObj->CcAddresses);
+}
+
+1;
+
+------=_NextPart_000_0004_01CB045C.A5A075D0
+content-type: text/html; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
+</head>
+<body dir="ltr">
+<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
+<p style="margin-top:0;margin-bottom:0">Hi,</p>
+<p style="margin-top:0;margin-bottom:0"><br>
+</p>
+<p style="margin-top:0;margin-bottom:0">What's the best way to add a new line in the below callback, I tried adding
+<span style="background-color: rgb(255, 255, 0);">\\n</span> but it didn't work.</p>
+<p style="margin-top:0;margin-bottom:0"><br>
+</p>
+<p style="margin-top:0;margin-bottom:0"><br>
+</p>
+<p style="margin-top:0;margin-bottom:0"><br>
+</p>
+<p style="margin-top:0;margin-bottom:0"></p>
+<div><span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">package RT::Transaction;</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">use strict;</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">use warnings;</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">no warnings 'redefine';</span><br>
+<br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">sub QuoteHeader {</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">    my \$self = shift;</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">    if (\$self->Object->isa('RT::Ticket')) {</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">       return \$self->loc("On [_1], [_2] wrote:<span style="background-color: rgb(255, 255, 0);">\n</span>To: [_3]<span style="background-color: rgb(255, 255, 0);">\n</span>Cc:
+ [_4]", \$self->CreatedAsString, \$self->Object->QueueObj->CorrespondAddress,\$self->TicketObj->RequestorAddresses,\$self->TicketObj->CcAddresses);</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">    }   </span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">    return \$self->loc("On [_1], [_2] wrote:<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);"><span style="background-color: rgb(255, 255, 0);">\n</span></span>To:
+ [_3]<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);"><span style="background-color: rgb(255, 255, 0);">\n</span></span>Cc: [_4]", \$self->CreatedAsString, \$self->CreatorObj->Name,\$self->TicketObj->RequestorAddresses,\$self->TicketObj->CcAddresses);</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">}</span><br>
+<br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">1;</span></div>
+<br>
+<p></p>
+</div></body></html>
+
+------=_NextPart_000_0004_01CB045C.A5A075D0--
+
+EOF
+
+        my $text_content = <<EOF;
+Hi,
+
+What's the best way to add a new line in the below callback, I tried adding \\n but it didn't work.
+
+
+package RT::Transaction;
+use strict;
+use warnings;
+no warnings 'redefine';
+sub QuoteHeader {
+    my \$self = shift;
+    if (\$self->Object->isa('RT::Ticket')) {
+       return \$self->loc("On [_1], [_2] wrote:\nTo: [_3]\nCc: [_4]", \$self->CreatedAsString, \$self->Object->QueueObj->CorrespondAddress,\$self->TicketObj->RequestorAddresses,\$self->TicketObj->CcAddresses);
+    }
+    return \$self->loc("On [_1], [_2] wrote:\nTo: [_3]\nCc: [_4]", \$self->CreatedAsString, \$self->CreatorObj->Name,\$self->TicketObj->RequestorAddresses,\$self->TicketObj->CcAddresses);
+}
+1;
+EOF
+        my $html_content = <<EOF;
+
+
+
+
+
+
+<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
+<p style="margin-top:0;margin-bottom:0">Hi,</p>
+
+<p style="margin-top:0;margin-bottom:0">What's the best way to add a new line in the below callback, I tried adding
+<span style="background-color: rgb(255, 255, 0);">\\n</span> but it didn't work.</p>
+
+
+
+
+<div><span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">package RT::Transaction;</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">use strict;</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">use warnings;</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">no warnings 'redefine';</span><br>
+<br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">sub QuoteHeader {</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">    my \$self = shift;</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">    if (\$self->Object->isa('RT::Ticket')) {</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">       return \$self->loc("On [_1], [_2] wrote:<span style="background-color: rgb(255, 255, 0);">
+</span>To: [_3]<span style="background-color: rgb(255, 255, 0);">
+</span>Cc:
+ [_4]", \$self->CreatedAsString, \$self->Object->QueueObj->CorrespondAddress,\$self->TicketObj->RequestorAddresses,\$self->TicketObj->CcAddresses);</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">    }   </span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">    return \$self->loc("On [_1], [_2] wrote:<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);"><span style="background-color: rgb(255, 255, 0);">
+</span></span>To:
+ [_3]<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);"><span style="background-color: rgb(255, 255, 0);">
+</span></span>Cc: [_4]", \$self->CreatedAsString, \$self->CreatorObj->Name,\$self->TicketObj->RequestorAddresses,\$self->TicketObj->CcAddresses);</span><br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">}</span><br>
+<br>
+<span style="font-family: Consolas, Courier, monospace; color: rgb(117, 123, 128);">1;</span></div>
+<br>
+
+</div>
+EOF
+        test_email( $text, $text_content,
+                    $mailer . ' with multipart/alternative, \n\n are replaced' );
+        test_email( $text, $html_content,
+                    $mailer . ' with multipart/alternative, line-break-only paragraphs removed from the HTML part', "text/html" );
+    }
+
     diag "Test mail with multipart/alternative";
     {
         my $text = <<EOF;
@@ -453,4 +602,4 @@ sub test_email {
     is( $txn->Content(Type => $check_type || "text/plain"), $content, $msg );
 }
 
-done_testing;
\ No newline at end of file
+done_testing;

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


More information about the rt-commit mailing list