Kjetil has asked for the wisdom of the Perl Monks concerning the following question:

Oh, deeply insightful ones,

I do not know how to proceed. The problem is seemingly trivial, and I have been trying different paths, but none has so far been successful.

I get e-mails sent from a web form. I can't change that, unfortunately.

In those e-mails, I have many Norwegian letters, e.g. ø. The e-mail comes with

Content-Type: text/plain; charset=ISO-8859-1
and when I look at it in pine, it comes out correctly.

However, if I look at the file itself, it comes out as the code =F8, and it seems like in a variable, it's there too. I'm stuffing these data into a PostgreSQL database (with DBI), and apparently, the =F8 code goes into the db too. Obviously, I don't want that... :-)

I've been playing around with setting locales, that is

use POSIX qw(locale_h); setlocale(LC_ALL, "no_NO.UTF-8");
but this doesn't help.

Now, I humbly request your attention and hope you can lead me along the right path.

Replies are listed 'Best First'.
Re: Norwegian letters problem
by zby (Vicar) on Apr 30, 2003 at 13:32 UTC
    For sure it looks like the 'quoted printable' encoding. There are perl modules for working with it: QuotedPrint. I think the Content-Type is just not correct, but I might be wrong.

    Update: I've found there is another header for this: Content-Transfer-Encoding. From RFC 2045:

    6.1. Content-Transfer-Encoding Syntax The Content-Transfer-Encoding field's value is a single token specifying the type of encoding, as enumerated below. Formally: encoding := "Content-Transfer-Encoding" ":" mechanism mechanism := "7bit" / "8bit" / "binary" / "quoted-printable" / "base64" / ietf-token / x-token
      Ah, the wisdom of the monks can never seize to amaze! Thanks a lot, MIME::QuotedPrint does the trick!
Re: Norwegian letters problem
by nite_man (Deacon) on Apr 30, 2003 at 14:18 UTC
    I think that your strings are Quoted Printable. Try to use MIME::QuotedPrint module:
    use MIME::QuotedPrint; my $msg = <your string>; $msg =~ s/=\?ISO-8859-1\?Q\?//g; # Cut a charset information and a cri +terion of quoted print string. $msg =~ s/\?=//g; # Cut a criterion of quoted print string end. $msg = MIME::QuotedPrint::decode($msg); # Decode string
          
    --------------------------------
    SV* sv_bless(SV* sv, HV* stash);