Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Email-Simple CPAN distribution.

Report information
The Basics
Id: 24922
Status: resolved
Priority: 0/
Queue: Email-Simple

People
Owner: Nobody in particular
Requestors: barry [...] bquotes.com
Cc:
AdminCc:

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



Subject: extra CRLF in header string results in space appended to last header
Date: Tue, 13 Feb 2007 21:56:37 +1000
To: <bug-Email-Simple [...] rt.cpan.org>
From: "Barry Downes" <barry [...] bquotes.com>
Distribution & Version: Email-Simple-1.998 Perl Version: v5.8.7 built for cygwin-thread-multi-64int Operating system vendor & version: $ uname -a CYGWIN_NT-5.1 barry 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin Bug description: The double-CRLF which terminates the headers is included in the header string, in the case that the email body is present. The header parsing in Email::Simple::Header interprets this as a final blank header line, which is interpreted as a continuation of the last header. This results in an extra space being appended to the last header (unless it is blank). In my case, this resulted in Email::MIME not recognising the Content-Transfer-Encoding in a few emails, and failing to decode them. My solution: Exclude the terminating CRLF from the header string. (Be sure not to include it in the body either.) Patch: $ svn diff -r276 Email Index: Email/Simple.pm =================================================================== --- Email/Simple.pm (revision 276) +++ Email/Simple.pm (working copy) @@ -60,6 +60,7 @@ my $head; if (defined $pos) { $head = substr $$text_ref, 0, $pos, ''; + substr($head, -length($mycrlf)) = ''; } else { $head = $$text_ref; $text_ref = \'';
From: ALEXMV [...] cpan.org
On Tue Feb 13 06:59:09 2007, barry@bquotes.com wrote: Show quoted text
> Bug description: > The double-CRLF which terminates the headers is included in the header > string, in the case that the email body is present. > [snip] > In my case, this resulted in Email::MIME not recognising the > Content-Transfer-Encoding in a few emails, and failing to decode them.
Heh. I ran into it in the exact same circumstance. My solution was slightly different; to ignore header lines with no non-whitespace. Whichever solution you choose to go with, the below patch also includes a (trivial) failing test file. - Alex
diff -ru --new-file Email-Simple-1.998/lib/Email/Simple/Header.pm Email-Simple-1.998-patched/lib/Email/Simple/Header.pm --- Email-Simple-1.998/lib/Email/Simple/Header.pm 2007-02-06 22:22:03.000000000 -0500 +++ Email-Simple-1.998-patched/lib/Email/Simple/Header.pm 2007-02-15 03:15:44.000000000 -0500 @@ -72,6 +72,7 @@ if (s/^\s+// or not /^([^:]+):\s*(.*)/) { # This is a continuation line. We fold it onto the end of # the previous header. + next unless length $_; next if !@headers; # Well, that sucks. We're continuing nothing? $headers[-1] .= $headers[-1] ? " $_" : $_; diff -ru --new-file Email-Simple-1.998/t/header-space.t Email-Simple-1.998-patched/t/header-space.t --- Email-Simple-1.998/t/header-space.t 1969-12-31 19:00:00.000000000 -0500 +++ Email-Simple-1.998-patched/t/header-space.t 2007-02-15 03:14:05.000000000 -0500 @@ -0,0 +1,5 @@ +use Test::More tests => 1; +use Email::Simple; + +my $m = Email::Simple->new("Foo-Bar: Baz\r\n\r\ntest\r\n"); +is($m->header("Foo-Bar"), "Baz", 'No trailing space on last header of \r\n delimited mails');
Thanks, I've added a test for this and fixed it in 1.999. Sorry for the delay! -- rjbs