MIME::QuotedPrint - extra '=' and linebreak?



Hello,

I have a script that reads CGI-input, processes the data and e-mails
it onwards by opening a filehandle-pipe to sendmail and writing the
necessary SMTP headers and data there.

Wanting to teach myself the essential internet protocols I've done
most of the processing by hand, i.e. without modules such as CGI.pm,
but when it comes to character encodings I decided to let myself off
the hook and use a module, namely MIME::QuotedPrint. It seemed just
the thing for the last glitch I had : getting mail clients to properly
display non-ASCII subject headers.

However, the module didn't quite produce the result I expected. It
correctly encoded the non-ASCII characters to '=<1byte_hexcode>', but
unexpectedly also added an extra '=\n' sequence to the end of the
string I was encoding.

The relevant code is pasted below. chomp'ing the encoded string and
removing the final '=' does now produce subject headers that display
the (iso-8859-15 encoded) characters properly, but it does seem to me
to be a bit of a hacky solution. So, have I misunderstood the use of
the module, is there a more "proper" way to get this done?

code:
-----------------------------------------------
....
#HANDLE CGI-INPUT AND STORE KEY-VALUE PAIRS IN %data
....

#EMAIL THE ORDER
###################
open MAIL, "|/usr/lib/sendmail -t -odq -oi";
print MAIL "From: XXXXXXXXXXXXXXXXXXXxx\n";
print MAIL "To: XXXXXXXXXXXXXXXXXXXXXXx\n";
print MAIL "Content-type: text/plain; charset=iso-8859-15\n";

my $encoded = $data{'tilaaja'}; #CAN CONTAIN NON-ASCII (ISO-8859-15)
CHARS
$encoded = MIME::QuotedPrint::encode($encoded);

#NECESSARY HACK?
chomp $encoded;
$encoded =~ s/=$//;

print MAIL "Subject: ORDER: =?iso-8859-15?q?$encoded?= \n\n";
print MAIL "Sent on $date, $time.\n";

#FORMAT AND WRITE MAIL MESSAGE MAIN CONTENT
for(keys %data) {
print MAIL "_"x60,"\n";
print MAIL ucfirst $_,":\n\t";
print MAIL "$_\n$data{$_}\n";
print MAIL "_"x60,"\n\n";
}
close MAIL;
--------------------------------------------------

-op

.



Relevant Pages

  • Re: find a value in a table based on 2 different criteria
    ... Are your entries in B1:Y1 proper dates, ... value do you have in F2 to specify the month in question? ... headers are the month and the value that determines what column of the table ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Securing an Email script
    ... Since you do ZERO checking on the values it's nothing BUT security issues. ... Proper redirects have to be done server-side, in case of PHP with a ... headercall to send the appropriate HTTP status code and headers. ... thingies and thinking about server-side error handling. ...
    (comp.lang.php)
  • Re: Reply-To as from $reverse_name
    ... recipient which is part of the alternates for a proper Reply-To? ... Dirty hacks: use wrapper-script as $editor (edit full headers) or ...
    (comp.mail.mutt)
  • Re: Why is my ISP blocking incoming emails - header attached
    ... previous e-mails from vsnl.net with proper subjects were refused as well... ... > recipient is not anybody I know, the Subject or message body are anything ... > messages sent by spammers using fake sender's addresses (in this case ... The headers are attached. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)