Skip Menu |

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

Report information
The Basics
Id: 52085
Status: rejected
Priority: 0/
Queue: MIME-tools

People
Owner: Nobody in particular
Requestors: icestar [...] inbox.ru
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 5.427
Fixed in: (no value)



Subject: Encoded header glued together in one string
Hello! It seems to me there is a bug in MIME::Head module. Suppose I want to build a new MIME::Entity object and pass some encoded header fields, for example: To: =?utf-8?B?0KDQsNCx0L7RgtCwIDxkaW1hQGFkcml2ZXIucnU +LCBJY2VTdGFyIDxpY2VzdGFyQGluYm94LnJ1?= =?utf-8?B?Piwg0J/RgNC40YjQtdC70LXRhiA8YWxpZW4uY29zbW9zQGdtYWlsLmNvbT4=?= Here are two lines, the second line starts from =?utf-8?B? but when I stringify an entity all headers become single-line and not all mail clients can parse such result. RFC 2047 says: While there is no limit to the length of a multiple-line header field, each line of a header field that contains one or more 'encoded-word's is limited to 76 characters. So, is this a limitation or bug?
Subject: Re: [rt.cpan.org #52085] Encoded header glued together in one string
Date: Fri, 27 Nov 2009 12:16:49 -0500
To: bug-MIME-tools [...] rt.cpan.org
From: "David F. Skoll" <dfs [...] roaringpenguin.com>
Hi, It's a bit hard to understand your bug report. Could you please send us a small Perl program that illustrates the problem? If we can see exactly how you're building the MIME::Entity and what you expect, we can help track down the problem. Regards, David.
On Fri Nov 27 12:17:10 2009, dfs@roaringpenguin.com wrote: Show quoted text
> Hi, > > It's a bit hard to understand your bug report. Could you please > send us a small Perl program that illustrates the problem? If > we can see exactly how you're building the MIME::Entity and what > you expect, we can help track down the problem. > > Regards, > > David.
OK. Here is an example in attach. After encoding Subject field I get three encoded lines and when I stringify message I get single-line value, this is not correct.
#!/usr/bin/perl use strict; use warnings; use MIME::Entity; use MIME::Base64; use Encode qw/is_utf8/; my $subject = "Здравствуй мир! Здравствуй мир! Здравствуй мир! Здравствуй мир!"; my $from = 'Тест <dima@adriver.ru>'; my $to = 'Тест2 <testxml@adriver.ru>'; my $body = 'Тело письма'; my $charset = 'utf-8'; $subject = encode_mimeheader($subject, 'utf-8'); print "SUBJECT: '$subject'\n"; ### Create an entity: my $top = MIME::Entity->build( From => encode_mimeheader($from, $charset), To => encode_mimeheader($to, $charset), Subject => encode_mimeheader($subject, $charset), Charset => $charset, Type => "text/plain", Data => $body ); my $message = $top->stringify; print "MESSAGE: '$message'\n"; exit 0; sub encode_mimeheader { my ($string, $charset) = @_; # convert to byte string because encode_base64 do not accept utf8 (multibyte character) my $s = is_utf8($string) ? encode_utf8($string) : $string; my $result = encode_base64($s); $result =~ s/^(.*)$/=?$charset?B?$1?=/mg; return $result; }
Subject: Re: [rt.cpan.org #52085] Encoded header glued together in one string
Date: Thu, 31 Dec 2009 13:56:35 -0500
To: Dmitry Bigunyak via RT <bug-MIME-tools [...] rt.cpan.org>
From: "Dave O'Neill" <dmo [...] roaringpenguin.com>
On Thu, Dec 03, 2009 at 05:53:52AM -0500, Dmitry Bigunyak via RT wrote: Show quoted text
> OK. Here is an example in attach. > After encoding Subject field I get three encoded lines and when I > stringify message I get single-line value, this is not correct.
You should probably be using encode_mimewords() from the MIME::Words module instead. use MIME::Words qw( encode_mimewords ); $subject = encode_mimewords($subject, Encoding => 'B', 'Charset' => 'utf8'); (the "Encoding => 'B'" argument specifies Base-64 encoding, otherwise you'll get Quoted-Printable). Changing your example to use this instead of your encode_mimeheader() doesn't present the same problems with spaces in the header. Cheers, Dave
Not a bug