Skip Menu |

This queue is for tickets about the MailTools CPAN distribution.

Report information
The Basics
Id: 26457
Status: resolved
Priority: 0/
Queue: MailTools

People
Owner: Nobody in particular
Requestors: cjm [...] cpan.org
Cc:
AdminCc:

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



Subject: [PATCH] Mail::Header inserts space when re-folding
When Mail::Header::_fold_line unfolds a header before refolding it, it adds a space where each LF was. When the header is refolded, that space remains. RFC 2822 section 2.2.3 makes it clear that folding/unfolding only involves inserting/removing CRLF pairs. The other whitespace is supposed to be left unchanged. While I understand that you've decided that it's too late to fix unfold without breaking existing code, I'm fairly sure that _fold_line can be fixed without compatibility problems. The attached patch (against 1.76) fixes _fold_line, and adds tests to demonstrate the problem and make sure it's fixed.
Subject: folding.patch
--- Mail\Header.pm Tue Apr 10 02:23:02 2007 +++ Mail\Header.pm Tue Apr 17 14:34:49 2007 @@ -106,8 +106,8 @@ my $min = int($maxlen * 4 / 5) - 4; my $ml = $maxlen; - $_[0] =~ s/[\r\n]+/ /og; # Remove new-lines + $_[0] =~ s/[\r\n]+//og; # Remove new-lines $_[0] =~ s/\s*\Z/\n/so; # End line with a EOLN return if $_[0] =~ /^From\s/io; --- t\header.t Wed Mar 10 03:51:22 2004 +++ t\header.t Tue Apr 17 14:36:28 2007 @@ -1,6 +1,6 @@ require Mail::Header; -print "1..22\n"; +print "1..25\n"; $h = new Mail::Header; @@ -73,6 +73,20 @@ print "not " unless $h->get(Date => 2) eq "an even\n longer test\n header\n"; +printf "ok %d\n",++$t; + +$h->fold(30); + +print "not " + unless $h->get(Date => 0) eq "a test header\n"; +printf "ok %d\n",++$t; + +print "not " + unless $h->get(Date => 1) eq "a longer test header\n"; +printf "ok %d\n",++$t; + +print "not " + unless $h->get(Date => 2) eq "an even longer test\n header\n"; printf "ok %d\n",++$t; $h->unfold;
Every once in a while, someone complains about it... and I can give you ten more places where MailTools follows rfc822, not rfc2822... But... because you also provided a patch of the tests, I will finally make the change. Hopefully, not too many ancient applications will suffer. By the way: line 139 must be changed as well: we should also not add or change a blank. - $_[0] =~ s/(.{$min,$max})\s+/$+\n /g; + $_[0] =~ s/(.{$min,$max})(\s)/$1\n$2/g;