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

I am a perl novice. There must be something I am doing wrong as Email::Valid is returning true when I validate email addresses with embedded spaces. I have included the code. The first call seems to return true and the second call returns false (because of the additional @)

use Email::Valid; use strict; print (Email::Valid->address( 'x @ x.com') ? 'yes' : 'no'); print "\n"; print (Email::Valid->address( 'x @@ x.com') ? 'yes' : 'no'); print "\n";

Replies are listed 'Best First'.
Re: Email::Valid, what am I doing wrong here?
by ikegami (Patriarch) on May 14, 2009 at 17:35 UTC

    What makes you think the spaces aren't allowed?

    To aid in the creation and reading of structured fields, the free insertion of linear-white-space (which permits folding by inclusion of CRLFs) is allowed between lexical tokens.

    And "Joe & J. Harvey" <ddd @ Org> is used in an example in the spec.

      Sorry, I had responded without logging in first. I was pretty sure that this (allowing spaces) was intentional on the part of the programmer. My only concern was whther the 'space' was safe enough.

      If I type a space (before or after the @) in the To field of a gmail 'compose' form, it gives me:

      Some addresses in the "To" field were not recognized. Please make sure that all addresses are properly formed.

        And thus we discover one more thing Google does wrong. :) In this case you're talking to an application which has chosen its own limited filter heuristics. Passing the address to any mail transport agent should work. I just checked my own gmail address with extra spaces added sent from mail on the command line and it turned up in my box just fine.

      If I type a space (before or after the @) in the To field of a gmail 'compose' form, it gives me:

      Some addresses in the "To" field were not recognized. Please make sure that all addresses are properly formed.

      I was trying to send the mails from a perl script. I assume, that the space would be a problem, if it appears before or after the @ sign
Re: Email::Valid, what am I doing wrong here?
by Your Mother (Archbishop) on May 14, 2009 at 17:21 UTC

    The real email specs are extremely broad/permissive and contain all kinds of crazy stuff that few netizens realize is valid so I'd assume it's not a bug and that spaces are allowed in those positions. One of the smarties here will shoot that down and force you to file a bug report if that's wrong. :)