[Rt-commit] rt branch, 4.4/require-han-extra-in-attachment-encoded-headers, created. rt-4.4.3-115-g6da469b84f
? sunnavy
sunnavy at bestpractical.com
Fri Dec 14 15:54:53 EST 2018
The branch, 4.4/require-han-extra-in-attachment-encoded-headers has been created
at 6da469b84f9d556ed1aacba7e39e1fbd0c081bf5 (commit)
- Log -----------------------------------------------------------------
commit 80c77a13f7055b2f03933a098a3027bbad09417a
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat May 12 04:45:56 2018 +0800
Require Encode::HanExtra in RT::Attachment::EncodedHeaders when necessary
Otherwise Encode::encode dies when encountering encodings like "gb18030":
Unknown encoding 'gb18030'
diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm
index 5708e31428..dc89a7eeaa 100644
--- a/lib/RT/Attachment.pm
+++ b/lib/RT/Attachment.pm
@@ -637,6 +637,14 @@ This is not protection using quoted printable or base64 encoding.
sub EncodedHeaders {
my $self = shift;
my $encoding = shift || 'utf8';
+
+ # Require Encode::HanExtra to handle more encodings it supports.
+ # The regex is based on the names documented in Encode::HanExtra.
+ if ( $encoding =~ /^(?:big5(?:-1984|-2003|ext|plus)|cccii|cns11643-[1-7f]|euc-tw|gb18030|unisys(?:-sosi(?:1|2))?)$/ ) {
+ unless ( Encode::HanExtra->require ) {
+ RT->Logger->error("Need Encode::HanExtra to handle $encoding");
+ }
+ }
return Encode::encode( $encoding, $self->Headers );
}
commit 6da469b84f9d556ed1aacba7e39e1fbd0c081bf5
Author: sunnavy <sunnavy at bestpractical.com>
Date: Sat May 12 06:08:19 2018 +0800
Test RT::Attachment::EncodedHeaders with gb18030
diff --git a/t/data/emails/new-ticket-from-gb18030 b/t/data/emails/new-ticket-from-gb18030
new file mode 100644
index 0000000000..02257cd1ef
--- /dev/null
+++ b/t/data/emails/new-ticket-from-gb18030
@@ -0,0 +1,10 @@
+Content-Type: text/plain; charset="gb18030"
+Content-Disposition: inline
+Content-Transfer-Encoding: base64
+MIME-Version: 1.0
+X-Mailer: MIME-tools 5.505 (Entity 5.505)
+From: root at localhost
+Subject: =?gb18030?B?suLK1A===?=
+
+suLK1A==
+
diff --git a/t/mail/han-encodings.t b/t/mail/han-encodings.t
new file mode 100644
index 0000000000..ba1acc0cd4
--- /dev/null
+++ b/t/mail/han-encodings.t
@@ -0,0 +1,32 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef, actual_server => 1;
+
+# we can't simply call Encode::HanExtra->require here because we are testing
+# if Encode::HanExtra could be automatically loaded.
+plan skip_all => 'Encode::HanExtra required' if system $^X, '-MEncode::HanExtra', '-e1';
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+
+{
+ my $gb18030_ticket_email =
+ RT::Test::get_relocatable_file( 'new-ticket-from-gb18030', ( File::Spec->updir(), 'data', 'emails' ) );
+ my $content = RT::Test->file_content( $gb18030_ticket_email );
+
+ my ( $status, $id ) = RT::Test->send_via_mailgate_and_http( $content );
+ is( $status >> 8, 0, "The mail gateway exited normally" );
+ ok( $id, "Created ticket" );
+
+ my $ticket = RT::Ticket->new( RT->SystemUser );
+ $ticket->Load( $id );
+ ok( $ticket->id, 'loaded ticket' );
+
+ my $txns = $ticket->Transactions;
+ $txns->Limit( FIELD => 'Type', VALUE => 'Create' );
+ my $attachment = $txns->First->Attachments->First;
+ my $encode_headers = $attachment->EncodedHeaders( 'gb18030' );
+ is( $encode_headers, Encode::encode( 'gb18030', $attachment->Headers ) );
+}
+
+done_testing;
-----------------------------------------------------------------------
More information about the rt-commit
mailing list