开发者

POP3 mail encoding

I am trying to print an email into a file and all i'm getting is this. How could i parse the message body into ascii?

Mime-Version: 1.0
Content-Type: text/plain; 
    charset="utf-8"
Content-Transfer-Encoding: base64
X-Spam-Status: No, hits=0.2 required=5.0 tests=AWL,NO_REAL_NAME autolearn=no 
    version=2.64
Status:   
DQpNZXNzYWdlIG1lZXRzIEFsZXJ0IGNvbmRpdGlvbg0KMjAxMC0wOC0xMCAxNTozODoxNiBkZXZp
Y2VfaWQ9RkcxMDBBMzkwNzUwNzAwOCBsb2dfaWQ9MDEwNDAzM开发者_开发问答jAwNSB0eXBlPWV2ZW50IHN1YnR5
cGU9YWRtaW4gcHJpPWFsZXJ0IHVzZXI9InJvb3QiIHVpPVNTSCg0MS4yMzcuMTA2LjI1MCkgYWN0


The message contents are base64 encoded. If you decode it, you will get the following result:

Message meets Alert condition 2010-08-10 15:38:16 device_id=FG100A3907507008 log_id=0104032005 type=event subtype=admin pri=alert user="root" ui=SSH(41.237.106.250) act

Heres an example of a base64 decode method:

public string DecodeBase64(string str)
{
   byte[] buff = Convert.FromBase64String(str);
   return System.Text.Encoding.UTF8.GetString(buff);
}

Edit: Here's a method for decoding message contents only. I haven't tested it, but pretty sure it'll do the trick.

public static string DecodeEmail(string contents)
{
    string[] delimiter = new string[] { "Status:" };
    string base64string = contents.Split(delimiter, StringSplitOptions.None)[1];
    return DecodeBase64(base64string);
}


The message is encoded using Base64. You can get example code to invoke a C# Base 64 decoder here.

Base 64 encoding commonly used for e-mail MIME document encoding is more fully described in RFC 3548

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜