读邮件,1:解码quoted-printable
C# 解quoted-printable编码的方法
private string DecodeQP(string code,string charset)
{
ArrayList aryBytes = new ArrayList();
char ch;
int i = 0;
while (i < code.Length)
{
ch = code[i];
if (ch == \’=\’)
{
if (code.Substring(i, 3) == “=\r\n”)
{
i += 3;
}
else
{
string tmp = code.Substring(i + 1, 2);
aryBytes.Add((byte)int.Parse(tmp, System.Globalization.NumberStyles.HexNumber));
i += 3;
}
}
else
{
aryBytes.Add((byte)ch);
i++;
}
}
byte[] decodeBytes = new byte[aryBytes.Count];
for (int j = 0; j < aryBytes.Count; j++)
{
decodeBytes[j] = (byte)aryBytes[j];
}
//string decode = Encoding.Default.GetString(decodeBytes);
string decode=Encoding.GetEncoding(charset).GetString(decodeBytes);
return decode;
}