V
V
Vyacheslav Golovanov2013-01-05 13:17:14
Perl
Vyacheslav Golovanov, 2013-01-05 13:17:14

What is the encoding in imap?

I'm trying to decode mail received via imap using perl (I use Net::IMAP::Simple)

I get the following lines: Lebedev's

=?UTF-8?B?RGF2aWQgS3VyZXh5YW4g0L/RgNC40LPQu9Cw0YjQsNC10YIg0JLQsNGBINGB?=

decoder coped with the decoding and wrote that it is base64

But if you try

use MIME::Base64;
print decode_base64('=?UTF-8?B?RGF2aWQgS3VyZXh5YW4g0L/RgNC40LPQu9Cw0YjQsNC10YIg0JLQsNGBINGB?=');


then the output is empty.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
R
return, 2013-01-05
@return

This is MIME-B, look for how to work with it.

A
Antelle, 2013-01-05
@Antelle

This is base64. It is necessary to decode what is after after "=?UTF-8?B?"
Answer: "David Kurexyan invites you with"

M
mithraen, 2013-01-05
@mithraen

This is decoded with Encode::MIME::Header.
In addition to B (base64), there may also be Q (quoted-printable).

M
merlin-vrn, 2013-01-07
@merlin-vrn

First, not in IMAP, but in the mail header. This is how all non-ASCII mail headers are arranged - only characters with the most significant bit 0 are allowed inside, i.e. UTF-8 is not directly valid; it is encoded in BASE64 and thus placed in the headers.
Secondly, even without knowing the answer, it would be logical to assume that =?UTF-8?B? is a "preamble" describing the format of the subsequent data, from? before? (which is not a base64 encoded character).
Thirdly, if your header looks like
Subject: =?UTF-8?B?bla-bla-bla?=
(spaces) =?UTF-8?B?bla-bla-bla?=
then all these lines need to be unpacked independently and then do the concatenation.
In general, read RFC5321 and 5322. The specific pearl module was suggested above.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question