By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,905 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,905 IT Pros & Developers. It's quick & easy.

Decoding MIME encoded email subject

P: n/a
Greetings all- I am trying to extract subject headers from emails that
have been saved as text files. The subject headers are in MIME UTF-8
format, and so they appear like this:

subject:
=?utf-8?B?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW 5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21i czsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=

What class can I use to decode the subject text?

Dec 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

That's not MIME format. MIME provides separation of message parts and
embedding of messages within other messages.

That's probably base64 or uuencode or something like that, not sure
exactly. The MIME header should have an encoding line which says what
encoding is used for the rest of the message. Most commonly MIME
messages are encoded with Quoted-Printable for text and Base64 for
binary. QP looks pretty much just like regular text with a lot of
extra = signs.

If this isn't enough info, post more of the MIME message.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Thu, 21 Dec 2006 13:05:03 -0600, b. dougherty
<au****************@austin.rr.comwrote:
>Greetings all- I am trying to extract subject headers from emails that
have been saved as text files. The subject headers are in MIME UTF-8
format, and so they appear like this:

subject:
=?utf-8?B?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW 5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21i czsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=

What class can I use to decode the subject text?
Dec 21 '06 #2

P: n/a
Sorry, it appears to be a message header extension, formatted as
described in section 4.1 of this:

http://tools.ietf.org/html/rfc2047

Any idea what class can decode this? Here's a larger snippet of the
mail:

--------------------------------------------------------------------

Content-Type: message/rfc822

Received: from SERVER ([x.x.x.x]) by x.com with Microsoft
SMTPSVC(6.0.3790.1830);
Wed, 13 Dec 2006 22:12:17 -0800
mime-version: 1.0
from: "User" <ma****@x.com>
to: y@y.com
date: 13 Dec 2006 22:12:17 -0800
subject:
=?utf-8?B?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW 5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21i czsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=
content-type: multipart/mixed;
boundary=--boundary_54358_dc8ddb80-9498-4b90-8e3e-3d2c411a5160

--------------------------------------------------------------------

On Thu, 21 Dec 2006 17:35:05 -0500, Samuel R. Neff
<sa********@nomail.comwrote:
>
That's not MIME format. MIME provides separation of message parts and
embedding of messages within other messages.

That's probably base64 or uuencode or something like that, not sure
exactly. The MIME header should have an encoding line which says what
encoding is used for the rest of the message. Most commonly MIME
messages are encoded with Quoted-Printable for text and Base64 for
binary. QP looks pretty much just like regular text with a lot of
extra = signs.

If this isn't enough info, post more of the MIME message.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Thu, 21 Dec 2006 13:05:03 -0600, b. dougherty
<au****************@austin.rr.comwrote:
>>Greetings all- I am trying to extract subject headers from emails that
have been saved as text files. The subject headers are in MIME UTF-8
format, and so they appear like this:

subject:
=?utf-8?B?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW 5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21i czsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=

What class can I use to decode the subject text?
Dec 21 '06 #3

P: n/a
b. dougherty wrote:
Greetings all- I am trying to extract subject headers from emails that
have been saved as text files. The subject headers are in MIME UTF-8
format, and so they appear like this:

subject:
=?utf-8?B?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW 5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21i czsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=

What class can I use to decode the subject text?
Try this:

public static string Decode(string s)
{
MatchCollection rr = Regex.Matches(s,
@"(?:=\?)([^\?]+)(?:\?B\?)([^\?]*)(?:\?=)");
string charset = rr[0].Groups[1].Value;
string data = rr[0].Groups[2].Value;
byte[] b = Convert.FromBase64String(data);
string res = Encoding.GetEncoding(charset).GetString(b);
return res;
}

Arne

Dec 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.