Solved

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

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

729 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