Subject: | [PATCH] $abstract->get_header('Missing-Header') warns with Mail::Internet |
Date: | Wed, 9 Jan 2008 12:22:24 -0200 |
To: | bug-Email-Abstract [...] rt.cpan.org, "Ricardo SIGNES" <rjbs [...] cpan.org> |
From: | "Adriano Ferreira" <a.r.ferreira [...] gmail.com> |
Ricardo,
While testing Mail::Thread 2.55 with Email::Abstract 2.134, I've
noticed many warnings emitted from Email::Abstract::MailInternet.
A sample of these warnings can be seen in this report:
http://www.nntp.perl.org/group/perl.cpan.testers/2007/11/msg799034.html
When I tried to understand the source of the warnings, I've found that
the culprit seems to be an optimization in
Email::Abstract::MailInternet to not do useless processing in scalar
context.
sub get_header {
my ($class, $obj, $header) = @_;
my @values = $obj->head->get($header);
# No reason to s/// lots of values if we're just going to return one.
$#values = 0 if not wantarray; # <<<<<<<<<<<<<<< HERE
chomp @values;
s/(?:\x0d\x0a|\x0a\x0d|\x0a|\x0d)\s+/ /g for @values;
return wantarray ? @values : $values[0];
}
The point is that if a header is missing, @values would contain an
empty list, but will become ( undef ) when passing by the marked line.
And then this "undef" would provoke the warning in the substitution.
The attached patch proposes a naive solution to this and an
additional test for " ->get_header('Missing-Header') ". Namely, the
code change is
diff -ru Email-Abstract-2.134/lib/Email/Abstract/MailInternet.pm
Email-Abstract/lib/Email/Abstract/MailInternet.pm
--- Email-Abstract-2.134/lib/Email/Abstract/MailInternet.pm
2007-09-24 19:45:03.000000000 -0300
+++ Email-Abstract/lib/Email/Abstract/MailInternet.pm 2008-01-09
12:04:25.000000000 -0200
@@ -25,6 +25,8 @@
my ($class, $obj, $header) = @_;
my @values = $obj->head->get($header);
+ # Return immediately if none found
+ return unless @values;
# No reason to s/// lots of values if we're just going to return one.
$#values = 0 if not wantarray;
Kind regards,
Adriano Ferreira
Message body is not shown because sender requested not to inline it.