登录 用户中心() [退出] 后台管理 注册
 

热门搜索:
您的位置:首页 >> 马上代码 >> 马上代码 >> 主题: 邮件中常见的 Quoted Printable 解码
标题 邮件中常见的 Quoted Printable 解码
clq
浏览(1803) 2006-08-07 22:48:42 发表 编辑

关键字:

--------------------------------------------------
从一个C语言的版本改进而来,还是有很多要注意的地方,所以还是值得在这里保存一个备份的 :) 有空再把那个 C 语言的版本找出来给大家。 [mail2000中自带的那个版本速度实在是太慢了,那个解码一封信居然要几分钟,也许它以为标题才会使用这种编码方式]
--------------------------------------------------
//clq 参考了一个c语言的算法
function DecodeQuoted(pSrc:pchar):string;
var
  nDstLen:integer;     // 输出的字符计数
  i:integer;
  Dst:string;
  pDst:pchar;
  nSrcLen:integer;
  b : Byte;
  Hex:string;

begin
  i := 0;
  nDstLen := 0;
  nSrcLen := length(pSrc);
  setlength(Dst, nSrcLen);//先分配空间
  pDst := pchar(Dst);

  while (i < nSrcLen) do
  begin
    //if (strncmp(pSrc, "=\r\n", 3) == 0)     // 软回车,跳过
    if (StrLComp(pSrc, '='#13#10, 3) = 0) then     // 软回车,跳过
    begin
        pSrc := pSrc+3;
        i := i+3;
    end
    else
    if (StrLComp(pSrc, '='#13, 2) = 0) then     // 软回车,跳过
    begin
        pSrc := pSrc+2;
        i := i+2;
    end
    else
    if (StrLComp(pSrc, '='#10, 2) = 0) then     // 软回车,跳过
    begin
        pSrc := pSrc+2;
        i := i+2;
    end
    else
    begin
        //if (pSrc[0] = '=') then     // 是编码字节
        //if (pSrc[0] = '=')and(StrToIntDef('$'+pSrc[1]+pSrc[2], -1)<>-1) then     // 是编码字节
        //注意容错,字符串长度,是否可转换等
        if (pSrc[0] = '=')and(StrToIntDef('$'+pSrc[1]+pSrc[2], -1)<>-1)and(i+2 < nSrcLen) then
        begin
          //sscanf(pSrc, "=%02X", pDst);
          //sscanf(pSrc, "=%02X", pDst);
          //pDst++;
          Hex := pSrc[1]+pSrc[2];
          b := StrToInt('$'+Hex);
          pDst^ := char(b);
          pDst := pDst+1;
          pSrc := pSrc+3;
          i := i+3;
        end
        else     // 非编码字节
        begin
          pDst^ := pSrc^;
          pDst := pDst+1;
          pSrc := pSrc+1;
          i := i+1;
        end
        //nDstLen := nDstLen+1;
    end;
  end;
  // 输出加个结束符
  pDst^ := #0;
  //return nDstLen;
  //result := Dst;
  result := pchar(Dst);//一定要这样,去掉后面的多余字符
end;

clq
2006-8-7 22:51:48 发表 编辑

今天找它时还以为丢掉了,吓我一跳。毕竟有些细节是锤炼了蛮多情况才弄好的。虽然我得到的原始算法比较简单。

总数:1 页次:1/1 首页 尾页  


发表评论:
文本/html模式切换 插入图片 文本/html模式切换


附件:




Copyright © 2005-2012 CLQ工作室, All Rights Reserved

CLQ工作室 版权所有