在收到163.com等一些邮件的时候 subject 通常是下面的形式,
=?gb2312?B?Z290b21vYmlsZQ==?=
这个翻译过来就是 pic test
只需要一个函数就可以处理好了!indy也就不再残缺了..
//idPop3缺少的只是这部分的处理. Subject
// this function by Chris G黱ther and Sergio Kessler
function ConvertCharSet( const Line : string ) : string;
var
strToDecode, RestBefore, RestAfter, strActual, decoded: string;
iLast, iFirst, eFirst, i: integer;
Encoding, c: char;
b64Decode: TBase64DecodingStream;
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
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 := RestBefore +
sak_QuotedPrintableDecode( PChar( strToDecode) ) +
RestAfter;
end else
if Encoding = 'B' then
begin
Dest := TMemoryStream.Create;
b64Decode := TBase64DecodingStream.Create( Dest);
b64Decode.Write( pointer(strToDecode)^, length( strToDecode));
b64Decode.Free;
decoded := '';
Dest.Position := 0;
for i:= 1 to Dest.Size do
begin
Dest.Read( c, 1);
decoded := decoded + c;
end;
Dest.Free;
strActual := RestBefore + decoded + RestAfter;
end;
iFirst := Pos( '=?', strActual );
end
else iFirst := 0;
end
else iFirst := 0;
end;
Result := strActual;
end;