1.邮件标题中有汉字,收下来是乱码,如何解决?
2.如何得到邮件大小,制作进度条?

解决方案 »

  1.   

    1.收下来得是乱码是因为字符串都经过了base64编码或者utf8编码
    base64编码解码得程序
    function Base64ToString(const Value : string): string;
    var
      x, y, n, l: Integer;
      d: array[0..3] of Byte;
      Table : string;
    begin
      Table :=
        #$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$3E +#$40
        +#$40 +#$40 +#$3F +#$34 +#$35 +#$36 +#$37 +#$38 +#$39 +#$3A +#$3B +#$3C
        +#$3D +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40 +#$00 +#$01 +#$02 +#$03
        +#$04 +#$05 +#$06 +#$07 +#$08 +#$09 +#$0A +#$0B +#$0C +#$0D +#$0E +#$0F
        +#$10 +#$11 +#$12 +#$13 +#$14 +#$15 +#$16 +#$17 +#$18 +#$19 +#$40 +#$40
        +#$40 +#$40 +#$40 +#$40 +#$1A +#$1B +#$1C +#$1D +#$1E +#$1F +#$20 +#$21
        +#$22 +#$23 +#$24 +#$25 +#$26 +#$27 +#$28 +#$29 +#$2A +#$2B +#$2C +#$2D
        +#$2E +#$2F +#$30 +#$31 +#$32 +#$33 +#$40 +#$40 +#$40 +#$40 +#$40 +#$40;  SetLength(Result, Length(Value));
      x := 1;
      l := 1;
      while x < Length(Value) do
      begin
        for n := 0 to 3 do
        begin
          if x > Length(Value) then
            d[n] := 64
          else
          begin
            y := Ord(Value[x]);
            if (y < 33) or (y > 127) then
              d[n] := 64
            else
              d[n] := Ord(Table[y - 32]);
          end;
          Inc(x);
        end;
        Result[l] := Char((D[0] and $3F) shl 2 + (D[1] and $30) shr 4);
        Inc(l);
        if d[2] <> 64 then
        begin
          Result[l] := Char((D[1] and $0F) shl 4 + (D[2] and $3C) shr 2);
          Inc(l);
          if d[3] <> 64 then
          begin
            Result[l] := Char((D[2] and $03) shl 6 + (D[3] and $3F));
            Inc(l);
          end;
        end;
      end;
      Dec(l);
      SetLength(Result, l);
    end;function StringToBase64(const Value: string): string;
    var
      c: Byte;
      n, l: Integer;
      Count: Integer;
      DOut: array[0..3] of Byte;
      Table : string;
    begin
      Table :=
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';  setlength(Result, ((Length(Value) + 2) div 3) * 4);
      l := 1;
      Count := 1;
      while Count <= Length(Value) do
      begin
        c := Ord(Value[Count]);
        Inc(Count);
        DOut[0] := (c and $FC) shr 2;
        DOut[1] := (c and $03) shl 4;
        if Count <= Length(Value) then
        begin
          c := Ord(Value[Count]);
          Inc(Count);
          DOut[1] := DOut[1] + (c and $F0) shr 4;
          DOut[2] := (c and $0F) shl 2;
          if Count <= Length(Value) then
          begin
            c := Ord(Value[Count]);
            Inc(Count);
            DOut[2] := DOut[2] + (c and $C0) shr 6;
            DOut[3] := (c and $3F);
          end
          else
          begin
            DOut[3] := $40;
          end;
        end
        else
        begin
          DOut[2] := $40;
          DOut[3] := $40;
        end;
        for n := 0 to 3 do
        begin
          Result[l] := Table[DOut[n] + 1];
          Inc(l);
        end;
      end;
    end;function GetTitle(const Value: string): string;
    var
      iPos: integer;
    begin
      Result := Value;
      if Copy(Value, 1, 2) <> '=?' then exit;
      //'?B?'&Ccedil;°&Atilde;&aelig;&micro;&Auml;&para;&frac14;&Ograve;&ordf;&Egrave;&yen;&micro;&ocirc;
      iPos := Pos('?B?', Value);
      Inc(iPos, 3);
      //×&icirc;&ordm;ó&micro;&Auml;'?='&Ograve;&sup2;&Ograve;&ordf;&Egrave;&yen;&micro;&ocirc;
      Result := Copy(Value, iPos, Length(Value) - iPos - 1);
      Result := Base64ToString(Result);
      //Result := Utf8ToAnsi(Result);
    end;
    2.你可以参看indy带的例子,它上面可以得到邮件的大小
      

  2.   

    indy例子中也没找到的到信件大小,恳请提示!
      

  3.   

    信件大小:  
     int MailSize = idPOP->RetrieveMsgSize(i);
      

  4.   

    中文编码部分,不妨参考本人的BCB解决方案。
    http://expert.csdn.net/Expert/TopicView2.asp?id=1126270
      

  5.   

    邮件大小必须收取信件以后才知道,如果收取不到信件那么就无法得到大小如果想要知道信件大小只有自己写代码了,不用Idpop3控件
      

  6.   

    to 绝望的生鱼片:用你的代码还是没搞定,好像不是base64编码,是mime编码。
    to 空心菜:能不能帮我转换成delphi的语言,谢谢!
      

  7.   

    Delphi我从来没有用过,不会转换,其实原理很简单,主要的Base64和Mine,Q_P解码部分的代码应该有delphi版本,你把我写的两个函数转换一下成Delphi就可以。
      

  8.   

    又:关于信件大小:  
     int MailSize = idPOP->RetrieveMsgSize(i);
    用上面的代码收到的不是邮件的大小吗?
    我用的是Indy9。