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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/