Uses
IdCoderQuotedPrintable, StrUtils;
function DeleteUTF8ControlStrings(Text: String): String;
var
Encoded : String;
Dump : String;
StartPos : Integer;
EndPos : Integer;
begin
Encoded:='';
Dump:=Text;
while Pos('=?UTF-8',AnsiUpperCase(Dump))<>0 do
begin
StartPos:=Pos('=?UTF-8',AnsiUpperCase(Dump))+10;
EndPos:=Pos('?=',AnsiUpperCase(Dump));
Encoded:=Encoded+Copy(Dump,StartPos,EndPos-StartPos);
Dump:=Encoded+Copy(Dump,EndPos+3,Length(Dump)-(EndPos+2));
end;
Result:=Trim(AnsiReplaceStr(Encoded,'_',' '));
end;
function MailsGetSubject(Subject: String): String;
var
Decoder : TIdDecoderQuotedPrintable;
TextAnsi : String;
begin
Result:=Subject;
if Pos('=?UTF-8',Subject)<>0 then
begin
Decoder:=TIdDecoderQuotedPrintable.Create;
try
Result:=DeleteUTF8ControlStrings(Subject);
Result:=Decoder.DecodeString(Result);
TextAnsi:=UTF8ToAnsi(Result);
if Length(TextAnsi)>0 then Result:=TextAnsi;
finally
FreeAndNil(Decoder);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
Var
Asunto: String;
Begin
...
...
...
Asunto:= MailsGetSubject(IdMessage1.Subject);
...
...
...
End;