Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > encode UTF8 -> MIME

Reply
Thread Tools

encode UTF8 -> MIME

 
 
cc96ai
Guest
Posts: n/a
 
      05-30-2007
I got UTF8 value %C3%A9
how could I encode it become ?

I try encode_base64 , but no luck
maybe I miss some, anyone have idea ?

 
Reply With Quote
 
 
 
 
QoS@domain.invalid
Guest
Posts: n/a
 
      05-30-2007

cc96ai <(E-Mail Removed)> wrote in message-id: <(E-Mail Removed). com>

>
>I got UTF8 value %C3%A9
>how could I encode it become é ?
>
>I try encode_base64 , but no luck
>maybe I miss some, anyone have idea ?


you might like Unicode::Lite

 
Reply With Quote
 
 
 
 
Peter J. Holzer
Guest
Posts: n/a
 
      06-10-2007
On 2007-05-30 00:00, cc96ai <(E-Mail Removed)> wrote:
> I got UTF8 value %C3%A9


Thats's not UTF-8. That's URL-encoded UTF-8.

> how could I encode it become é ?


You have *decode* it to get é. And since it is encoded twice, you have
to decode it twice.

First decode the URL-Encoding:

$s = "%C3%A9";

$s =~ s/%([0-9A-F][0-9A-F])/chr(hex($1))/eg;

(there is almost certainly a module on CPAN which provides a
function to do that - but (to my surprise) neither CGI nor URI
contain such a function, ans its a simple one-liner)

Now you have UTF-8, which you can decode to a "perl character string":

use Encode;
$s = decode('utf-8', $s);

Now you have a string with a single character "é".

Now, how does MIME get into it?

For MIME, you again have to decide on a specific character encoding
(e.g., UTF-8, or ISO-8859-1, or whatever), and then possibly on a
specific transport encoding (base64 or quoted-printable).

So you have to encode it in your character encoding first, and then
possibly encode the result again with the transport encoding.

Note that the MIME is a quite complex format (especially the encoding of
header fields described in RFC 2047 and RFC 2231), so I won't go into
more detail unless you tell us exactly what you need. Any advice I can
give (except "use existing modules" and "read the RFCs") is almost
certainly incomplete and will cause you to produce ill-formed messages
if follow it blindly.

hp


--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | http://www.velocityreviews.com/forums/(E-Mail Removed) |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
given char* utf8, how to read unicode line by line, and output utf8 gry C++ 2 03-13-2012 04:32 AM
tomcat 4.x : setting mime type for a directory or setting a default mime type CJ Java 1 10-29-2004 07:51 PM
line wrap with encode('MIME-Header', "foo") Axel Hanusch Perl Misc 2 06-03-2004 10:57 AM
how 2 convert mime to txt or extract words from mime joe Perl Misc 0 04-07-2004 12:34 AM
Receiving zip files via Mime::Parser/Mime::Decoder Jan Arickx Perl Misc 0 08-25-2003 08:24 PM



Advertisments