找回密码
 加入
搜索
查看: 2537|回复: 3

[AU3基础] 请教126邮件编码的问题

[复制链接]
发表于 2010-6-23 22:43:49 | 显示全部楼层 |阅读模式
用POP3下载126邮件,得到如下编码,请教高手指点一下,如何才能解这类编码?谢谢!
<table width=3D"618" border=3D"0" align=3D"center" cellpadding=3D"0" cellsp=
acing=3D"0">
=09<tr>
=09=09<td height=3D"115" background=3D"http://mimg.126.net/xm/all/sms/safe/=
091126/img/post_top5_2_126.jpg">&nbsp;</td>
=09</tr>
=09<tr>
=09=09<td background=3D"http://mimg.126.net/xm/all/sms/safe/091126/img/post=
_bg.jpg" style=3D"padding:35px; font-size:14px; line-height:160%">
=09=09=09<div>=E5=B0=8A=E6=95=AC=E7=9A=84=E9=82=AE=E7=AE=B1=E7=94=A8=E6=88=
=B7=EF=BC=9A</div>
=09=09=09<p style=3D" text-indent:2em">
=09=09=09=09=E6=84=9F=E8=B0=A2=E6=82=A8=E9=80=89=E6=8B=A9=E4=BD=BF=E7=94=A8=
=E7=BD=91=E6=98=93=E9=82=AE=E7=AE=B1=EF=BC=81=E6=82=A8=E7=8E=B0=E5=B7=B2=E8=
=8E=B7=E5=BE=97<strong>=E5=85=8D=E8=B4=B9=E4=BD=BF=E7=94=A8=E2=80=9C=E9=9A=
 楼主| 发表于 2010-6-27 14:17:09 | 显示全部楼层
本帖最后由 论坛管理员 于 2010-6-27 14:19 编辑

Quoted-Printable编码原理是把一个8bit的字符用两个16进制数值表示,然后在前面加“=”。所以我们看到经过QP编码后的文件通常是这个样子:=B3=C2=BF=A1=C7=E5=A3= AC=C4=FA=BA=C3=A3=A1。

Quoted -printable根据输入的字符串或字节范围进行编码,若是不需编码的字符,直接输出。若需要编码,则先输出'=',后面跟着以2个字符表示的十六进制字节值。有的场合,以“=?charset?Q?xxxxxxxx?=”表示xxxxxxxx是Quoted-printable编码,且原文的字符集是charset。在段体内则直接编码,适当时机换行,换行前额外输出一个'='。

详细出处参考:http://www.jb51.net/web/25072.html

提供一下网络搜索到的参考代码,请高人帮忙弄个解码UDF出来,谢谢!

代码参考1:
        Public Function HexDecode(ByVal p_sIn As String) As String
     Dim a As Integer
     Dim sOut As String

     If (Len(p_sIn) = 0) Then Exit Function

     For a = 1 To Len(p_sIn) Step 4
     sOut = sOut & Chr(CInt("&H" & Mid(p_sIn, a, 4)))
     Next a

     HexDecode = sOut
    End Function
 楼主| 发表于 2010-6-27 14:17:49 | 显示全部楼层
代码参考2:

C# Quoted-Printable编码、解码
# using System; 
# using System.Collections; 
# using System.Text; 
# 
# /// <summary> 
# /// Class for encoding and decoding a string to QuotedPrintable 
# /// RFC 1521 http://www.ietf.org/rfc/rfc1521.txt 
# /// RFC 2045 http://www.ietf.org/rfc/rfc2045.txt 
# /// Date: 2006-03-23 
# /// Author: Kevin Spaun 
# /// Company: SPAUN Informationstechnik GmbH - http://www.spaun-it.com/ 
# /// Feedback: kspaun@spaun-it.de 
# /// License: This piece of code comes with no guaranties. You can use it for whatever you want for free. 
# /// 
# /// Modified by Will Huang ( http://blog.miniasp.com/post/2008/02/14/Quoted-Printable-Encoding-and-Decoding.aspx ) 
# /// Modified at 2008-02-13 
# /// 
# /// Modified by reterry (http://www.jb51.net) 
# /// Modified at 2008-11-29 
# /// Modified for MySelf 
# /// 
# /// </summary> 
# public class QuotedPrintable 
# { 
# private const byte EQUALS = 61; 
# private const byte CR = 13; 
# private const byte LF = 10; 
# private const byte SPACE = 32; 
# private const byte TAB = 9; 
# 
# /// <summary> 
# /// Encodes a string to QuotedPrintable 
# /// </summary> 
# /// <param name="_ToEncode">String to encode</param> 
# /// <returns>QuotedPrintable encoded string</returns> 
# public static string Encode(string _ToEncode) 
# { 
# StringBuilder Encoded = new StringBuilder(); 
# string hex = string.Empty; 
# //byte[] bytes = Encoding.Default.GetBytes(_ToEncode); 
# byte[] bytes = Encoding.UTF8.GetBytes(_ToEncode); 
# //int count = 0; 
# 
# for (int i = 0; i < bytes.Length; i++) 
# { 
# //these characters must be encoded 
# if ((bytes[i] < 33 || bytes[i] > 126 || bytes[i] == EQUALS) && bytes[i] != CR && bytes[i] != LF && bytes[i] != SPACE) 
# { 
# if (bytes[i].ToString("X").Length < 2) 
# { 
# hex = "0" + bytes[i].ToString("X"); 
# Encoded.Append("=" + hex); 
# } 
# else 
# { 
# hex = bytes[i].ToString("X"); 
# Encoded.Append("=" + hex); 
# } 
# } 
# else 
# { 
# //check if index out of range 
# if ((i + 1) < bytes.Length) 
# { 
# //if TAB is at the end of the line - encode it! 
# if ((bytes[i] == TAB && bytes[i + 1] == LF) || (bytes[i] == TAB && bytes[i + 1] == CR)) 
# { 
# Encoded.Append("=0" + bytes[i].ToString("X")); 
# } 
# //if SPACE is at the end of the line - encode it! 
# else if ((bytes[i] == SPACE && bytes[i + 1] == LF) || (bytes[i] == SPACE && bytes[i + 1] == CR)) 
# { 
# Encoded.Append("=" + bytes[i].ToString("X")); 
# } 
# else 
# { 
# Encoded.Append(System.Convert.ToChar(bytes[i])); 
# } 
# } 
# else 
# { 
# Encoded.Append(System.Convert.ToChar(bytes[i])); 
# } 
# } 
# //if (count == 75) 
# //{ 
# // Encoded.Append("=\r\n"); //insert soft-linebreak 
# // count = 0; 
# //} 
# //count++; 
# } 
# 
# return Encoded.ToString(); 
# } 
# 
# /// <summary> 
# /// Decodes a QuotedPrintable encoded string 
# /// </summary> 
# /// <param name="_ToDecode">The encoded string to decode</param> 
# /// <returns>Decoded string</returns> 
# public static string Decode(string _ToDecode) 
# { 
# //remove soft-linebreaks first 
# //_ToDecode = _ToDecode.Replace("=\r\n", ""); 
# 
# char[] chars = _ToDecode.ToCharArray(); 
# 
# byte[] bytes = new byte[chars.Length]; 
# 
# int bytesCount = 0; 
# 
# for (int i = 0; i < chars.Length; i++) 
# { 
# // if encoded character found decode it 
# if (chars[i] == '=') 
# { 
# bytes[bytesCount++] = System.Convert.ToByte(int.Parse(chars[i + 1].ToString() + chars[i + 2].ToString(), System.Globalization.NumberStyles.HexNumber)); 
# 
# i += 2; 
# } 
# else 
# { 
# bytes[bytesCount++] = System.Convert.ToByte(chars[i]); 
# } 
# } 
# 
# //return System.Text.Encoding.Default.GetString(bytes, 0, bytesCount); 
# return System.Text.Encoding.UTF8.GetString(bytes, 0, bytesCount); 
# } 
# }
发表于 2010-6-28 01:28:19 | 显示全部楼层
楼主曲高和寡啊
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 08:54 , Processed in 0.078488 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表