#!/usr/sup/gnu/bin/perl # Definition pick more or less straight from RFC-822. $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 valid_address { local($_) = @_; # Remove comments, remember that comments might nest. 1 while s/\((?:[^()]|\\[()])*?[^\\]\)/ /g; /$address/o; } # Either read the arguments or read the standard input (line by line). if (@ARGV > 0) { foreach (@ARGV) { print "$_ is ", valid_address($_) ? "" : "not ", "valid\n"; } } else { while (<>) { chop; print "$_ is ", valid_address($_) ? "" : "not ", "valid\n"; } }