Google Answers Logo
View Question
 
Q: Include control character "\" in received email- CGI Perl ( Answered,   0 Comments )
Question  
Subject: Include control character "\" in received email- CGI Perl
Category: Computers > Internet
Asked by: budatlitho-ga
List Price: $5.00
Posted: 01 Nov 2002 07:53 PST
Expires: 01 Dec 2002 07:53 PST
Question ID: 95392
How can I include a control character "\" in the email output?

My Perl CGI script is:
print MAIL "<PMTags1.0Win><\#13><Flotilla>Flotilla
$flot{'FLNO.'.$x}<\#09>Name<\#13>\n"

My received email is:
<PMTags1.0Win><#13><Flotilla>Flotilla 10-05<#09>Name<#13>

Mail program is 
$mailprog = '/usr/sbin/sendmail';
running on a UNIX system
Answer  
Subject: Re: Include control character "\" in received email- CGI Perl
Answered By: gan-ga on 01 Nov 2002 08:13 PST
 
To include the special character "\" in perl output,
double-escape it like so:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "At the end of this sentence a single backslash is visible \\";

This is true of printing to file, as well as screen.

Hope this helps; if you require further information please do not
hesitate to ask for clarification before rating.

gan

Request for Answer Clarification by budatlitho-ga on 01 Nov 2002 09:56 PST
I received no line at all when I used the following:
#!/user/bin/perl
# reads incoming fields and puts them in an array in pairs.  Also,
fixes spaces, etc.
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $flot{$name} = $value;
                       }


$recipient = $flot{'recipient'};

open (MAIL,"|$mailprog -t"); #or dienice("Can't access $mailprog!\n")

print MAIL "To: $recipient\n";
print MAIL "Reply-to: $flot{'Reply_to'}\n";
print MAIL "Subject: 9CR Directory-Flotilla\n";

print MAIL "At the end of this sentence a single backslash is visible
\\";

close(MAIL);

I tried this also- same result: no line at all.
print MAIL "At the end of this sentence a single backslash is visible
\\n";

Clarification of Answer by gan-ga on 01 Nov 2002 12:33 PST
Hello budatlitho-ga,

I'm looking into this for you now, and will post back, hopefully with
a solution, as soon as possible.

Could you possibly let me know the precise version of sendmail that
you are using, also it's source code would be useful if it is
available somewhere.

Assuring you of my full attention,

gan

Clarification of Answer by gan-ga on 01 Nov 2002 13:22 PST
hello again budatlitho-ga.

One thing caught my eye - I think it's possibly just an effect of
posting, but at the line:

print MAIL "At the end of this sentence a single backslash is visible
\\";

the carrying over of the print command onto the next line would cause
problems.
I'd expect you to be receiving a '500 internal server error' from the
perl script, though, if that were the case.

I continue to seek the solution...

Request for Answer Clarification by budatlitho-ga on 01 Nov 2002 13:46 PST
"Could you possibly let me know the precise version of sendmail that
you are using, also it's source code would be useful if it is
available somewhere."

Requested from systems administrator.

"One thing caught my eye - I think it's possibly just an effect of
posting, but at the line:"

It's just the posting- it's in one contiguous line in the script.

Clarification of Answer by gan-ga on 01 Nov 2002 14:07 PST
Your sendmail script may accept the backslash if it is encoded as
follows:

print "At the end of this sentence a single backslash is visible
&#92;";

I have tested this, and it executes correctly when run as output to a
file or to the screen. However, since you are piping the output on to
sendmail, the issue is wether your version of sendmail will accept
encoding as above.

Try it and see; let me know if you have success. In the meantime, I
shall continue to seek information regarding this problem & will post
back soon to keep you informed of progress.

best regards,

gan

Clarification of Answer by gan-ga on 02 Nov 2002 07:26 PST
Hello budatlitho-ga,

I have been in contact with a sendmail user who reports that the
following works on his system; hopefully it might help.

#!/usr/local/bin/perl #change to your path to perl

$mailprog = '/usr/lib/sendmail'; #change to your path to sendmail

open (MAIL,"|$mailprog -t someone\@some_domain.com"); #change the
email
address. keep the \ in there
print MAIL "Subject: Test\n\n";
print MAIL "At the end of this sentence a single backslash is
visible\\";

close(MAIL);

Also, it's worth checking with your systems administrator, that there
are no rules set up within your sendmail installation which might
prevent the transmission of the escaped backslash through to the email
body output. They may be able to reconfigure the program to allow your
tags to pass through unhindered.

Let me know if you have success with the above.

I hope this helps get you 'up and running', but at this stage, if you
continue to fail to meet with success, I would like to ensure that you
are aware of the refund or repost procedure:

https://answers.google.com/answers/faq.html#refund

I shall of course continue to seek information which might help fix
your problem. I am becoming increasingly suspicious that the backslash
is meeting problems within sendmail, rather than your perl code.

best regards,

gan

Request for Answer Clarification by budatlitho-ga on 02 Nov 2002 08:20 PST
Gan:

I figured out how to do it, albeit indirectly.  In my input, I pass a
field with the value of "\".  Assigning it as a variable allows me to
insert it in the output anywhere I want.
Name of field in original form: backspace  value: \
After array assignment in CGI:
$form{'backspace'}

Inserted at end of line:
print MAIL "Some text with backslash required at end
$form{'backslash'}\n";

Works fine. What pointed me in the right direction (other than your
suggestions) was the admonishment to change any email address into a
variable, as Perl won't allow the "@' character.

As far as the charge goes, it's ok with me.  Your time was certainly
worth the price.  Thanks!

Clarification of Answer by gan-ga on 02 Nov 2002 09:02 PST
Hello budatlitho-ga,

I'm glad that the issue is now resolved.

Best regards,

gan
Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy