Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Internet (https://www.clubdelphi.com/foros/forumdisplay.php?f=3)
-   -   Error con asunto al usar Indy =?UTF-8? (https://www.clubdelphi.com/foros/showthread.php?t=85232)

MAXIUM 18-02-2014 22:10:10

Error con asunto al usar Indy =?UTF-8?
 
Hola, Al leer el asunto de un correo, en algunos mensajes me sale por ejemplo: =?utf-8?Q?AW:_Neues_Projekt_Sch=C3=BCrn_Warenwirtschaft_ ?=

Uso DElphi 7 e Indy 10

Gracias

MAXIUM 20-02-2014 18:18:46

Solución:

Código Delphi [-]
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;

Casimiro Notevi 20-02-2014 19:36:22

^\||/^\||/^\||/


La franja horaria es GMT +2. Ahora son las 18:41:10.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi