Email address syntax check?

Email address syntax check?

am 02.12.2006 20:58:00 von tuxedo

I'd like to do a email address verification as part of a simple cgi web mail
submission form. I'm considering use of the Email::Valid module, which
requires Mail::Address, which is part of the MailTools-1.74 package.

However, unfortunately, I do not have sufficient permissions to install
modules other than in external directories on the server.

The Email::Valid module is not a problem as it can be installed by ...

perl Makefile.PL PREFIX=/where/I/want/it/put

.... but the installation of MailTools-1.74 does not offer the same
possibility through the PREFIX method. I tried but I got the usual error:
"Warning: You do not permission to install in /usr/lib/perl5/.." etc.

Anyone happens to know a solution? Or perhaps better, a procedure that is
already part of the perl version which I have - perl 5.6.1.

What I'm hoping for is a non-critical address syntax check, without getting
my hands dirty with complex regex's and RFC's....

Any pointers to man pages, or even entire syntax checking code, would be
greatly appreciated!

Many thanks!

Re: Email address syntax check?

am 02.12.2006 21:33:46 von tuxedo

I wrote:

[...]

> Any pointers to man pages, or even entire syntax checking code, would be
> greatly appreciated!

To be a bit more specific in terms of the conditions I would like to check
and what I consider valid form input, that is: one or more comma or white
space separated valid email addresses.

What I do not need or plan to make use of are live checks that query smtp
servers for existence of addresses, as I understand such type of procedures
do not necessarily work, nor could they speed up the cgi processing.

Re: Email address syntax check?

am 02.12.2006 21:34:47 von Gunnar Hjalmarsson

tuxedo wrote:
> I'd like to do a email address verification as part of a simple cgi web mail
> submission form.

I'm using this sub in a couple of applications:

sub emailsyntax {
return 1 unless my ($localpart, $domain) = shift =~ /^(.+)@(.+)/;
my $atom = '[^[:cntrl:] "(),.:;<>@\[\\\\\]]+';
my $qstring = '"(?:\\\\.|[^"\\\\\s]|[ \t])*"';
my $word = qr($atom|$qstring);
return 1 unless $localpart =~ /^$word(?:\.$word)*$/;
$domain =~ /^$atom(?:\.$atom)+$/ ? 0 : 1;
}

my $address = 'john.smith@example.com';
print "Syntax ok\n" unless emailsyntax($address);

It's not as strict as RFC 822; for instance it accepts non-ASCII
characters. Still catches most syntactical typos.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: Email address syntax check?

am 02.12.2006 21:36:13 von chris-usenet

tuxedo wrote:
> The Email::Valid module is not a problem as it can be installed by ...
> perl Makefile.PL PREFIX=/where/I/want/it/put

> ... but the installation of MailTools-1.74 does not offer the same
> possibility through the PREFIX method. I tried but I got the usual error:
> "Warning: You do not permission to install in /usr/lib/perl5/.." etc.

Recheck the FAQ on this, which refers to LIB as well as PREFIX.

Regards,
Chris

Re: Email address syntax check?

am 02.12.2006 22:07:43 von tuxedo

Gunnar Hjalmarsson wrote:

[...]

> It's not as strict as RFC 822; for instance it accepts non-ASCII
> characters. Still catches most syntactical typos.

Many thanks for this contribution - I will test and hopefully it will fit my
purpose perfectly!

Re: Email address syntax check?

am 02.12.2006 22:16:57 von Gunnar Hjalmarsson

tuxedo wrote:
> Gunnar Hjalmarsson wrote:
>>It's not as strict as RFC 822; for instance it accepts non-ASCII
>>characters. Still catches most syntactical typos.
>
> Many thanks for this contribution

You're welcome.

> - I will test and hopefully it will fit my purpose perfectly!

Please let me know of possible findings.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: Email address syntax check?

am 02.12.2006 22:59:02 von tuxedo

Gunnar Hjalmarsson wrote:

> Please let me know of possible findings.

Thanks. But I can't quite see through this. I get a perl syntax error
near "=~ ^".

Any chance that you could kindly post your complete script within a
cut-n-paste example for the blind and stupid?

Many thanks!

Re: Email address syntax check?

am 02.12.2006 23:17:24 von Gunnar Hjalmarsson

tuxedo wrote:
> Gunnar Hjalmarsson wrote:
>>Please let me know of possible findings.
>
> Thanks. But I can't quite see through this. I get a perl syntax error
> near "=~ ^".
>
> Any chance that you could kindly post your complete script within a
> cut-n-paste example for the blind and stupid?

But... The code I posted _is_ intended to copy, paste and run. Your
newsreader must have done something with it.

Try to copy from:
http://groups.google.com/group/comp.lang.perl.modules/msg/e7 e65ccea8c2fac9

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Re: Email address syntax check?

am 02.12.2006 23:38:01 von tuxedo

Gunnar Hjalmarsson wrote:

[..]

> newsreader must have done something with it.

Yes - some of the forward slashes were gone. Damn newsreader! If I view
source they are all there and your script works fine - thanks again!