[Rt-commit] rt branch, 4.4/gpg-skip-broken-html, created. rt-4.4.3-53-g877abee2e
? sunnavy
sunnavy at bestpractical.com
Wed Oct 3 17:08:12 EDT 2018
The branch, 4.4/gpg-skip-broken-html has been created
at 877abee2ee32a488dbbd1b7e96de6be57df3658e (commit)
- Log -----------------------------------------------------------------
commit 06b6d451907c9e3dc198e10830de55729d958931
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Oct 4 04:27:32 2018 +0800
Skip broken html that wraps gpg encrypted message
Some emails might contain weirdly partial gpg encrypted message in the
html part, e.g.
<html><div>Encrypted Message</div></html>
It's just a wrapping of plain encrypted message and is invalid. For
cases like that, this commit skips html part and uses the plain
alternative part instead.
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 9f897c307..5759d7c16 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -595,6 +595,20 @@ sub _FindPreferredContentObj {
# If we actully found a part, return its content
if ( my $first = $plain_parts->First ) {
+ if ( $args{Type} eq 'text/html'
+ && RT->Config->Get( 'GnuPG' )
+ && RT->Config->Get( 'GnuPG' )->{Enable}
+ && $Attachment->ContentType eq 'multipart/alternative'
+ && $first->Content =~ m{-----BEGIN PGP MESSAGE-----.+-----END PGP MESSAGE-----}s )
+ {
+ my $siblings = $first->Siblings;
+ $siblings->ContentType( VALUE => 'text/plain' );
+ $siblings->LimitNotEmpty;
+ if ( my $plain_attachment = $siblings->First ) {
+ RT->Logger->debug( "Found partially encrypted html, switching to alternative plain part." );
+ return $plain_attachment;
+ }
+ }
return $first;
}
} else {
diff --git a/share/html/Elements/ShowTransactionAttachments b/share/html/Elements/ShowTransactionAttachments
index d1c77dfdb..71fe125ca 100644
--- a/share/html/Elements/ShowTransactionAttachments
+++ b/share/html/Elements/ShowTransactionAttachments
@@ -159,8 +159,38 @@ my $render_attachment = sub {
return;
}
- if (
+ my $force_display;
+ if ( RT->Config->Get( 'GnuPG' )
+ && RT->Config->Get( 'GnuPG' )->{Enable}
+ && $ParentObj
+ && $ParentObj->ContentType eq 'multipart/alternative'
+ && RT->Config->Get( 'PreferRichText', $session{CurrentUser} ) )
+ {
+
+ my $siblings = $message->Siblings;
+ if ( $message->ContentType eq 'text/plain' ) {
+ $siblings->ContentType( VALUE => 'text/html' );
+ $siblings->LimitNotEmpty;
+ if ( my $html_message = $siblings->Next ) {
+ if ( $html_message->Content =~ m{-----BEGIN PGP MESSAGE-----.+-----END PGP MESSAGE-----}s ) {
+ $force_display = 1;
+ }
+ }
+ }
+ elsif ( $message->ContentType eq 'text/html' ) {
+ if ( $message->Content =~ m{-----BEGIN PGP MESSAGE-----.+-----END PGP MESSAGE-----}s ) {
+ $siblings->ContentType( VALUE => 'text/plain' );
+ $siblings->LimitNotEmpty;
+ if ( $siblings->Count ) {
+ RT->Logger->debug( "Found partially undecrypted html, switching to alternative plain part." );
+ return;
+ }
+ }
+ }
+ }
+ if (
+ $force_display ||
# it's a toplevel object
!$ParentObj
commit 877abee2ee32a488dbbd1b7e96de6be57df3658e
Author: sunnavy <sunnavy at bestpractical.com>
Date: Thu Oct 4 04:42:19 2018 +0800
Test broken html that wraps gpg encrypted message
diff --git a/t/data/gnupg/emails/special/broken-html.txt b/t/data/gnupg/emails/special/broken-html.txt
new file mode 100644
index 000000000..2c9f84ddc
--- /dev/null
+++ b/t/data/gnupg/emails/special/broken-html.txt
@@ -0,0 +1,44 @@
+From: root at localhost
+Content-Type: multipart/alternative; boundary="=-MRyJofprf2aLkeAxMXTv"
+Subject: test broken html
+
+--=-MRyJofprf2aLkeAxMXTv
+Content-Type: text/plain; charset="UTF-8"
+
+-----BEGIN PGP MESSAGE-----
+
+hQIOA076g5OuwfIOEAgAv9bYyAJKVmQ4p/LStq1pvnKzdvS//bLyMSgvGzNB1o9q
+wNl0k6KdkXCbbkaOOu0CBl64gTxNuXPUdAyCXl/ojWfXUR/b6R+0mEyPFd7TYpu5
+mJmHv62kIlR/QoUdBvHEwA2+vlvOqX4U0VuVwGh8d7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52CGn/HxEosiCn3LuxEIuyzzgeHIZNwt/Qy52cx91g9E4CCKp8
+thfebaml+asNmp+xGtizHq9Uxkj7KQpueD3xrhSV3Af+JAUhOtCH2Wkp3z5LI5s9
+0tyT/3p65GEoiwnsK6TT0NfkgRcGS1HdgLUDsFXOZubUTrZ/Gvbbdjmkk0DVpCEI
+D0Vuy07sfBa60lYYNGqIwAC3gJvX39cFJSTqKCI9+FMqkFLjdlnaD7hSNE3oFqRt
+nK6xzQ29H7PRiwm9WxQy/IvSEfiYFe4P+TuyRlVteY10K9V6PuM9G9N41rwtW44M
+QmHyf7SA0lWMiiKwGxbDGf0LjyJ7jpZYSy9nsIeFhczVZdFJ2yvVPczlbuokbaSZ
+03tz6r4XppdNO3CFuUu+t0HYAi23byHjuMdfutFr+J0PZeCIvLTqtAIlt+iYvC5s
+MdJaAYEkD9pC59khxzVUXEJrzcSlstUQbdJttP+j51oHLTLhmzjXudEY5WqcO7mk
+9W9lMl+4ZYWUYDDJi/Vx1KjcO/SUA1ttkcx6JNxXa5hatoX4ZM9d25FnoIwH
+=THDc
+-----END PGP MESSAGE-----
+</body></html>
diff --git a/t/mail/gnupg-special.t b/t/mail/gnupg-special.t
index 15aad3489..c8a41acb3 100644
--- a/t/mail/gnupg-special.t
+++ b/t/mail/gnupg-special.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use RT::Test::GnuPG tests => 25, gnupg_options => { passphrase => 'rt-test' };
+use RT::Test::GnuPG tests => undef, gnupg_options => { passphrase => 'rt-test' };
use Digest::MD5 qw(md5_hex);
@@ -86,6 +86,24 @@ $user->SetEmailAddress('recipient at example.com');
is(md5_hex($bin->Content), '1e35f1aa90c98ca2bab85c26ae3e1ba7', "correct png");
}
+{
+ my $id = send_via_mailgate('broken-html.txt');
+
+ my $tick = RT::Ticket->new( $RT::SystemUser );
+ $tick->Load( $id );
+ ok ($tick->id, "loaded ticket #$id");
+
+ my $txn = $tick->Transactions->First;
+ my $parts = $txn->Attachments->ItemsArrayRef;
+
+ is (scalar @$parts, 4, 'alternative, text, html and original');
+ like( $txn->Content, qr/This is decrypted plain content/, 'got decrypted content' );
+ unlike( $txn->Content, qr/BEGIN PGP MESSAGE/, 'no undecrypted content' );
+ $m->goto_ticket($tick->id);
+ $m->text_contains('This is decrypted plain content', 'got decrypted content on the page');
+ $m->text_lacks('BEGIN PGP MESSAGE', 'no undecrypted content on the page');
+}
+
sub send_via_mailgate {
my $fname = shift;
my $emaildatadir = RT::Test::get_relocatable_dir(File::Spec->updir(),
@@ -99,3 +117,4 @@ sub send_via_mailgate {
return $id;
}
+done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list