按照论坛上找到的几个方法,对其他的邮件几倍都可以顺利的解码了
可是发现有一个淘宝的注册信,怎么都不行这个邮件的标题源是这样的:
=?utf-8?B?5Lqy54ix55qEIHRpYW54aW5nY2Zw77yM?= =?utf-8?B?5a6M5oiQ5pyA5ZCO5LiA5q2l77yM5oKo?= =?utf-8?B?55qE5rOo5YaM5bCx5oiQ5Yqf5LqG77yB?=最怪异的是,
var 
tmp:String;tmp := IdMessage1.Subject;如果 直接:Memo1.Lines.Add(tmp);
没问题,但是乱码如果 ShowMessage(tmp);
都会报错,好像说内存地址什么的错误我本来想用 ExtractStrings([' '],[],Pchar(tmp),AStrings);
切开这个字符串,来分别解码的,也是不行。求教该怎么做啊??初学 Dlephi,经验不足,望各位大大赐教!!!

解决方案 »

  1.   

    你好,請問你確定 「IdMessage1.Subject」回傳的值是string嗎?還是pchar,謝謝。
      

  2.   

    啊  应该是 string 吧
      

  3.   

    //设置应答内容的类型
        IdHttp.Request.ContentType := 'application/x-www-form-urlencoded';
        //获取论坛数据,由于论坛是UTF8编码的,故此处需转换
        StrData := UTF8ToAnsi(IdHttp.Get(PChar(BBSUrl)));
      

  4.   

    狂晕~~
    就没有兄弟能帮看一下的吗
    Delphi 真的这么冷清啊
      

  5.   

    解决办法有,绝对OK。支持=?gb2312?b? 、 =?gbk?q? 、 =?gbk?b? 、 =?utf-8?q? 、 =?utf-8?b? 五种情况。D7调试通过。
    调用方法:str := Base64Decode(utf8str);
    ======================================================
    function Base64Decode(strInput:string):string;
    begin
      Result := Base64Decode1(strInput);
      while (Pos('=?gb', LowerCase(Result))>0) or (Pos('=?utf', LowerCase(Result))>0) do
         Result := Base64Decode1(Result);
    end;function Base64Decode1(strInput:string):string;
    var
        posGB2312B,posGBKQ,posGBKB,posUTF8Q,posUTF8B:Integer;
        strDecode,strChar,stmp,s2 : string;
        posStart,CharLen : Integer;
        posEnd : Integer;
        IdDecoderMIME1: TIdDecoderMIME;
    begin
        posGB2312B := pos('=?gb2312?b?',lowercase(strInput)); if posGB2312B=0 then posGB2312B := 99999999;
        posGBKQ :=  pos('=?gbk?q?',lowercase(strInput)); if posGBKQ=0 then posGBKQ := 99999999;
        if  posGB2312B < posGBKQ  then begin
           strChar := '=?gb2312?b?';
           CharLen := 11;
        end
        else begin
           strChar := '=?gbk?q?';
           CharLen := 8;
        end;
        posGBKB :=  pos('=?gbk?b?',lowercase(strInput)); if posGBKB=0 then posGBKB := 99999999;
        if (posGBKB< posGB2312B) and ( posGBKB < posGBKQ) then begin
           strChar := '=?gbk?b?';
           CharLen := 8;
        end;
        posUTF8Q :=  pos('=?utf-8?q?',lowercase(strInput)); if posUTF8Q=0 then posUTF8Q := 99999999;
        if (posUTF8Q< posGB2312B) and ( posUTF8Q < posGBKQ) and (posUTF8Q <posGBKB) then begin
           strChar := '=?utf-8?q?';
           CharLen := 10;
        end;
        posUTF8B :=  pos('=?utf-8?b?',lowercase(strInput)); if posUTF8B=0 then posUTF8B := 99999999;
        if (posUTF8B< posGB2312B) and ( posUTF8B < posGBKQ) and (posUTF8B <posGBKB) and (posUTF8B<posUTF8Q) then begin
           strChar := '=?utf-8?b?';
           CharLen := 10;
        end;    IdDecoderMIME1 := TIdDecoderMIME.Create(nil);    try
              while pos(strChar,lowercase(strInput))>0 do begin
                  try
                      posStart:=pos(strChar,lowercase(strInput));
                      posEnd:=posEx('?=',lowercase(strInput),posStart+CharLen);
                      if ('=?utf-8?b?'= strChar)  then
                        strDecode:=strDecode+copy(strInput,1,posStart-1)+ UTF8Decode(DecodeString (copy(strInput,posStart+CharLen,posEnd-posStart-CharLen)))
                      else if  ( '=?gbk?b?'= strChar)  then
                        strDecode:=strDecode+copy(strInput,1,posStart-1)+ DecodeString (copy(strInput,posStart+CharLen,posEnd-posStart-CharLen))
                      else if ( '=?utf-8?q?'= strChar) or ( '=?gbk?q?'= strChar) then begin
                        stmp := copy(strInput,posStart+CharLen,posEnd-posStart-CharLen);
                        stmp := AnsiReplaceStr(stmp,'=','%');
                        stmp :=  AnsiReplaceStr(stmp,'_','+');
                        stmp := HttpDecode( stmp);
                        if ('=?utf-8?q?'= strChar) then
                           stmp := UTF8Decode(stmp);
                        s2 := copy(strInput,1,posStart-1);
                        if Trim(s2)='' then s2 :='';
                        strDecode:=strDecode+ s2 + stmp ;
                      end
                      else
                        strDecode:=strDecode+copy(strInput,1,posStart-1)+ IdDecoderMIME1.DecodeString (copy(strInput,posStart+CharLen,posEnd-posStart-CharLen));
                      strInput:=copy(strInput,posEnd+2,length(strInput)-posEnd-1);
                  finally
                   //   Application.ProcessMessages;
                  end;          end;
        finally
          IdDecoderMIME1.Free;
        end;    strDecode := strDecode + strInput;
        result := strDecode;end;
      

  6.   

    以上需要 uses StrUtils,IdCoderMIME,
         EncdDecd,HTTPApp