我正在開發一個電子郵件查看器,它可以讀取.eml文件並在瀏覽器控件中顯示消息。我找到了代碼片段,它可以顯示7位和帶引號的可打印消息(Content-Transfer-Encoding:quoted-printable/Content-Transfer-Encoding:base64)。 我需要的是解碼8位消息。解碼8位郵件消息:內容傳輸編碼:8位
private static AlternateView ImportText(StringReader r, string encoding, System.Net.Mime.ContentType contentType)
{
string line = string.Empty;
StringBuilder b = new StringBuilder();
while ((line = r.ReadLine())!= null)
{
switch (encoding)
{
case "quoted-printable":
if (line.EndsWith("="))
{
b.Append(DecodeQuotedPrintables(line.TrimEnd('='), contentType.CharSet));
}
else
{
b.Append(DecodeQuotedPrintables(line, contentType.CharSet) + "\n");
}
break;
case "base64":
b.Append(DecodeBase64(line, contentType.CharSet));
break;
case "8bit": // I need an 8bit decoder here!!!
b.Append(IneedAn8bitDecoderHere(line, contentType.CharSet));
break;
default:
b.Append(line);
break;
}
}
AlternateView returnValue = AlternateView.CreateAlternateViewFromString(b.ToString(), null, contentType.MediaType);
returnValue.TransferEncoding = TransferEncoding.QuotedPrintable;
return returnValue;
}
我用Google搜索的8位解碼器,但找不到任何。我真的需要8位解碼器嗎?你知道一個好的工作嗎?
UPDATE:
相關頭:在我的代碼(串線)
MIME-Version: 1.0
Content-Type: text/plain; charset="koi8-r";
Content-Transfer-Encoding: 8bit
體消息:
����������� �� ����, � ����� ��� � ������ ��������� ������� � �������� �������� �� �������
什麼展望顯示在真實世界:
Фантастично но факт, я снова как и раньше сделалась статной и красивой примерно за месяцок
我想我不需要情況下, 「8位」:一部分。正如SLaks提到的那樣,我需要將郵件源加載到字節數組中,而不是在進程的開始時加入字符串。檢查來自字節數組的郵件頭中的字符集=將給出適當的代碼頁。
一旦你讀入一個字符串,爲時已晚。你需要使用適當的'Encoding'來從字節解碼它。 – SLaks
從[Exchange Server 2003:Content-Transfer-Encoding:8bit](http://msdn.microsoft.com/zh-cn/library/ms526992(v = exchg.10).aspx)8位編碼具有相同的行 - 作爲7位編碼的長度限制。它允許8位字符。 8位文件不需要編碼或解碼。由於並非所有MTA都能處理8位數據,所以8位編碼不是Internet郵件的有效編碼機制。 –
這是關於二進制附件,根本不是字符串。 – SLaks