Tags:
create new tag
view all tags
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

UPDATED 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! smile

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

Topic attachments
I Attachment History Action Size Date Who Comment
Unknown file formatpatch SendEmailSplitAddressError.patch r2 r1 manage 2.8 K 2003-05-16 - 13:51 UnknownUser Modifies split code as described in topic
Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2003-05-16 - PeterMorch
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.