Skip Menu |

This queue is for tickets about the MIME-tools CPAN distribution.

Report information
The Basics
Id: 98737
Status: resolved
Priority: 0/
Queue: MIME-tools

People
Owner: dfs+pause [...] roaringpenguin.com
Requestors: Mark.Martinec [...] ijs.si
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 5.505
Fixed in: (no value)



Subject: Lift encoding restriction according to RFC 6533: can't have encoding quoted-printable for message type message/global-headers
Trying to update my software to generate a DSN according to RFC 6533 (Internationalized Delivery Status and Disposition Notifications), I stumbled across the following diagnostic from MIME-Tools-5.505: can't have encoding quoted-printable for message type message/global-headers! This is generated by the following code in MIME::Entity::build() : ### Type-check sanity: if ($type =~ m{^(multipart|message)/}) { ($encoding =~ /^(|7bit|8bit|binary|-suggest)$/i) or croak "can't have encoding $encoding for message type $type!"; } The restriction above needs to be relaxed, the RFC 2045 requirements were relaxed by RFC 6532: RFC 2045 section 6.4 If an entity is of type "multipart" the Content-Transfer-Encoding is not permitted to have any value other than "7bit", "8bit" or "binary". [...] Certain Content-Transfer-Encoding values may only be used on certain media types. In particular, it is EXPRESSLY FORBIDDEN to use any encodings other than "7bit", "8bit", or "binary" with any composite media type, i.e. one that recursively includes other Content-Type fields. Currently the only composite media types are "multipart" and "message". All encodings that are desired for bodies of type multipart or message must be done at the innermost level, by encoding the actual body that needs to be encoded. RFC 6532: 3.5. Changes to MIME Message Type Encoding Restrictions This specification updates Section 6.4 of [RFC2045]. [RFC2045] prohibits applying a content-transfer-encoding to any subtypes of "message/". This specification relaxes that rule -- it allows newly defined MIME types to permit content-transfer-encoding, and it allows content-transfer-encoding for message/global (see Section 3.7). 3.7. The message/global Media Type [...] If an object of this type is sent to a 7-bit-only system, it MUST have an appropriate content-transfer-encoding applied. (Note that a system compliant with MIME that doesn't recognize message/global is supposed to treat it as "application/octet-stream" as described in Section 5.2.4 of [RFC2046].) [...] Encoding considerations: Any content-transfer-encoding is permitted. The 8-bit or binary content-transfer-encodings are recommended where permitted. [...] Restrictions on usage: This is a structured media type that embeds other MIME media types. An 8-bit or binary content-transfer-encoding SHOULD be used unless this media type is sent over a 7-bit-only transport. RFC 6533: Note that [RFC6532] relaxed a restriction from MIME [RFC2046] regarding the use of Content-Transfer-Encoding in new "message" subtypes. This specification explicitly allows the use of Content-Transfer-Encoding in message/global-headers and message/global-delivery-status. RFC 6533: 4.5. Additional Requirements on SMTP Servers If an SMTP server that advertises both SMTPUTF8 and DSN needs to return an undeliverable SMTPUTF8 message, then it has two choices for encapsulating the SMTPUTF8 message when generating the corresponding multipart/report: If the return-path SMTP server does not support SMTPUTF8, then the undeliverable body part and headers MUST be encoded using a 7-bit Content-Transfer-Encoding such as "base64" or "quoted-printable" [RFC2045], as detailed in Section 4. Otherwise, "8bit" Content-Transfer-Encoding can be used.
Subject: Re: [rt.cpan.org #98737] Lift encoding restriction according to RFC 6533: can't have encoding quoted-printable for message type message/global-headers
Date: Wed, 10 Sep 2014 13:27:07 -0400
To: bug-MIME-tools [...] rt.cpan.org
From: "David F. Skoll" <dfs [...] roaringpenguin.com>
Hi, Show quoted text
> The restriction above needs to be relaxed, > the RFC 2045 requirements were relaxed by RFC 6532:
Thanks for the bug report. I plan on applying the patch below for the next release. From my understanding, RFC 6532 only relaxes the restriction for new subtypes of message/, so I keep it in place for old subtypes. Your review would be appreciated. Regards, David. diff --git a/lib/MIME/Entity.pm b/lib/MIME/Entity.pm index 37d0de4..9ea4ddd 100644 --- a/lib/MIME/Entity.pm +++ b/lib/MIME/Entity.pm @@ -570,7 +570,7 @@ sub build { $filename = undef if (defined($filename) and $filename eq ''); ### Type-check sanity: - if ($type =~ m{^(multipart|message)/}) { + if ($type =~ m{^(multipart/|message/(rfc822|partial|external-body|delivery-status|disposition-notification|feedback-report))}) { ($encoding =~ /^(|7bit|8bit|binary|-suggest)$/i) or croak "can't have encoding $encoding for message type $type!"; } diff --git a/t/Entity.t b/t/Entity.t index 2ef11e2..440c931 100644 --- a/t/Entity.t +++ b/t/Entity.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; use warnings; -use Test::More tests => 34; +use Test::More tests => 39; use MIME::Entity; use MIME::Parser; @@ -101,6 +101,45 @@ my $LINE; my $got = $e->head->mime_attr('content-type.charset'); is($got, 'iso8859-1', 'Charset: explicit'); } + + { + #-----test------ + my $croaked = 1; + eval { + my $e = MIME::Entity->build(Type => 'message/rfc822', + Encoding => 'base64', + Data => "Subject: phooey\n\nBlat\n"); + $croaked = 0; + }; + ok($croaked, 'MIME::Entity->build croaked on message/rfc822 with base64 encoding'); + ok($@ =~ /can't have encoding base64 for message type message\/rfc822/, + 'and it croaked with expected error.'); + } + + { + #-----test------ + my $croaked = 1; + eval { + my $e = MIME::Entity->build(Type => 'message/global', + Encoding => 'base64', + Data => "Subject: phooey\n\nBlat\n"); + $croaked = 0; + }; + ok(!$croaked, 'MIME::Entity->build did not croak on message/global with base64 encoding'); + } + { + #-----test------ + my $croaked = 1; + eval { + my $e = MIME::Entity->build(Type => 'multipart/alternative', + Encoding => 'base64', + Data => "Subject: phooey\n\nBlat\n"); + $croaked = 0; + }; + ok($croaked, 'MIME::Entity->build croaked on multipart/alternative with base64 encoding'); + ok($@ =~ /can't have encoding base64 for message type multipart\/alternative/, + 'and it croaked with expected error.'); + } } #diag("Create an entity");
From: Mark.Martinec [...] ijs.si
Thanks for a quick response. Show quoted text
> I plan on applying the patch below for the next > release. From my understanding, RFC 6532 only relaxes > the restriction for new subtypes of message/, so I keep > it in place for old subtypes.
Right, it doesn't relax it for old types. On a careful reading, seems to me that it also does not relax it automatically for any future subtype, but offers new documents that introduce such new subtype a freedom to explicitly permit encodings, should they choose so. ... which is not something that can possibly be coded into present programs that will need to cope with potential future subtypes defined after a program release, so some compromise seems to be necessary. Show quoted text
> - if ($type =~ m{^(multipart|message)/}) { > + if ($type =~ m{^(multipart/|message/(rfc822|partial|
external-body|delivery-status|disposition-notification|feedback-report))}) { Yes, something like that. Some boundary or delimiter or a \z at the end of a regexp to stay on the safe side? Is the $type guaranteed to be in lowercase? Hope the RFC 5965 (message/feedback-report) doesn't change its mind when it realizes that an Original-Rcpt-To field may contain an UTF-8 string :)
Subject: Re: [rt.cpan.org #98737] Lift encoding restriction according to RFC 6533: can't have encoding quoted-printable for message type message/global-headers
Date: Thu, 11 Sep 2014 10:01:51 -0400
To: bug-MIME-tools [...] rt.cpan.org
From: "David F. Skoll" <dfs [...] roaringpenguin.com>
On Wed, 10 Sep 2014 19:33:06 -0400 "Mark.Martinec@ijs.si via RT" <bug-MIME-tools@rt.cpan.org> wrote: Show quoted text
> Yes, something like that. Some boundary or delimiter or > a \z at the end of a regexp to stay on the safe side?
Yes, good point. Show quoted text
> Is the $type guaranteed to be in lowercase?
No, because it's passed in by the user. So below is an updated patch. Regards, David. diff --git a/lib/MIME/Entity.pm b/lib/MIME/Entity.pm index 37d0de4..fd09008 100644 --- a/lib/MIME/Entity.pm +++ b/lib/MIME/Entity.pm @@ -570,7 +570,7 @@ sub build { $filename = undef if (defined($filename) and $filename eq ''); ### Type-check sanity: - if ($type =~ m{^(multipart|message)/}) { + if ($type =~ m{^(multipart/|message/(rfc822|partial|external-body|delivery-status|disposition-notification|feedback-report$))}i) { ($encoding =~ /^(|7bit|8bit|binary|-suggest)$/i) or croak "can't have encoding $encoding for message type $type!"; } diff --git a/t/Entity.t b/t/Entity.t index 2ef11e2..421af5d 100644 --- a/t/Entity.t +++ b/t/Entity.t @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; use warnings; -use Test::More tests => 34; +use Test::More tests => 39; use MIME::Entity; use MIME::Parser; @@ -101,6 +101,45 @@ my $LINE; my $got = $e->head->mime_attr('content-type.charset'); is($got, 'iso8859-1', 'Charset: explicit'); } + + { + #-----test------ + my $croaked = 1; + eval { + my $e = MIME::Entity->build(Type => 'message/rfc822', + Encoding => 'base64', + Data => "Subject: phooey\n\nBlat\n"); + $croaked = 0; + }; + ok($croaked, 'MIME::Entity->build croaked on message/rfc822 with base64 encoding'); + ok($@ =~ /can't have encoding base64 for message type message\/rfc822/, + 'and it croaked with expected error.'); + } + + { + #-----test------ + my $croaked = 1; + eval { + my $e = MIME::Entity->build(Type => 'message/global', + Encoding => 'base64', + Data => "Subject: phooey\n\nBlat\n"); + $croaked = 0; + }; + ok(!$croaked, 'MIME::Entity->build did not croak on message/global with base64 encoding'); + } + { + #-----test------ + my $croaked = 1; + eval { + my $e = MIME::Entity->build(Type => 'multipart/ALTERNATIVE', + Encoding => 'base64', + Data => "Subject: phooey\n\nBlat\n"); + $croaked = 0; + }; + ok($croaked, 'MIME::Entity->build croaked on multipart/alternative with base64 encoding'); + ok($@ =~ /can't have encoding base64 for message type multipart\/ALTERNATIVE/, + 'and it croaked with expected error.'); + } } #diag("Create an entity");
Subject: Re: [rt.cpan.org #98737] Lift encoding restriction according to RFC 6533: can't have encoding quoted-printable for message type message/global-headers
Date: Thu, 11 Sep 2014 10:04:48 -0400
To: bug-MIME-tools [...] rt.cpan.org
From: "David F. Skoll" <dfs [...] roaringpenguin.com>
Ugh! Bad patch The proper regex line should be: if ($type =~ m{^(multipart/|message/(rfc822|partial|external-body|delivery-status|disposition-notification|feedback-report)$)}i) { I had the $ in the wrong place. :( Regards, David.
Subject: Re: [rt.cpan.org #98737] Lift encoding restriction according to RFC 6533: can't have encoding quoted-printable for message type message/global-headers
Date: Thu, 11 Sep 2014 16:32:54 +0200
To: bug-MIME-tools [...] rt.cpan.org
From: Mark Martinec <Mark.Martinec [...] ijs.si>
Show quoted text
> Ugh! Bad patch > I had the $ in the wrong place. :(
Looks good now, thanks!
Hi, Although I forgot to mention it in the changelog, this bug is fixed in the 5.506 release that I just uploaded. Regards, Dianne.