#!/usr/bin/perl # By Sean Murphy # E-Mail Syntax Checker # # This is a simple script that will # check the syntax of an email address # and spit back whether the address is # syntactically correct or not. This # is my first post to the Craft node. #mmmm...marshmallowey goodness... $atom = '[^()<>@,;:\".\[\] \000-\037\177]+'; $quoted = '"(?:[^"\\\n]|\\.)*"'; $word = "(?:$atom|$quoted)"; $localpart = "$word(?:\.$word)*"; $subdomain = "(?:$atom|\\[(?:[^\\[\\]\\\\\\r]|\\.)*\\])"; $domain = "$subdomain(?:\.$subdomain)*"; $addrspec = "$localpart\@$domain"; $route = "(?:\@$domain)+:"; $routeaddr = "<$route?$addrspec>"; $mailbox = "(?:$addrspec|$word+$routeaddr)"; $group = "$word+:(?:$mailbox(?:,+$mailbox)*)?;"; $address = "$mailbox|$group"; sub addr { local($_) = @_; 1 while s/\((?:[^()]|\\[()])*?[^\\]\)/ /g; /$address/o; } if (@ARGV > 0) { foreach (@ARGV) { print "$_ is ", addr($_) ? "" : "not ", "valid\n"; } } else { while (<>) { chop; print "$_ is ", addr($_) ? "" : "not ", "valid\n"; } }