4 use RT::Test tests => undef;
8 diag "simple rfc822 attachment";
11 my $top = MIME::Entity->build(
12 From => 'root@localhost',
14 Subject => 'this is top',
18 my $rfc822 = MIME::Entity->build(
19 From => 'foo@localhost',
20 To => 'bar@localhost',
22 Data => ['rfc822 attachment'],
23 'X-Brokenness' => 'high',
27 Data => $rfc822->stringify,
28 Type => 'message/rfc822',
31 my $parsed = content_as_mime($top);
33 for my $mime ($top, $parsed) {
35 is $mime->parts, 2, 'two mime parts';
37 like $mime->head->get('Subject'), qr/this is top/, 'top subject';
38 like $mime->head->get('From'), qr/root\@localhost/, 'top From';
39 like $mime->parts(0)->bodyhandle->as_string, qr/top mail/, 'content of top';
41 my $attach = $mime->parts(1);
42 my $body = $attach->bodyhandle->as_string;
44 like $attach->head->mime_type, qr/message\/rfc822/, 'attach of type message/rfc822';
45 like $body, qr/rfc822 attachment/, 'attach content';
50 From => 'foo@localhost',
51 'X-Brokenness' => 'high',
56 diag "multipart rfc822 attachment";
59 my $top = MIME::Entity->build(
60 From => 'root@localhost',
62 Subject => 'this is top',
66 my $rfc822 = MIME::Entity->build(
67 From => 'foo@localhost',
68 To => 'bar@localhost',
70 Data => ['rfc822 attachment'],
71 'X-Brokenness' => 'high',
75 Data => '<b>attachment of rfc822 attachment</b>',
80 Data => $rfc822->stringify,
81 Type => 'message/rfc822',
84 my $parsed = content_as_mime($top);
86 for my $mime ($top, $parsed) {
88 is $mime->parts, 2, 'two mime parts';
90 like $mime->head->get('Subject'), qr/this is top/, 'top subject';
91 like $mime->head->get('From'), qr/root\@localhost/, 'top From';
92 like $mime->parts(0)->bodyhandle->as_string, qr/top mail/, 'content of top';
94 my $attach = $mime->parts(1);
95 my $body = $attach->bodyhandle->as_string;
97 like $attach->head->mime_type, qr/message\/rfc822/, 'attach of type message/rfc822';
98 like $body, qr/rfc822 attachment/, 'attach content';
99 like $body, qr/attachment of rfc822 attachment/, 'attach content';
104 From => 'foo@localhost',
105 'X-Brokenness' => 'high',
106 'Content-Type' => 'text/plain',
107 'Content-type' => 'text/html',
112 sub content_as_mime {
114 my ( $status, $id ) = RT::Test->send_via_mailgate($entity);
115 is( $status >> 8, 0, "The mail gateway exited normally" );
116 ok( $id, "created ticket" );
117 # We can't simply use Txn->ContentAsMIME since that is wrapped in a
118 # message/rfc822 entity
119 return RT::Test->last_ticket->Transactions->First->Attachments->First->ContentAsMIME(Children => 1);
125 my $body = $attach->bodyhandle->as_string;
126 for my $name (keys %header) {
127 if (lc $name eq 'content-type') {
128 like $attach->head->get($name), qr/message\/rfc822/, "attach $name message/rfc822, not from a subpart";
130 is $attach->head->get($name), undef, "attach $name not in part header";
132 like $body, qr/$name: $header{$name}/i, "attach $name in part body";