Solved

Need to parse a variable to see if it contains more than 1 email address

Posted on 2003-12-07
4
199 Views
Last Modified: 2013-12-25
I have a perl / cgi script that allows a web site visitor to send the page they are on to another persons email address... "refer to a friend".

The problem is that a spammer has targeted this process, and has made a process that submits many many email addresses to the cgi program, and is using my form, and a comment field (for the spam message) to send out his spam and abuse my network.

The "to" address is contained in the variable: $FORM_DATA{"to"}

I am wanting a perl snippit that I would place in a subroutine before mailing, that would test this address, and if there was more than one email address in the field, it would return an error to the screen and stop the cgi execution.

I would like the code for an answer to be in subroutine format (working code), and if the code you suggest works as I paste it in the program, then you get the points. Post your email-at-domain if you want me to send you the entire script.

Thanks!

(I would be interested in expanding the points to exclude a person from using the form more than 1x per day, by logging IP address, but that is not as critical as the above.)
0
Comment
Question by:rapidhost
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
rkosai earned 250 total points
ID: 9893118
To check if a variable contains more than one email address, we can check for invalid address characters. Because those characters would 1)serve as delimiters, or 2)be invalid anyways, we can use this code:

sub valid_email {
  my $email = shift;
  if ($email =~ /[^\w\@\.]/) {return 0} else {return 1};
}

You could use it like this:

my $addr = $FORM_DATA{"to"};
if (valid_email($addr)) {
  #send mail
} else {
  #display error message
}
0
 
LVL 84

Expert Comment

by:ozo
ID: 9894834
Except that there are no characters that are invalid in email addresses.
0
 
LVL 3

Expert Comment

by:rkosai
ID: 9895003
There are actually a few invalid characters in an email address.  Space, newlines, carriage returns, and many of the symbols (such as $, #, %, etc) are not allowed in email addresses.  In addition, commas tend to be used as delimiters so they also can't be used.
0
 
LVL 84

Expert Comment

by:ozo
ID: 9917660
$ # % etc are allowed in email addresses, and Space, newlines and carriage returns may be used when in quotes.  Commas also need to be quoted
http://www.faqs.org/rfcs/rfc822.html
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now