diff options
author | Jim Brandt <jbrandt@bestpractical.com> | 2022-09-02 23:54:11 +0300 |
---|---|---|
committer | Jim Brandt <jbrandt@bestpractical.com> | 2022-09-02 23:54:11 +0300 |
commit | 434a45c7a14873280474e75627b6e60755e912c5 (patch) | |
tree | 7a120473855d7e4d95d8bb6cac839fc1bb049d4c | |
parent | b2e7624961885e17f264f197142b247f5aa58f99 (diff) | |
parent | af39698745921ae47954580011dcd0b4996aba17 (diff) |
Merge branch '4.4/message-attachment-original-content' into 4.4-trunk
-rw-r--r-- | lib/RT/Attachment.pm | 10 | ||||
-rw-r--r-- | t/mail/rfc822-attachment.t | 40 |
2 files changed, 36 insertions, 14 deletions
diff --git a/lib/RT/Attachment.pm b/lib/RT/Attachment.pm index e51a9b7073..858c42907f 100644 --- a/lib/RT/Attachment.pm +++ b/lib/RT/Attachment.pm @@ -376,8 +376,14 @@ sub OriginalContent { if ($self->IsMessageContentType) { # There shouldn't be more than one "subpart" to a message/* attachment my $child = $self->Children->First; - return $self->Content unless $child and $child->id; - return $child->ContentAsMIME(Children => 1)->as_string; + if ( $child and $child->id ) { + return $child->ContentAsMIME( Children => 1 )->as_string; + } + else { + # No children could happen if $TreatAttachedEmailAsFiles is true. + # Can't indiscriminately return $self->Content as it might be decoded(for textual messages). + # Leave it to the follwing code, which covers this case. + } } return $self->Content unless RT::I18N::IsTextualContentType($self->ContentType); diff --git a/t/mail/rfc822-attachment.t b/t/mail/rfc822-attachment.t index f498ec55ae..f66584f737 100644 --- a/t/mail/rfc822-attachment.t +++ b/t/mail/rfc822-attachment.t @@ -19,21 +19,24 @@ diag "simple rfc822 attachment"; From => 'foo@localhost', To => 'bar@localhost', Subject => 'rfc822', - Data => ['rfc822 attachment'], + Data => ['rfc822 attachment 测试'], + Charset => 'UTF-8', 'X-Brokenness' => 'high', ); $top->attach( Data => $rfc822->stringify, Type => 'message/rfc822', + Charset => 'UTF-8', ); - my $parsed = content_as_mime($top); - - for my $mime ($top, $parsed) { + for my $mime ( $top, contents_as_mime($top) ) { diag "testing mail"; is $mime->parts, 2, 'two mime parts'; + eval { $mime->as_string }; + ok( !$@, 'stringifying mime does not die' ); + like $mime->head->get('Subject'), qr/this is top/, 'top subject'; like $mime->head->get('From'), qr/root\@localhost/, 'top From'; like $mime->parts(0)->bodyhandle->as_string, qr/top mail/, 'content of top'; @@ -42,7 +45,7 @@ diag "simple rfc822 attachment"; my $body = $attach->bodyhandle->as_string; like $attach->head->mime_type, qr/message\/rfc822/, 'attach of type message/rfc822'; - like $body, qr/rfc822 attachment/, 'attach content'; + like $body, qr/rfc822 attachment 测试/, 'attach content'; headers_like( $attach, @@ -67,25 +70,28 @@ diag "multipart rfc822 attachment"; From => 'foo@localhost', To => 'bar@localhost', Subject => 'rfc822', - Data => ['rfc822 attachment'], + Data => ['rfc822 attachment 测试附件'], + Charset => 'UTF-8', 'X-Brokenness' => 'high', ); $rfc822->attach( - Data => '<b>attachment of rfc822 attachment</b>', + Data => ['<b>attachment of rfc822 attachment 测试</b>'], Type => 'text/html', + Charset => 'UTF-8', ); $top->attach( Data => $rfc822->stringify, Type => 'message/rfc822', + Charset => 'UTF-8', ); - - my $parsed = content_as_mime($top); - for my $mime ($top, $parsed) { + for my $mime ( $top, contents_as_mime($top) ) { diag "testing mail"; is $mime->parts, 2, 'two mime parts'; + eval { $mime->as_string }; + ok( !$@, 'stringifying mime does not die' ); like $mime->head->get('Subject'), qr/this is top/, 'top subject'; like $mime->head->get('From'), qr/root\@localhost/, 'top From'; @@ -95,8 +101,9 @@ diag "multipart rfc822 attachment"; my $body = $attach->bodyhandle->as_string; like $attach->head->mime_type, qr/message\/rfc822/, 'attach of type message/rfc822'; - like $body, qr/rfc822 attachment/, 'attach content'; - like $body, qr/attachment of rfc822 attachment/, 'attach content'; + like $body, qr/rfc822 attachment 测试附件/, 'attach content'; + + like $body, qr/attachment of rfc822 attachment 测试/, 'attach content'; headers_like( $attach, @@ -119,6 +126,15 @@ sub content_as_mime { return RT::Test->last_ticket->Transactions->First->Attachments->First->ContentAsMIME(Children => 1); } +sub contents_as_mime { + my $entity = shift; + RT->Config->Set( 'TreatAttachedEmailAsFiles', 1 ); + my @contents = content_as_mime($entity); + RT->Config->Set( 'TreatAttachedEmailAsFiles', 0 ); + push @contents, content_as_mime($entity); + return @contents; +} + sub headers_like { my $attach = shift; my %header = (@_); |