[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2003-12-07
4
Medium Priority
?
207 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

656 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