我用的是MIME,影響了附件的內容啊

解决方案 »

  1.   

    解码过后就对了
    function EncodeQuotedP(Source:string):string;
      function dQP1(bt:Byte):string;
      var
        str:string;
      begin
        setlength(str,5);
        str:=Format('%X',[bt]);
        if Length(str)=1 then
          str:='0'+str;
        str:='='+str;
        dQP1:=str;
      end;
      function dQP0(bt:Byte):string;
      begin
        dQP0:='='+IntToHex(bt,2);
      end;
    var
      i,LenStr:Integer;
      tStr:string;
    begin
      LenStr:=Length(Source);
      SetLength(tStr,3*LenStr+3);
      tStr:='';
      for i:=1 to LenStr do
      begin
        case Source[i] of
          '!'..'<','>'..'~':
            tStr:=tStr+Source[i];
          else
            tStr:=tStr+dQP0(ord(Source[i]));
        end;
      end;
      EncodeQuotedP:=tStr;
    end;function DecodeQuotedP(Source:string):string;
    var
      sStr:string;
      tStr:string;
      function qCov(subStr:string):Char;
      var
        Tmp:Integer;
        function CtoI(C:Char):Integer;
        var
          Retn:Integer;
        begin
          case C of
            '0':Retn:=0;
            '1':Retn:=1;
            '2':Retn:=2;
            '3':Retn:=3;
            '4':Retn:=4;
            '5':Retn:=5;
            '6':Retn:=6;
            '7':Retn:=7;
            '8':Retn:=8;
            '9':Retn:=9;
            'A':Retn:=10;
            'B':Retn:=11;
            'C':Retn:=12;
            'D':Retn:=13;
            'E':Retn:=14;
            'F':Retn:=15;
            else
              Retn:=0;
          end;
          CtoI:=Retn;
        end;
      begin
        if Pos('=',subStr)>0 then
          Delete(subStr,1,1);
        subStr:=UpperCase(subStr);
        if Length(subStr)=2 then
        begin
          Tmp:=CtoI(subStr[1])*16+CtoI(subStr[2]);
          qCov:=Char(Tmp);
        end
        else
          qCov:=#0;
      end;
    begin
      SetLength(sStr,10);
      SetLength(tStr,200);
      tStr:='';
    While Source<>'' do
    begin
        if Source[1]='=' then
        begin
          sStr:=MidStr(Source,1,3);
          tStr:=tStr+qCov(sStr);
          Delete(Source,1,3);
        end
        else
        begin
          tStr:=tStr+Source[1];
          delete(Source,1,1);
      end;
    end;
      DecodeQuotedP:=tStr;
    end;function DecodeBase64(Source:string):string;
    var
      i,ForI:Integer;
      X1,X2,X3:Char;
      Y1,Y2,Y3,Y4:Char;
      function ISHB(CHA:Char):Byte;
      begin
        case CHA of
          'A'..'Z':
            ISHB:=Ord(CHA)-Ord('A');
          'a'..'z':
            ISHB:=Ord(CHA)-Ord('a')+26;
          '0'..'9':
            ISHB:=ord(CHA)-Ord('0')+52;
          '+':
            ISHB:=62;
          '/':
            ISHB:=63;
          else
          begin
            ShowMessage('Err Char ! ');
            ISHB:=255;
          end;
        end;
      end;
    begin
      Result:='';
      if (Length(Source) mod 4) <> 0 then
      begin
        ShowMessage('Err length in ('+Source+')');
        exit;
      end;
      ForI:=Length(Source) div 4;
      for i:=0 to ForI-1 do
      begin
        Y1:=Source[i*4+1];
        Y2:=Source[i*4+2];
        Y3:=Source[i*4+3];
        Y4:=Source[i*4+4];
        if (Y3='=') and (Y4='=') then
        begin
          X1:=char(((ISHB(Y1) shl 2) and 252) or ((ISHB(Y2) shr 4) and 3));
          x2:=#0;
          x3:=#0;
        end else if (y4='=') then
        begin
          X1:=Char(((ISHB(Y1) shl 2) and 252) or ((ISHB(Y2) shr 4) and 3));
          X2:=Char(((ISHB(Y2) shl 4) and 240) or ((ISHB(Y3) shr 2) and 15));
          X3:=#0;
        end
        else
        begin
          X1:=Char(((ISHB(Y1) shl 2) and 252) or ((ISHB(Y2) shr 4) and 3));
          X2:=Char(((ISHB(Y2) shl 4) and 240) or ((ISHB(Y3) shr 2) and 15));
          X3:=Char(((ISHB(Y3) shl 6) and 192) or (ISHB(Y4) and 63));
        end;
        Result:=Result+X1+X2+X3;
      end;
    end;procedure DeleteTempFile(PathName:string);
    var
      pn:string;
      sr: TSearchRec;
    begin
      pn:=trim(PathName);
      if pn[length(pn)]<>'\' then
        pn:=pn+'\';
      if FindFirst(pn+'*.mme', faAnyFile, sr) = 0 then
      begin
        DeleteFile(PathName+sr.Name);
        while FindNext(sr) = 0 do
        begin
          DeleteFile(PathName+sr.Name);
        end;
        FindClose(sr);
      end;
    end;
      

  2.   

    用DecodeBase64、DecodeQuotedP,具体原理就查查TCP/IP协议的书吧
      

  3.   

    to  TangDL(Wo~~~~~~~~~~)
      我不是很明白,難道是我把附件存下來後,再對附件解碼啊?但是我只是在有的機器上不太對,而且文件基本上是對的,只不過多了幾個字節,比如原來是1981bytes,之後變為2002bytes