获取的内容字符串:Received: from test ([127.0.0.1]) by test with Microsoft SMTPSVC(6.0.3790.1830);
Mon, 25 Jul 2005 16:14:34 +0800
Date: Mon, 25 Jul 2005 16:14:34 +0800
From: "a" <[email protected]>
To: "l" <[email protected]>
Subject: u have hanppy
X-mailer: Foxmail 5.0 [cn]
Mime-Version: 1.0
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: base64
Return-Path: [email protected]
Message-ID: <TESTPswmOgwyX00000001@test>
X-OriginalArrivalTime: 25 Jul 2005 08:14:34.0890 (UTC) FILETIME=[E46E1EA0:01C590F0]bGl1ZGijrMT6usOjoQ0KDQoJICAgICAgICAgICBiZ2dnZw0KDQqhoaGhoaGhoaGhoaGhoaGh1sIN
CsDxo6ENCiAJCQkJDQoNCqGhoaGhoaGhoaGhoaGhoaFqaWFqaA0KoaGhoaGhoaGhoaGhoaGhoWpp
YWpoQGFuY2NuZXQuY29tDQqhoaGhoaGhoaGhoaGhoaGhoaGhoTIwMDUtMDctMjUNCg==
Mon, 25 Jul 2005 16:14:34 +0800
Date: Mon, 25 Jul 2005 16:14:34 +0800
From: "a" <[email protected]>
To: "l" <[email protected]>
Subject: u have hanppy
X-mailer: Foxmail 5.0 [cn]
Mime-Version: 1.0
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: base64
Return-Path: [email protected]
Message-ID: <TESTPswmOgwyX00000001@test>
X-OriginalArrivalTime: 25 Jul 2005 08:14:34.0890 (UTC) FILETIME=[E46E1EA0:01C590F0]bGl1ZGijrMT6usOjoQ0KDQoJICAgICAgICAgICBiZ2dnZw0KDQqhoaGhoaGhoaGhoaGhoaGh1sIN
CsDxo6ENCiAJCQkJDQoNCqGhoaGhoaGhoaGhoaGhoaFqaWFqaA0KoaGhoaGhoaGhoaGhoaGhoWpp
YWpoQGFuY2NuZXQuY29tDQqhoaGhoaGhoaGhoaGhoaGhoaGhoTIwMDUtMDctMjUNCg==
{
static void Main()
{
byte [] binaryData;
string base64String = "bGl1ZGijrMT6usOjoQ0KDQoJICAgICAgICAgICBiZ2dnZw0KDQqhoaGhoaGhoaGhoaGhoaGh1sINCsDxo6ENCiAJCQkJDQoNCqGhoaGhoaGhoaGhoaGhoaFqaWFqaA0KoaGhoaGhoaGhoaGhoaGhoWppYWpoQGFuY2NuZXQuY29tDQqhoaGhoaGhoaGhoaGhoaGhoaGhoTIwMDUtMDctMjUNCg==";
try
{
binaryData = System.Convert.FromBase64String(base64String);
}
catch (System.ArgumentNullException)
{
System.Console.WriteLine("Base 64 string is null.");
return;
}
catch (System.FormatException)
{
System.Console.WriteLine("Base 64 string length is not 4 or is not an even multiple of 4." );
return;
} System.Text.Encoding encode = System.Text.Encoding.UTF8;
char[] chars = new char[encode.GetCharCount(binaryData, 0, binaryData.Length)];
encode.GetChars(binaryData, 0, binaryData.Length, chars, 0);
string text = new string(chars);
System.Console.WriteLine(text);
}
}/*
程序输出是:
liudh? bggggjiajh
[email protected]
2005-07-25
*/
using System.Text;class MailToText
{
static void Main()
{
string s0 = @"
Received: from test ([127.0.0.1]) by test with Microsoft SMTPSVC(6.0.3790.1830);
Mon, 25 Jul 2005 16:14:34 +0800
Date: Mon, 25 Jul 2005 16:14:34 +0800
From: 'a' <[email protected]>
To: 'l' <[email protected]>
Subject: u have hanppy
X-mailer: Foxmail 5.0 [cn]
Mime-Version: 1.0
Content-Type: text/plain;
charset='gb2312'
Content-Transfer-Encoding: base64
Return-Path: [email protected]
Message-ID: <TESTPswmOgwyX00000001@test>
X-OriginalArrivalTime: 25 Jul 2005 08:14:34.0890 (UTC) FILETIME=[E46E1EA0:01C590F0]bGl1ZGijrMT6usOjoQ0KDQoJICAgICAgICAgICBiZ2dnZw0KDQqhoaGhoaGhoaGhoaGhoaGh1sIN
CsDxo6ENCiAJCQkJDQoNCqGhoaGhoaGhoaGhoaGhoaFqaWFqaA0KoaGhoaGhoaGhoaGhoaGhoWpp
YWpoQGFuY2NuZXQuY29tDQqhoaGhoaGhoaGhoaGhoaGhoaGhoTIwMDUtMDctMjUNCg==
";
string NewLine = Environment.NewLine; // "\r\n"
int i = s0.LastIndexOf(NewLine + NewLine);
if (i == -1)
{
NewLine = "\n";
i = s0.LastIndexOf(NewLine + NewLine);
}
if (i == -1) return;
string s1 = s0.Substring(0, i);
string s2 = Base64ToText(s0.Substring(i), Encoding.UTF8);
string s = string.Format("{0}{1}{1}{2}", s1, NewLine, s2);
Console.WriteLine(s);
} static string Base64ToText(string base64String, Encoding code)
{
byte [] bs;
try
{
bs = Convert.FromBase64String(base64String);
}
catch (ArgumentNullException)
{
return "Base 64 string is null.";
}
catch (FormatException)
{
return "Base 64 string length is not 4 or is not an even multiple of 4.";
} char [] chars = new char [code.GetCharCount(bs, 0, bs.Length)];
code.GetChars(bs, 0, bs.Length, chars, 0);
return new string(chars);
}
}/*
程序输出是:Received: from test ([127.0.0.1]) by test with Microsoft SMTPSVC(6.0.3790.1830);
Mon, 25 Jul 2005 16:14:34 +0800
Date: Mon, 25 Jul 2005 16:14:34 +0800
From: 'a' <[email protected]>
To: 'l' <[email protected]>
Subject: u have hanppy
X-mailer: Foxmail 5.0 [cn]
Mime-Version: 1.0
Content-Type: text/plain;
charset='gb2312'
Content-Transfer-Encoding: base64
Return-Path: [email protected]
Message-ID: <TESTPswmOgwyX00000001@test>
X-OriginalArrivalTime: 25 Jul 2005 08:14:34.0890 (UTC) FILETIME=[E46E1EA0:01C590F0]liudh? bggggjiajh
[email protected]
2005-07-25
*/
Received: from test ([127.0.0.1]) by test with Microsoft SMTPSVC(6.0.3790.1830);
Mon, 25 Jul 2005 16:14:34 +0800
Date: Mon, 25 Jul 2005 16:14:34 +0800
From: ""a"" <[email protected]>
To: ""l"" <[email protected]>
Subject: u have hanppy
X-mailer: Foxmail 5.0 [cn]
Mime-Version: 1.0
Content-Type: text/plain;
charset=""gb2312""
Content-Transfer-Encoding: base64
Return-Path: [email protected]
Message-ID: <TESTPswmOgwyX00000001@test>
X-OriginalArrivalTime: 25 Jul 2005 08:14:34.0890 (UTC) FILETIME=[E46E1EA0:01C590F0]bGl1ZGijrMT6usOjoQ0KDQoJICAgICAgICAgICBiZ2dnZw0KDQqhoaGhoaGhoaGhoaGhoaGh1sIN
CsDxo6ENCiAJCQkJDQoNCqGhoaGhoaGhoaGhoaGhoaFqaWFqaA0KoaGhoaGhoaGhoaGhoaGhoWpp
YWpoQGFuY2NuZXQuY29tDQqhoaGhoaGhoaGhoaGhoaGhoaGhoTIwMDUtMDctMjUNCg==
";