forked from rjbs/Email-MIME
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multipart messages without content-type in subparts. (GH: rjb…
…s#14) Per RFC 1341, section 7.2 https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html A body part is NOT to be interpreted as actually being an RFC 822 message. To begin with, NO header fields are actually required in body parts. A body part that starts with a blank line, therefore, is allowed and is a body part for which all default values are to be assumed. In such a case, the absence of a Content-Type header field implies that the encapsulation is plain US-ASCII text.
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,17 @@ use Test::More; | |
use Carp; $SIG{__WARN__} = sub { Carp::cluck @_ }; | ||
|
||
use_ok 'Email::MIME::Creator'; | ||
use_ok 'Email::MIME::ContentType'; | ||
|
||
sub ct { | ||
return ( | ||
type => $_[0], # okay! | ||
subtype => $_[1], # okay! | ||
|
||
discrete => $_[0], # dumb! | ||
composite => $_[1], # dumb! | ||
); | ||
} | ||
|
||
my $hi = Email::MIME->create(body => "Hi"); | ||
my $hello = Email::MIME->create(body => "Hello"); | ||
|
@@ -89,4 +100,48 @@ END | |
unlike($email->as_string, qr/Postlude/, "postlude in string"); | ||
} | ||
|
||
{ | ||
my $email = Email::MIME->new(<<'END'); | ||
From: Test <[email protected]> | ||
To: Test <[email protected]> | ||
Subject: Test | ||
Content-Type: multipart/alternative; boundary=90e6ba6e8d06f1723604fc1b809a | ||
--90e6ba6e8d06f1723604fc1b809a | ||
Content-Type: text/plain; charset=UTF-8 | ||
Part 1 | ||
Part 1a | ||
--90e6ba6e8d06f1723604fc1b809a | ||
Part 2 | ||
Part 2a | ||
--90e6ba6e8d06f1723604fc1b809a-- | ||
END | ||
|
||
my @parts = $email->subparts; | ||
|
||
is(@parts, 2, 'got 2 parts'); | ||
|
||
like($parts[0]->body, qr/^Part 1.*Part 1a$/s, 'Part 1 looks right'); | ||
is_deeply( parse_content_type($parts[0]->header('Content-Type')), { | ||
ct(qw(text plain)), | ||
attributes => { | ||
charset => 'UTF-8', | ||
}, | ||
}, 'explicit ct worked' ); | ||
|
||
like($parts[1]->body, qr/^Part 2.*Part 2a$/s, 'Part 2 looks right'); | ||
is_deeply( parse_content_type($parts[1]->header('Content-Type')), { | ||
ct(qw(text plain)), | ||
attributes => { | ||
charset => 'us-ascii', | ||
}, | ||
}, 'default ct worked' ); | ||
} | ||
|
||
done_testing; |