diff options
author | sunnavy <sunnavy@bestpractical.com> | 2022-09-02 21:57:59 +0300 |
---|---|---|
committer | sunnavy <sunnavy@bestpractical.com> | 2022-09-02 23:33:39 +0300 |
commit | af39698745921ae47954580011dcd0b4996aba17 (patch) | |
tree | 7a120473855d7e4d95d8bb6cac839fc1bb049d4c | |
parent | b122dc266a479197d96a8b3b34adfd60232e0777 (diff) |
Test textual and UTF-8 encoded "message/..." attachments
It covers both cases where $TreatAttachedEmailAsFiles is true or false.
-rw-r--r-- | t/mail/rfc822-attachment.t | 40 |
1 files changed, 28 insertions, 12 deletions
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 = (@_); |