邮件解码

很多时候有收到以  ‘=?utf-8?Q?=’或者 ‘?GB2312?B?1qe’开头的信息,那么如何解码呢

以下是函数:目前增加支持 utf-8,BIG5的转换。

Q表示Q编码,B表示B编码。

=============================

uses EncdDecd

=========================

//信息/Subject: =?utf-8?Q?=E5=9B=BD=E9=99=85=E8=B6=B3=E8=81=94=E9=A6=96=E6=AC=BE=E7=BD=91=E6=B8=B8FIFA_OL2=E5=90=AF=E5=8A=A8=E5=85=AC=E6=B5=8B!=E7=8B=82=E9=80=81adidas=E8=A3=85=E5=A4=87=E5=92=8C=E6=B8=B8=E6=88=8F=E6=89=8B=E6=9F=84?=

//翻译结果/Subject: 国际足联首款网游FIFA OL2启动公测!狂送adidas装备和游戏手柄

function sak_ConvertCharSet( const Line : string ) : string;

var
  strToDecode, RestBefore, RestAfter, strActual, decoded,scharset: string;
  iLast, iFirst, eFirst, i: integer;
  Encoding, c: char;
  Dest: TMemoryStream;
begin
  strActual := Line;

  iFirst := Pos( '=?', strActual );
  while (iFirst > 0) do
  begin
    RestBefore := copy( strActual, 1, iFirst-1 );
    strToDecode := copy( strActual, iFirst+2, length( strActual) );
    eFirst := pos( '?', strToDecode);
    if eFirst > 0 then
    begin
      scharset:=UpperCase( Copy(strToDecode,1,eFirst-1));
      Encoding := UpperCase( strToDecode[eFirst+1])[1];
      delete( strToDecode, 1, eFirst + 2);  // remove until ?Q? or ?B? inclusive
      iLast := Pos( '?=', strToDecode );
      if iLast > 0 then
      begin
        RestAfter := copy( strToDecode, iLast+2, length( strToDecode) );
        delete( strToDecode, iLast, length( strToDecode));  // remove the ?= and the rest

        strActual := RestBefore + RestAfter;
        if Encoding = 'Q' then
        begin
           strActual := sak_QuotedPrintableDecode( PChar( strToDecode) ) ;
        end else
        if Encoding = 'B' then
        begin
           strActual := DecodeString(strToDecode) ;
        end;
        if scharset='BIG5' then  strActual:=BIG52GBK(strActual,950,936)//950:BIG5代码表;936:GBK代码表
        else if scharset='UTF-8' then strActual:=UTF8Decode(strActual);

{strActual:=BIG52GBK(strActual,65001,936);//65001:UTF8代码表;936:GBK代码表,但是使用这种办法转换结尾有乱码

}

        strActual := RestBefore + strActual + RestAfter;;
        iFirst := Pos( '=?', strActual );
      end
      else iFirst := 0;
    end
    else iFirst := 0;
  end;
  Result := strActual;
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值