[Rt-commit] rt branch 5.0/outlook-plain-quotes-nested-in-html-stanza created. rt-5.0.3-488-g2783d40f55

BPS Git Server git at git.bestpractical.com
Tue Apr 18 15:27:22 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-plain-quotes-nested-in-html-stanza has been created
        at  2783d40f55031476a32fa85e68f935365fa43f01 (commit)

- Log -----------------------------------------------------------------
commit 2783d40f55031476a32fa85e68f935365fa43f01
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Mar 3 02:42:18 2022 +0800

    Test stanza for outlook plain quotes nested in html quotes

diff --git a/t/web/ticket_txn_content.t b/t/web/ticket_txn_content.t
index d092aa9015..ac06824899 100644
--- a/t/web/ticket_txn_content.t
+++ b/t/web/ticket_txn_content.t
@@ -152,4 +152,99 @@ $form    = $m->form_name( 'TicketUpdate' );
 $content = $form->find_input( 'UpdateContent' );
 like( $content->value, qr/This transaction appears to have no content/, 'no transaction content' );
 
+$m->goto_create_ticket( $qid );
+$m->submit_form_ok(
+    {
+        form_name => 'TicketCreate',
+        fields    => {
+            Subject     => 'outlook plain quotes nested in html',
+            ContentType => 'text/html',
+            Content     => <<'EOF',
+<div>On Tue Mar 01 18:29:22 2022, root wrote:
+<blockquote>
+<pre>
+replied from outlook
+
+________________________________________
+From: root <root at localhost>
+Sent: Tuesday, March 1, 2022 2:24 PM
+To: rt
+Subject: test mixed quotes
+
+test
+
+</pre>
+</blockquote>
+</div>
+
+<p>test</p>
+EOF
+        },
+        button    => 'SubmitTicket',
+    },
+    'submit TicketCreate form'
+);
+$m->text_like( qr/Ticket \d+ created in queue/, 'ticket is created' );
+$m->content_contains(<<'EOF', 'stanza output' );
+<div class="message-stanza closed"><blockquote>
+
+
+<pre>
+replied from outlook
+</pre>
+<div class="message-stanza open"><blockquote>
+<pre>
+________________________________________
+From: root <root at localhost>
+Sent: Tuesday, March 1, 2022 2:24 PM
+To: rt
+Subject: test mixed quotes
+
+test
+
+</pre>
+
+</blockquote>
+</div></blockquote></div></div>
+EOF
+
+$m->goto_create_ticket( $qid );
+$m->submit_form_ok(
+    {
+        form_name => 'TicketCreate',
+        fields    => {
+            Subject     => 'outlook plain quotes nested in html',
+            ContentType => 'text/html',
+            Content     => <<'EOF',
+This is what they typed
+<blockquote>
+This is what they replied to
+<div><br>
+-------- Forwarded Message --------
+This is the original forwarded email
+</div>
+</blockquote>
+EOF
+        },
+        button    => 'SubmitTicket',
+    },
+    'submit TicketCreate form'
+);
+$m->text_like( qr/Ticket \d+ created in queue/, 'ticket is created' );
+$m->content_contains(<<'EOF', 'stanza output' );
+<div class="message-stanza closed"><blockquote>
+
+This is what they replied to
+
+<div><br>
+</div>
+<div class="message-stanza open"><blockquote>
+<div>-------- Forwarded Message --------
+This is the original forwarded email
+</div>
+
+</blockquote>
+</div></blockquote></div><hr class="clear"></div></div>
+EOF
+
 done_testing;

commit e7beaf4932fa16c2acb624c11146acaedb201ed6
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Mar 2 05:30:29 2022 +0800

    Fix stanza for outlook plain quotes nested in html quotes
    
    When replying an email sent from outlook using CKEditor in web UI, the
    generated content is like:
    
        <div>
          On Tue Mar 01 18:29:22 2022, root wrote:
          <blockquote>
        <pre>
        replied from outlook
    
        ________________________________________
        From: root <root at localhost>
        Sent: Tuesday, March 1, 2022 2:24 PM
        To: rt
        Subject: test mixed quotes
    
        test
    
        </pre>
          </blockquote>
        </div>
    
    Previously the stanza code didn't handle above HTML correctly and
    generated the quote part like:
    
        <div class="message-stanza closed">
          <blockquote>
        <pre>
        replied from outlook
    
        <div class="message-stanza open">
        ________________________________________
        From: root <root at localhost>
        Sent: Tuesday, March 1, 2022 2:24 PM
        To: rt
        Subject: test mixed quotes
    
        test
    
        </pre>
          </blockquote>
        </div>
        </div>
    
    The inner <div>'s opening tag is put into <pre>, while its closing tag
    is put out of its ancestor <blockquote>. It confuses HTML parser and
    causes it to close a <div> ancestor un-intendedly, which breaks layout,
    sometimes badly if the snippet occurs multiple times on the page, as it
    wrongly closes more <div>s.
    
    This commit fixes the nesting issue and shows outlook quotes correctly:
    
        <div class="message-stanza closed">
          <blockquote>
        <pre>
        replied from outlook
        </pre>
            <div class="message-stanza open">
              <blockquote>
        <pre>
        ________________________________________
        From: root <root at localhost>
        Sent: Tuesday, March 1, 2022 2:24 PM
        To: rt
        Subject: test mixed quotes
    
        test
        </pre>
              </blockquote>
            </div>
          </blockquote>
        </div>
    
    Some email clients wrap with <div>(instead of <pre>), which is also covered.

diff --git a/share/html/Elements/ShowMessageStanza b/share/html/Elements/ShowMessageStanza
index 91cdd07df9..6f59056355 100644
--- a/share/html/Elements/ShowMessageStanza
+++ b/share/html/Elements/ShowMessageStanza
@@ -119,6 +119,14 @@ AGAIN: foreach ( ; $i < @$Message; $i++ ) {
                     # need to, we can process it the same way as 'raw'.
                     $preceding{raw} = substr($stanza->{raw}, 0, $start, '');
 
+                    # If it's wrapped in <pre>(ckeditor does it) or <div>(some email clients do it), we need to
+                    # complement for the split ones. Here we close <pre>/<div> for the former part. Opening a new
+                    # <pre>/<div> for the latter part is in the else block.
+
+                    if ( $preceding{raw} =~ /^<(pre|div)>/i ) {
+                        $preceding{raw} .= "</$1>";
+                    }
+
                     # Replace the current stanza with the two we just created
                     splice @$Message, $i, 1, \%preceding, $stanza;
 
@@ -129,7 +137,16 @@ AGAIN: foreach ( ; $i < @$Message; $i++ ) {
                 } else {
                     # Nest the current stanza and everything that follows
                     $stanza->{_outlooked}++;
+
+                    # Complement the <pre>/<div> for the latter part, see also the if block above.
+                    $stanza->{raw} = "<$1>" . $stanza->{raw} if $stanza->{raw} =~ m{</(pre|div)>$}i;
                     $stanza = $Message->[ $i ] = [ splice @$Message, $i ];
+
+                    # Wrap the latter part with a new blockquote if the original stanza has it. Note
+                    # that </blockquote> in "close_raw" is to close the one in the upper level(original stanza).
+                    if ( ref $Message->[0] eq 'HASH' && $Message->[0]{raw} eq '<blockquote>' ) {
+                        unshift @$stanza, { %{ $Message->[0] }, close_raw => '</blockquote>' };
+                    }
                 }
             }
             else {
@@ -158,9 +175,10 @@ AGAIN: foreach ( ; $i < @$Message; $i++ ) {
     }
 
     if (@stack) {
+        $m->out('</div>');
+        $m->out( $Message->[0]{close_raw} ) if ref $Message->[0] eq 'HASH' && $Message->[0]{close_raw};
         ( $Message, $i ) = @{ pop @stack };
         $Depth--;
-        $m->out('</div>');
         goto AGAIN;
     }
 } else {

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list