呵呵,开玩笑而已,资料找到了,中午我们这里网络暴慢所以没有贴 处理电子邮件要做的工作很多,要了解个叫MIME的标准。你需要看RFC2045,2046,2110,2111,2112等等了解详细情况。要让EMAIL里没有乱码不是件容易的事,有很多种情况需要处理 下面是两种编码方式的解码原代码,在原始数据里有"content-type"标志指示编码方式.如果还有问题再说吧,一时说不完,下班回家打游戏了... ******************************************************************** //解析'BASE64'编码方式的内容 Function DecodeBase64(Const Data:String):String; var i,j:Integer; m,n:array[1..256] of byte; str:string; tmpStringList:TStringList; Ret: String; begin tmpStringList:= TStringList.Create; try tmpStringList.Text:=Data; Ret:=''; for i:=0 to tmpStringList.Count-1 do begin str:=tmpStringList.Strings[i]; for j:=1 to length(str) do begin case str[j] of 'A'..'Z': m[j]:=ord(str[j])-ord('A'); 'a'..'z': m[j]:=ord(str[j])-ord('a')+26; '0'..'9': m[j]:=ord(str[j])-ord('0')+52; '+' : m[j]:=62; '/' : m[j]:=63; '=' : m[j]:=64; end; end; for j:=1 to ((length(str)+3) shr 2) do begin n[3*j-2]:=(m[(j shl 2)-3] shl 2)or(m[(j shl 2)-2] shr 4); n[3*j-1]:=(m[(j shl 2)-2] shl 4)or(m[(j shl 2)-1] shr 2); n[3*j]:=(m[(j shl 2)-1] shl 6)or(m[(j shl 2)]); if m[(j shl 2)-3]=64 then continue; Ret:= Ret+Chr(n[3*j-2]); if m[(j shl 2)-1]=64 then continue; Ret:= Ret+Chr(n[3*j-1]); if m[(j shl 2)]=64 then continue; Ret:= Ret+Chr(n[3*j]); end; end; if Assigned(tmpStringList) then begin tmpStringList.Free; tmpStringList:=nil; end; Except if Assigned(tmpStringList) then begin tmpStringList.Free; tmpStringList:=nil; end; end; Result:=Ret; end;//解析'ISO-8859-1'编码方式的内容 Function DecodeISO(Const Data:String):String; Var DataLen,I,tmpInt:Integer; Ret:String; begin Ret:=''; I:=1; try DataLen:=Length(Data); ProtectCount := 0; While I<=DataLen do begin inc(ProtectCount); if ProtectCount > 5000 then break; if (Data[i]='=')And(I<DataLen-1) then begin try tmpInt:=(HextoDec(Data[i+1]) shl 4)+HextoDec(Data[i+2]); Ret:= Ret+Chr(tmpInt); i:=i+3; except end; end else begin Ret:= Ret+Data[i]; I:=I+1; end; end; except end; Result:=Ret; end;
处理电子邮件要做的工作很多,要了解个叫MIME的标准。你需要看RFC2045,2046,2110,2111,2112等等了解详细情况。要让EMAIL里没有乱码不是件容易的事,有很多种情况需要处理
下面是两种编码方式的解码原代码,在原始数据里有"content-type"标志指示编码方式.如果还有问题再说吧,一时说不完,下班回家打游戏了...
********************************************************************
//解析'BASE64'编码方式的内容
Function DecodeBase64(Const Data:String):String;
var
i,j:Integer;
m,n:array[1..256] of byte;
str:string;
tmpStringList:TStringList;
Ret: String;
begin
tmpStringList:= TStringList.Create;
try
tmpStringList.Text:=Data;
Ret:='';
for i:=0 to tmpStringList.Count-1 do begin
str:=tmpStringList.Strings[i];
for j:=1 to length(str) do begin
case str[j] of
'A'..'Z': m[j]:=ord(str[j])-ord('A');
'a'..'z': m[j]:=ord(str[j])-ord('a')+26;
'0'..'9': m[j]:=ord(str[j])-ord('0')+52;
'+' : m[j]:=62;
'/' : m[j]:=63;
'=' : m[j]:=64;
end;
end;
for j:=1 to ((length(str)+3) shr 2) do begin
n[3*j-2]:=(m[(j shl 2)-3] shl 2)or(m[(j shl 2)-2] shr 4);
n[3*j-1]:=(m[(j shl 2)-2] shl 4)or(m[(j shl 2)-1] shr 2);
n[3*j]:=(m[(j shl 2)-1] shl 6)or(m[(j shl 2)]);
if m[(j shl 2)-3]=64 then continue;
Ret:= Ret+Chr(n[3*j-2]);
if m[(j shl 2)-1]=64 then continue;
Ret:= Ret+Chr(n[3*j-1]);
if m[(j shl 2)]=64 then continue;
Ret:= Ret+Chr(n[3*j]);
end;
end;
if Assigned(tmpStringList) then begin
tmpStringList.Free;
tmpStringList:=nil;
end;
Except
if Assigned(tmpStringList) then begin
tmpStringList.Free;
tmpStringList:=nil;
end;
end;
Result:=Ret;
end;//解析'ISO-8859-1'编码方式的内容
Function DecodeISO(Const Data:String):String;
Var
DataLen,I,tmpInt:Integer;
Ret:String;
begin
Ret:='';
I:=1;
try
DataLen:=Length(Data);
ProtectCount := 0;
While I<=DataLen do begin
inc(ProtectCount);
if ProtectCount > 5000 then break;
if (Data[i]='=')And(I<DataLen-1) then begin
try
tmpInt:=(HextoDec(Data[i+1]) shl 4)+HextoDec(Data[i+2]);
Ret:= Ret+Chr(tmpInt);
i:=i+3;
except
end;
end
else begin
Ret:= Ret+Data[i];
I:=I+1;
end;
end;
except
end;
Result:=Ret;
end;
现在的问题是如果对方用GB2312发过来时显示不正常。(Body正常,只有Subject不正常)
如:发送时标题是:"爱人解放了"
接收时标题是:"=?GB_2312-80?Q?=B0=AE=C8=CB=BD=E2=B7=C5=C1=CB?="