Discussion:
[Mimedefang] Problem with MIME::Tools and base64 encoded message/rfc822 attachements
Franz Schwartau
2015-07-27 22:35:52 UTC
Permalink
Dear list,

I'd like to use MIME::Tools for parsing a base64 encoded attachement of
an e-mail.

Please have a look at the attached tar.

If using the test script parse.pl with a base64 encoded test
attachement, ME_Parts isn't filled properly:

./parse.pl mail2-b64.eml
[...]
'ME_Parts' => [
bless( {
'ME_Bodyhandle' => bless( {

'MB_Path' => '/tmp/parser/msg-1438036387-58191-0/msg-58191-2.txt'
},
'MIME::Body::File' ),
'mail_inet_head' => bless( {

'mail_hdr_list' => [],

'mail_hdr_hash' => {},

'mail_hdr_foldlen' => 79,

'mail_hdr_modify' => 0,

'mail_hdr_lengths' => {},

'mail_hdr_mail_from' => 'KEEP'
},
'MIME::Head' ),
'ME_Parts' => []
}, 'MIME::Entity' )
],
[...]

It works with a 7bit attachement, though:

./parse.pl mail2-7bit.eml
[...]
'ME_Parts' => [
bless( {
'ME_Bodyhandle' => bless( {

'MB_Path' => '/tmp/parser/msg-1438036447-58356-0/msg-58356-2.txt'
},
'MIME::Body::File' ),
'ME_Parts' => [],
'mail_inet_head' => bless( {

'mail_hdr_foldlen' => 79,

'mail_hdr_hash' => {

'Subject' => [

\'Subject: This is just a test
'

],

'Date' => [

\'Date: Mon, 27 Jul 2015 23:56:46 +0200
'

],

'From' => [

\'From: ***@test.com
'

],

'To' => [

\'To: ***@test.com
'

]

},

'mail_hdr_mail_from' => 'KEEP',

'mail_hdr_lengths' => {},

'mail_hdr_list' => [


${$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}{'mail_hdr_hash'}{'From'}[0]},


${$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}{'mail_hdr_hash'}{'To'}[0]},


${$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}{'mail_hdr_hash'}{'Date'}[0]},


${$VAR1->{'ME_Parts'}[0]{'mail_inet_head'}{'mail_hdr_hash'}{'Subject'}[0]}

],

'mail_hdr_modify' => 0
},
'MIME::Head' )
}, 'MIME::Entity' )
],
[...]

Why doesn't it work with a base64 encoded attachement?

Best regards
Franz
Dianne Skoll
2015-07-28 03:03:43 UTC
Permalink
On Tue, 28 Jul 2015 00:35:52 +0200
Post by Franz Schwartau
Why doesn't it work with a base64 encoded attachement?
RFC 2046, section 5.2.1: https://tools.ietf.org/html/rfc2046#section-5.2.1

No encoding other than "7bit", "8bit", or "binary" is permitted for
the body of a "message/rfc822" entity.

So the answer is in the RFC: You're not allowed to use base64 encoding
for a message/rfc822 attachment.

Regards,

Dianne.
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
Faraz Vahabzadeh
2015-07-28 03:39:46 UTC
Permalink
Dianne is correct!

I guess the sample file is not a good one. Either the Content-Type has
to change to "text/plain" or if you are really dealing with such badly
constructed messages in real life then as the man page for Mime::Parser
suggests just turn off nested message extraction ($parser->extract_nested_messages(0);)
which treats that particular mime part as "text/plain".

And adding MIME::Tools->debugging(1); can help a lot debugging your
program.

Cheers,
--fzv
Post by Dianne Skoll
On Tue, 28 Jul 2015 00:35:52 +0200
Post by Franz Schwartau
Why doesn't it work with a base64 encoded attachement?
RFC 2046, section 5.2.1: https://tools.ietf.org/html/rfc2046#section-5.2.1
No encoding other than "7bit", "8bit", or "binary" is permitted for
the body of a "message/rfc822" entity.
So the answer is in the RFC: You're not allowed to use base64 encoding
for a message/rfc822 attachment.
Regards,
Dianne.
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

Loading...