473,769 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Decoding MIME encoded email subject

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?QVVUTyBQRU9 QTEUgLS0gTWFuaG VpbeKAmXMgSmVmZ iBCdW5jaCBpbiBI aWdoYmVhbXM7IEx lZ2VuZGFyeSBSZW QgTWNDb21iczsgV 2hv4oCZcyBTaGlm dGluZyBHZWFycz8 7IE1vcmU=?=

What class can I use to decode the subject text?

Dec 21 '06 #1
3 11022

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?QVVUTyBQRU9 QTEUgLS0gTWFuaG VpbeKAmXMgSmVmZ iBCdW5jaCBpbiBI aWdoYmVhbXM7IEx lZ2VuZGFyeSBSZW QgTWNDb21iczsgV 2hv4oCZcyBTaGlm dGluZyBHZWFycz8 7IE1vcmU=?=

What class can I use to decode the subject text?
Dec 21 '06 #2
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.379 0.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?QVVUTyBQRU9 QTEUgLS0gTWFuaG VpbeKAmXMgSmVmZ iBCdW5jaCBpbiBI aWdoYmVhbXM7IEx lZ2VuZGFyeSBSZW QgTWNDb21iczsgV 2hv4oCZcyBTaGlm dGluZyBHZWFycz8 7IE1vcmU=?=
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********@nom ail.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?QVVUTyBQRU9 QTEUgLS0gTWFuaG VpbeKAmXMgSmVmZ iBCdW5jaCBpbiBI aWdoYmVhbXM7IEx lZ2VuZGFyeSBSZW QgTWNDb21iczsgV 2hv4oCZcyBTaGlm dGluZyBHZWFycz8 7IE1vcmU=?=

What class can I use to decode the subject text?
Dec 21 '06 #3
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?QVVUTyBQRU9 QTEUgLS0gTWFuaG VpbeKAmXMgSmVmZ iBCdW5jaCBpbiBI aWdoYmVhbXM7IEx lZ2VuZGFyeSBSZW QgTWNDb21iczsgV 2hv4oCZcyBTaGlm dGluZyBHZWFycz8 7IE1vcmU=?=

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.FromBas e64String(data) ;
string res = Encoding.GetEnc oding(charset). GetString(b);
return res;
}

Arne

Dec 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3470
by: Thomas Williams | last post by:
Hello everyone, my name is Tom W. And, I am new to the list, and have been using Python for about a year now. Anyway, I got a question! I am trying to decode MIME (base64) email from a POP3 server, but all I get is a corrupt file. I know that it good to begin with because I check it with another email client. This is what I am doing!
1
3738
by: Thomas Williams | last post by:
Thanks, I tried it and it stop at: f = file("mail.txt") with the error message. TypeError: 'str' object is not callable Tom Williams
2
2838
by: David Stockwell | last post by:
snippet payload = {} try: message = email.message_from_string(message) messageHeader = dict(message._headers) addressFrom = messageHeader addressReply = messageHeader.get("Reply-To") messageId = messageHeader.get("Message-ID")
2
3100
by: asnowfall | last post by:
I am trying to build System.Mail.MailMessage object out of mime encoded SMTP data. I have following questions Byte byteMailData; //mime encoded STMP data for "email with attachment" 1) MailMessage.Body = Convert(byteMailData); If I do the above, will MailMessage object extract the Message BODY, Message HEADER and Attachments automatically.
3
8747
by: Laangen_LU | last post by:
Dear Group, my first post to this group, so if I'm on the wrong group, my apologies. I'm trying to send out an email in Chinese lanuage using the mail() function in PHP. Subject and mailbody are stored as Unicode entities (eg. 註)
2
1608
by: gweasel | last post by:
I've got the following code on the "OnClick" event for a command button on a form. ______________________________________ Private Sub EmailNotify_Click() DoCmd.SendObject acSendNoObject, , , "user@company.com", CCFIELD, BCCFIELD, , BODY_HERE, False End Sub ______________________________________
4
17604
by: Ciuin | last post by:
Hi all, I need to mail() emails with user input that does contain non-ascii (umlauts, accents) and non-latin (cyrillic) characters in the "Subject:" and "From:" headers. I understand that they are typically encoded in UTF8 like this: =?UTF-8?B?w5Z0emkg0J/RgNC40LLQtdGC?= but I cannot find a PHP function to encode the input string in this
1
1671
by: praveen2gupta | last post by:
I am working on email server. It is running fine on all English mails. Recently I have converted it to multi language. All laguage are good with in server mail send and received. My Problem is the mails received from gmail in other than english. I am not able to display the subject of the mail received .The body part is ok. charset utf-8 used to display subject and body. the characters stored in the database is Example ...
7
2945
by: Ron Garret | last post by:
I'm writing a little HTTP server and need to parse request content that is mime-encoded. All the MIME routines in the Python standard library seem to have been subsumed into the email package, which makes this operation a little awkward. It seems I have to do the following: 1. Extract the content-length header from the HTTP request and use that to read the payload. 2. Stick some artificial-looking headers onto the beginning of this...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.