Connovar has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm currently using Mail::Sender to deliver mail to certain workpools of users in our system. I noticed something fishy when we started receiving bounces on a user's address that contained a single quote in the last name, e.g.

jane.o'doe@domain.com.

The actuall address that is used when sending (after passing through the Mail::Sender internals) comes out like so,

doe@domain.com

I found the code responsible:

sub _prepare_addresses { my ($self, $type) = @_; if (ref $self->{$type}) { $self->{$type.'_list'} = $self->{$type}; $self->{$type} = join ', ', @{$self->{$type.'_list'}}; } else { $self->{$type} =~ s/\s+/ /g; $self->{$type} =~ s/, ?,/,/g; $self->{$type.'_list'} = [map {s/\s+$//;$_} $self->{$type} =~ /((? +:[^"',]+|"[^"]*"|'[^']*')+)(?:,\s*|\s*$)/g]; } }
Regexs are not my strong point in perl, however I can see that the problem comes from the first class in the first regex group, i.e. [^"',]. What I am wondering is there a better way to handle the parsing of $self->{'to'}? Doing a split on "," then cleaning up trailing white space and boundary single and double quote characters.

I did a fair bit of googling and was surprised this has not come up before.

Replies are listed 'Best First'.
Re: Mail::Sender not handling single quotes
by Jenda (Abbot) on Nov 01, 2005 at 17:41 UTC

    You may circumvent this by specifying the address in an array:

    ... to => [ "jane.o'doe@domain.com" ], ...
    This is legal even if there is just one address :-)

    I did get a report about this bug already and do have a fix ready, but did not release it yet. Sorry, I will.

    Jenda
    XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.

      Thankyou all for the replies. Jenda I should be able to change the input (email addresses) from a scalar to an array ref from when they are retrieved without too much difficulty. If I would or been paying attention I would of realised this before posting! Thanks again :)
Re: Mail::Sender not handling single quotes
by PodMaster (Abbot) on Nov 01, 2005 at 07:49 UTC
    What I am wondering is there a better way to handle the parsing of $self->{'to'}? Doing a split on "," then cleaning up trailing white space and boundary single and double quote characters.
    Yes, leave it something that knows how, like Mail::Address, Email::Address ...

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      For the sake of clarification, the code in the root node is from Mail::Sender, which is apparently inadvertently mangling certain types of email addresses. Connovar, it would be a good idea to send a private message to Jenda, who is a regular contributor here as well as the author & maintainer of that module.
Re: Mail::Sender not handling single quotes
by dtr (Scribe) on Nov 01, 2005 at 09:10 UTC

    You might also like to look at Regexp::Common - which contains regular expressions for pretty much anything you can think of!