![]() |
|
||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
MIVA® SNIPPETS: Validating e-mail addresses
Syntax VerificationTo avoid accepting mistyped, invalid or bogus e-mail addresses you should first check for validity of the syntax. Check for appearance of a single '@' character, at least one dot, last two domain tokens must be long at least two characters and the address may contain only valid characters: aphanumeric or a hyphen '-' see RFC 1034 - 3.5. Preferred name syntax. The minimal length of an e-mail address should be 7 characters.
Domain Verification - Shell ScriptIf you have your own cgi-bin directory and a shell enabled or Perl installed, you can use nslookup or ping - just MvCALL a very simple shell script and parse the callvalue to find out if the domain exists. However, it will not tell you if the mailbox exists or not. The shell script (e.g. ping.sh) would look something like this:
#! /bin/sh
'-c1' stands for a single ping, if you prefer you can try to ping more times. You could write the script in Perl, of course too. Be sure to upload the file in text mode and set permission to 0755. Test it before trying with Miva - try first in Telnet:ping.sh miva.com. If it works, call it from a browser: http://yourDomain.com/cgi-bin/ping.sh?miva.com. You should either see the output of the ping command on the screen or download it as a file. If there are problems, try changing the extension to '.cgi' or write the program in Perl instead:
#!/usr/bin/perl
Domain Verification - Miva CallYou would call it with the following Miva code:
According to your OS and the ping version you may need to change some details like url, paths, arguments or the return string. Instead of checking the callvalue you can also work with the callreturnheaders - the ping.sh script returns 500 server error if nothing found. You should be aware that the method is not bulletproof:
You can modify the script to use 'nslookup' instead or checking the ports 110 (POP) and/or 25 (SMTP). The last might be the best solution - as soon as I find some spare time I will try to post a sample script too. Putting It All TogetherThis is a simplified code. It checks for valid characters (alphanumeric + hyphen), the minimal lenght (7 characters), for presence of '@' and a dot and pings the domain to see if some echo comes.
After posting this code, Drew Skinner mentioned on the Miva User List that there are addresses containing non-alphanueric characters in the first part of the address. For example !@domain.com or !/bin/sh@domain.com. They are not really conform to the recomendation of RFC, but they may exist. If you want to accept such addresses just slightly modify the code as follows:
Here goes a sample code with a submission form and both alternatives Test It!Using Mailer Software For ValidatingDrew suggested also using the -bv option of a mailer to check if a mail to the desired address is deliverable. Unfortunately, the most common mailer, Sendmail, is absolutely useless - it confirms any non-existing domain (in the default configuration, at least). According to Drew, Exim (another mailer) is much better. You can experiment with your own mailer and modify the scripts respectively. For example, with Exim you could use the following shell script: Some Useful LinksList of RFC'sRFC 821 - SMTP RFC 821 (SMTP) Verifying and expanding RFC 822 Format of ARPA Internet text messages RFC 1035 - 8. MAIL SUPPORT RFC 974 Mail routing and the domain system |
||||||||||
|
Miva and some other terms used on this page are registerd trademarks of the Miva Corporation |