I'm quite sure this is a bug (with a very simple patch). In TWiki::Net::sendEmail(), these lines are present for To, Bcc and Cc.
$tmp =~ s/^To:\s*//io;
@arr = split( /[,\s]+/, $tmp )
shouldn't that be:
$tmp =~ s/^To:\s*//io;
@arr = split( /\s*,\s*/, $tmp );
?
In
MailToTWikiAddOn replies are sent to users. If the
From: line from the user looks like this:
From: Peter Morch <peter@morch.nospam.com>
, then replies get sent to
Peter@localhost,
Morch@localhost and
peter@morchPLEASENOSPAM.nospam.com. The
From: line above is in standardized valid mbox format which very many users send, and so now I'm wondering: Is there any particular reason that TWiki::Net::sendEmail() splits the addresses in non-standardized ways? If not, there is a bug, and my patch will work. I've tested my patch with mailnotify and with
MailToTWikiAddOn, and they seem to work from my limited newbie viewpoint.
--
PeterMorch - 15 May 2003
Since TWiki core code doesn't need this code, and you really need to do full email address header parsing (e.g. using
CPAN:Mail::Address
which is quite good) to handle the full scope of this problem, I'm reluctant to include this in the core, as it would incur another module load, and installation hassles, for people who don't use that plugin. I think the plugin should do the address parsing using Mail::Address and hand a valid email address (
fred@examplePLEASENOSPAM.com) that doesn't include the name part.
Here's some code from a script I wrote recently that parses the From header, in this case it shows the name if it exists, otherwise the email address, but it gives an idea:
use Mail::Address;
# Clean up From address, showing name if it exists, otherwise email address
sub clean_from {
my ($from) = @_;
my @addrs = Mail::Address->parse($from);
my $cleanFrom;
print "Warning: more than one address in From, using first" if $#addrs > 0;
$cleanFrom = $addrs[0]->name || $addrs[0]->address;
return $cleanFrom;
}
See
RFC:2822
for the full complexity of addresses that you might have to parse, hence the need for this module.
--
RichardDonkin - 15 May 2003
with a new r1.2 patch
I had just finished a very lengthy ramble on the merits of my first patch (r1.1), when I finally undestood your point about the complexities of
RFC:2822
. E.g.
To: "Morch, Peter" <peter@morch.nospam.com>
is also exactly one email address. And here, both the r1.1 patched and the original version will fail. Still, the r1.1 patched version is better, though. There are test cases where the original will fail, but the r1.1-patched version will work. The opposite is not true.
So now there is a newer, better r1.2 patch. It uses the
MailTools
(Mail::Internet, Mail::Address) family if they are installed. Otherwise they use the r1.1 patch from before. This follows the pattern used in sendEmail already, where Net::SMTP is used if it is present, otherwise sendmail is used.
If
MailTools
is present, it uses API functions from
MailTools
to do the parsing, and that works!
Otherwise it splits on /\s*,\s*/ as in the r1.1 patch. Can we agree that although not perfect, that is still better than what is there in the original from the Beijing (01Feb2003) release?
--
PeterMorch - 16 May 2003