I'm trying to use Email::MIME to convert a plain email (not MIME) to a
MIME multipart mail. According to the manual I can use the parts_set
method for this purpose because it'll convert a plain email to multipart
if necessary.

So I add the original body as part 1 and a random second part as follows:

$email = Email::MIME->new(<STDIN>);

my $part1 = Email::MIME->create(
    attributes => { content_type => "text/plain" },
    body => $email->body);
my $part2 = Email::MIME->create(
    attributes => { content_type => "text/plain" },
    body => 'part 2');

$email->parts_set([ $part1, $part2 ]);

print $email->as_string();

Now what this does is not exactly as I expected. The result is indeed a
multipart email with both parts. However looking closely I noticed that
each part has both a Date and a MIME-Version header. Those I did not
expect. Moreover I also noticed that the email headers are appended by a
"Content-Type: multipart/mixed" header, but not with a MIME-Version
header. So I have two MIME-Version headers instead of one, but neither
are in the right place.

Now I can understand this to some degree, since I use
Email::MIME->create() to create the parts. The documentation of create()
does specify that a Date-header will be added, since it's mandatory (at
least, within the context of an email itself). So even though methods
like parts() do return the parts as Email::MIME instances, apparently
the create() method is not the right way to create a simple part,
without automatically creating headers that are only relevant for the
email itself.

So... how does one create simple parts? Or if this is not the way at
all: how does one convert a non-MIME email to MIME multipart?

Kind regards,


Reply via email to