Solved

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

Posted on 2003-12-07
4
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
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…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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