#!/usr/local/bin/perl # # ValidMail - Check E-mail Address Syntax # V1.0 - 25 Jun 1996 # # Written by # Jouko Valta (jopi@x2ftp.oulu.fi) # # # Check for special characters and domain name on assumed e-mail address. # # Options # o none # # Return Values # 0 Address Syntax OK. # 1 Address clearly invalid # 2 Error occurred while processing address # # # TODO: do further tracing for it. # # ## Filenames $MASTER_INDEX = "/ftp-service/bin/lib/valid_domain"; # Parse input string # The first test performed is to count the number of elements and check match, # otherwise, Syntax error is flagged. # local $_ = $address = $ARGV[0]; ($user, $host, $junk) = /^\s*(\S+)\@(\S+)\s*(\S*)\s*$/; if (!$user || !$host || $junk || y/\@\!/\@\!/ != 1) { # Test address syntax printf ("*** ADDRESS INVALID: '$address' (Syntax) ***\n"); exit 1; } if (/\@\S+\.(\S+)\s*$/) { # At least sub '.' main $d0 = $1; $d0 =~ tr/a-z/A-Z/; } if (!$d0) { printf ("*** ADDRESS INVALID: '$address' (No domain) ***\n"); exit 1; } # Compare $d0 against the domain codes... if (!open (M, "<$MASTER_INDEX")) { print STDERR "$0: Cannot open data file.\n"; exit 2; } $found = 0; while () { if (/^\s*$|^!/) { next; } # Empty line or comment if (/^\s*($d0)\s+(\S+)/) { # Find domain on Codes List $country = $2; ++$found; # print STDERR "DEBUG: $_\n"; } } # while if (!$found) { printf ("*** ADDRESS INVALID: '$address' (Illegal domain) ***\n"); exit 1; } else { printf ("ok '$address' ($country)\n"); exit 0; }