Farzher
Farzher

Reputation: 14573

IMAP what type of header encoding is this?

Why does my subject look like this?

From: "Website Magazine"
 <[email protected]>
To: [email protected]
Date: 20 Sep 2012 15:36:20 -0400
Subject: =?utf-8?B?MTQgTmV3LWlzaCBBUEnigJlzIGZvciBEZXZlbG9wZXIgSW5z?=
 =?utf-8?B?cGlyYXRpb24=?=

In gmail it reads as 14 New-ish API’s for Developer Inspiration

I'm using PHP, but just telling me what type of encoding that is should be enough for me to parse it.

Upvotes: 0

Views: 1317

Answers (2)

Xeoncross
Xeoncross

Reputation: 57184

That is base64 encoding.

 print base64_decode('MTQgTmV3LWlzaCBBUEnigJlzIGZvciBEZXZlbG9wZXIgSW5z');

You see, the problem is that only ASCII characters are allowed in emails, so if you have non-English/Latin text you need to base64 encode it so that you can send it.

function mail_utf8($to, $from_user, $from_email, $subject = '(No subject)', $message = '')
{ 
    $from_user = "=?UTF-8?B?".base64_encode($from_user)."?=";
    $subject = "=?UTF-8?B?".base64_encode($subject)."?=";

    $headers = "From: $from_user <$from_email>\r\n". 
               "MIME-Version: 1.0" . "\r\n" . 
               "Content-type: text/html; charset=UTF-8" . "\r\n"; 

    return mail($to, $subject, $message, $headers); 
}

Upvotes: 3

Lix
Lix

Reputation: 47976

What you are looking at is a string encoded in base64.

To decode this string you could use php for example.

echo base64_decode('MTQgTmV3LWlzaCBBUEnigJlzIGZvciBEZXZlbG9wZXIgSW5z');

Upvotes: 1

Related Questions