Skip Menu |

This queue is for tickets about the MailTools CPAN distribution.

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

People
Owner: Nobody in particular
Requestors: awkay69 [...] yahoo.com
Cc:
AdminCc:

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



Subject: Mail::Header fold stops early
Long lists of email addresses are only partially folded. The attached program demonstrates the problem: after folding 3 lines worth of data, the algorithm gives up and the last line is left with the remaining characters.
Subject: t.pl
use Mail::Header; $f = new Mail::Header(); $f->replace('To', 'nsg@example.com,felsing@example.com,tedsmith@example.com,heinzkil@example.com,lbennett@example.com,ehteague@example.com,tstave@example.com,klenn@example.com,butler@example.com,pfrantz@example.com,jenkins@example.com,meb@example.com,snb@example.com,btabb@example.com,emp@example.com,clist@example.com,jdfox@example.com,kzhang@example.com,vmitch@example.com,skgray@example.com,smidkiff@example.com,ANesbit@example.com,annie@example.com,jonjab@example.com,mrwatson@example.com,ebreak@example.com,mahyatt@example.com,acoffman@example.com,rthomas@example.com,dpwalton@example.com,mgrenci@example.com,mbean@example.com,jstaiger@example.com,johnruss@example.com,'); $f->fold(75); $f->print;
It turns out that this example shows the 4/5 rule as a minimum starting point is a bad idea. The attached patch suggests adding two backoff rules in the matching. One which allows a split mid-line on commas, and one that allows a complete backtrack. Perhaps there are more desirable places to break, and perhaps the algotihm needs to be more than one stage. This is just one possible solution that fixes the example in question.
*** /usr/lib/perl5/site_perl/5.8.6/Mail/Header.pm 2007-09-13 15:16:43.000000000 -0700 --- /tmp/Header.pm 2007-09-13 15:17:51.000000000 -0700 *************** *** 104,109 **** --- 104,110 ---- my $max = int($maxlen - 5); # 4 for leading spcs + 1 for [\,\;] my $min = int($maxlen * 4 / 5) - 4; + my $half = int($maxlen / 2) - 4; my $ml = $maxlen; $_[0] =~ s/[\r\n]+//og; # Remove new-lines *************** *** 124,135 **** --- 125,139 ---- $x .= "$1\n " while($_[0] =~ s/^\s* ([^"]{$min,$max}?[\,\;] + |[^"]{$half,$max}?[\,\;] + |[^"]{1,$max}?[\,\;] |[^"]{1,$max}\s |[^\s"]*(?:"[^"]*"[ \t]?[^\s"]*)+\s |[^\s"]+\s ) //x); $x .= $_[0]; + print STDERR "In: $x\n"; $_[0] = $x; $_[0] =~ s/(\A\s+|[\t ]+\Z)//sog; $_[0] =~ s/\s+\n/\n/sog; *************** *** 141,146 **** --- 145,151 ---- } } + print STDERR "Final: $_[0]\n"; $_[0] =~ s/\A(\S+)\n\s*(?=\S)/$1 /so; }
Your reported problem is there, but your patch doesn't really solve it (besides contained debug prints) I will change the match into $x .= "$1\n " while $_[0] =~ s/^\s* ( [^"]{$min,$max} [,;] | [^"]{1,$max} [,;\s] | [^\s"]*(?:"[^"]*"[ \t]?[^\s"]*)+\s ) //x; It will be fixed in 2.00_03 If you really want to have correct folding, then use MailBox, not MailTools.
From: awkay69 [...] yahoo.com
On Fri Sep 14 04:28:50 2007, MARKOV wrote: Show quoted text
> Your reported problem is there, but your patch doesn't really solve it > (besides contained debug prints) I will change the match into > > $x .= "$1\n " while $_[0] =~ > s/^\s* > ( [^"]{$min,$max} [,;] > | [^"]{1,$max} [,;\s] > | [^\s"]*(?:"[^"]*"[ \t]?[^\s"]*)+\s > ) //x; > > It will be fixed in 2.00_03 > If you really want to have correct folding, then use MailBox, not
MailTools. Thanks. I am not the one using it for folding, MIME::Entity is; well, technically, MIME::Entity uses MIME::Head, which in turn uses Mail::Header. If you are claiming your module is sufficient for creating RFC-compliant headers, then we should probably communicate that to the MIME-Tools team, since they are relying on it.
closed again fixed in 2.00_03