Solved

error in data

Posted on 1999-01-04
9
122 Views
Last Modified: 2010-03-05
I have a form that has a box on it called email.  when the user enters in their email address and submits the form the address is printed: user%40server.com  Is there a reason why I am getting %40 instead of @ ?  And is there a way in the script to prevent that ?
0
Comment
Question by:craigs052998
  • 5
  • 4
9 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 70 total points
ID: 1207293
It's being escaped for safety... you need to unescape it.  If the variable name is $address

use URI::Escape;

$address = uri_unescape($address);

0
 

Author Comment

by:craigs052998
ID: 1207294
when you refer to variable do you mean perl or form?  the item name on the form is email and I want the script to print it on the message being mailed to the proper person.  the line in my script is:

print OUT "Users e-mail address:     $form{'email'}\n";

are you saying do:
print OUT "Users e-mail address:   $email = uri_unescape($email)\n";

to get it to print right ?
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1207295
Unless you're going to use it later, you don't need to assign it, thus

print OUT "Users e-mail address: uri_unescape($email)\n";


will do
0
 

Author Comment

by:craigs052998
ID: 1207296
that didn't work.  I got    uri_unescape(subject) in my from box with the following code:

print OUT "From:        uri_unescape($email)\n";

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:b2pi
ID: 1207297
You did put the



    use URI::Escape;

line at the top of your script?

What happens if you do:

$email = uri_unescape($email);
print OUT "From: $email\n";


0
 

Author Comment

by:craigs052998
ID: 1207298
still no good.  following is my script down to the point email(name) is used.  I am using name as the form item name in this script.

#Form that sends input to mail using blat
#!/perl5/bin/perl

use URI::Escape;

#output http headers
print "Content-type: text/html\n\n";

#define mail program and recipient address
$send_to = "person\@location.com";
$mail_prog = "blat.exe";

#Make sure the CGI request comes from the form
if ($ENV{'REQUEST_METHOD' } eq "GET" ) {
        $buffer = $ENV{'QUERY_STRING'};
        if($buffer eq "")  {
          print "<TITLE>Error</TITLE>\n";
          print "<H1 align=center>No</H1>\n";
          print "Use the form boxes.\n";
          exit(1);
        }
   }    else  {
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
   }

#Parse Env. variables from buffer
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
   ($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;
$value =~ s/%2C/,/g;
$value =~ s/%28/(/g;
$value =~ s/%29/)/g;
$value =~ s/%3F/?/g;
$value =~ s/%3A/:/g;
$value =~ s/%21/!/g;
$value =~ s/%2F/\//g;
$value =~ s/%5C/\\/g;
$value =~ s/%5B/\[/g;
$value =~ s/%5D/\]/g;
$value =~ s/%0D%0A/\n/g;
$value =~ s/%([a-fA-f0-9] [a-fA-f0-9])/pack("C", hex($1))/eg;
  $form{$name} = $value;
}

$variablearray{'date'} = &getdate;
$variablearray{'time'} = &gettime;

#check that all form boxes are filled out
#and all env. variables passed
if($form{"name"} eq "")  {
  print "<TITLE>Sorry</TITLE>\n";
  print "<h1 align=center>Please specify who this is from.</h1>\n";
  exit(1);
}
if($form{"month"} eq "")  {
  print "<TITLE>Sorry</TITLE>\n";
  print "<h1 align=center>Please select a month.</h1>\n";
  exit(1);
}
if($form{"year"} eq "")  {
  print "<TITLE>Sorry</TITLE>\n";
  print "<h1 align=center>Please select a year.</h1>\n";
  exit(1);
}

#format the text of the textarea field
#so it is not all one line when mailed
#$text = ($form{"added"});
#$a = length($text);
#$b = 50;
#$c = 51;
#while ($a > $b)  {
#   $x = index($text," ",$b);
#   substr($text,$x,1) = "\n";
#   $b = $b + $c;
#   $c = $c + 1;
#}

#print the contents of the form fields into a text file
open (OUT, ">escl") || die "Could not open Escl";
print OUT "Date:        $variablearray{'date'}\n";
print OUT "\n";
print OUT "Time:        $variablearray{'time'}\n";
print OUT "\n";
print OUT "To:          $form{'to'}\n";
print OUT "\n";

$name = uri_unescape($name);
print OUT "From:        $name\n";
0
 

Author Comment

by:craigs052998
ID: 1207299
forgot to mention I get server error during submission

TIA
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1207300
replace the foreach loop with

foreach $pair (@pairs)  {
          ($name, $value) = split(/=/, $pair);
          $form{$name} = uri_unescape($value);
}

then, at the bottom, use

print OUT "From: $form{email}\n";

If you're getting a server error, though, it's somewhat likely you don't have the URI::Escape package installed.  If that's the case, either install it, or, leave the foreach loop as it is, but change

$value =~ s/%29/)/g;
$value =~ s/%3F/?/g;

to

$value =~ s/%29/)/g;
$value =~ s/%40/\@/g;
$value =~ s/%3F/?/g;

0
 

Author Comment

by:craigs052998
ID: 1207301
the value =~ .... thing hit it right on the head  thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

20 Experts available now in Live!

Get 1:1 Help Now