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;