Solved

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

Posted on 2003-12-07
4
201 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

816 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

11 Experts available now in Live!

Get 1:1 Help Now