PC Review


Reply
Thread Tools Rate Thread

Decoding MIME encoded email subject

 
 
b. dougherty
Guest
Posts: n/a
 
      21st Dec 2006
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?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21iczsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=

What class can I use to decode the subject text?

 
Reply With Quote
 
 
 
 
Samuel R. Neff
Guest
Posts: n/a
 
      21st Dec 2006

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
<(E-Mail Removed)> 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?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21iczsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=
>
>What class can I use to decode the subject text?


 
Reply With Quote
 
b. dougherty
Guest
Posts: n/a
 
      21st Dec 2006
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" <(E-Mail Removed)>
to: (E-Mail Removed)
date: 13 Dec 2006 22:12:17 -0800
subject:
=?utf-8?B?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21iczsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=
content-type: multipart/mixed;
boundary=--boundary_54358_dc8ddb80-9498-4b90-8e3e-3d2c411a5160

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



On Thu, 21 Dec 2006 17:35:05 -0500, Samuel R. Neff
<(E-Mail Removed)> wrote:

>
>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
><(E-Mail Removed)> 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?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21iczsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=
>>
>>What class can I use to decode the subject text?


 
Reply With Quote
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      24th Dec 2006
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?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21iczsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=
>
> 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

 
Reply With Quote
 
b. dougherty
Guest
Posts: n/a
 
      24th Dec 2006
Arne, that worked perfectly. Thank you very much!


On Sun, 24 Dec 2006 00:12:31 -0500, Arne Vajhøj <(E-Mail Removed)>
wrote:

>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?QVVUTyBQRU9QTEUgLS0gTWFuaGVpbeKAmXMgSmVmZiBCdW5jaCBpbiBIaWdoYmVhbXM7IExlZ2VuZGFyeSBSZWQgTWNDb21iczsgV2hv4oCZcyBTaGlmdGluZyBHZWFycz87IE1vcmU=?=
>>
>> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
MailMessage & mime encoded SMTP data asnowfall@gmail.com Microsoft C# .NET 2 20th Jan 2006 08:26 PM
decoding MIME attachments? Mad Scientist Jr Microsoft ASP .NET 1 11th Nov 2005 09:15 PM
decoding mime messages =?Utf-8?B?U1BT?= Microsoft Outlook Discussion 1 10th Nov 2005 09:44 PM
Re: Problem with decoding data in Server 2003 which were encoded by OS Steven L Umbach Microsoft Windows 2000 Security 2 26th Jun 2004 05:37 PM
MIME decoding Dwayne Microsoft Dot NET 1 12th Jan 2004 07:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 PM.