Текст сообщения (Indy)
for i:=1 to IdPOP31.CheckMessages do
begin
IdMessage1.Clear;
IdPOP31.RetrieveHeader(i,IdMessage1);
..............
Выводит все нормально кроме самого текста сообщения:
Memo2.Lines.Add(' Текст сообщения : '+DecodeStr(IdMessage1.Body.Text));
.................
end;
Почему так получается?
Зависит ли IdMessage1.Body.Text от кодировки сообщения?
function DecodeStr(Text: string): string;
var
Temp, Dec: string;
P,P2:Integer;
begin
Temp:=Text;
Result:='';
while pos('=?windows-1251?',Temp)>0 do
begin
P:=pos('=?windows-1251?',Temp);
// P2:=pos('?=',Copy(Temp,P,Length(Temp)))+P;
P2:=pos('?=',Temp);
Dec:=Copy(Temp,p+17,P2-(P+17));
Dec:=Form1.IdDecoderMIME1.DecodeString(Dec);
Result:=Result+Copy(Temp,1,P-1)+Dec;
Temp:=Copy(Temp,P2+2,length(Temp));
end;
Result:=Result+Temp;
Temp:=Result;
Result:='';
while pos('=?koi8-r?',Temp)>0 do
begin
P:=pos('=?koi8-r?',Temp);
P2:=pos('?=',Temp);
Dec:=Copy(Temp,p+11,P2-(P+11));
try
if Dec<>''
then Dec:=KOI8_RToUTF16Str(Form1.IdDecoderMIME1.DecodeString(Dec));
except
end;
Result:=Result+Copy(Temp,1,P-1)+Dec;
Temp:=Copy(Temp,P2+2,length(Temp));
end;
Result:=Result+Temp;
end;
..................
function KOI8_RToUTF16Str(const s: string): WideString;
var
i,j: integer;
begin
j:= length(s);
setLength(Result,j);
for i:=1 to j do
Result:=KOI8_RToUTF16Char(s);
end;
........................
function KOI8_RToUTF16Char(const P: Char): WideChar;
begin
case ord(P) of
$80: result:= #$2500; $81: result:= #$2502; $82: result:= #$250c; $83: result:= #$2510; $84: result:= #$2514;
$85: result:= #$2518;
$86: result:= #$251c;
$87: result:= #$2524;
$88: result:= #$252c;
$89: result:= #$2534;
$8a: result:= #$253c;
$8b: result:= #$2580; $8c: result:= #$2584; $8d: result:= #$2588; $8e: result:= #$258c; $8f: result:= #$2590; $90: result:= #$2591; $91: result:= #$2592; $92: result:= #$2593; $93: result:= #$2320; $94: result:= #$25a0; $95: result:= #$2219; $96: result:= #$221a; $97: result:= #$2248; $98: result:= #$2264; $99: result:= #$2265; $9a: result:= #$00a0; $9b: result:= #$2321;
$9c: result:= #$00b0; $9d: result:= #$00b2; $9e: result:= #$00b7; $9f: result:= #$00f7; $a0: result:= #$2550; $a1: result:= #$2551; $a2: result:= #$2552; $a3: result:= #$0451; $a4: result:= #$2553; $a5: result:= #$2554; $a6: result:= #$2555; $a7: result:= #$2556; $a8: result:= #$2557; $a9: result:= #$2558; $aa: result:= #$2559; $ab: result:= #$255a; $ac: result:= #$255b; $ad: result:= #$255c; $ae: result:= #$255d; $af: result:= #$255e; $b0: result:= #$255f; $b1: result:= #$2560; $b2: result:= #$2561; $b3: result:= #$0401; $b4: result:= #$2562; $b5: result:= #$2563; $b6: result:= #$2564;
$b7: result:= #$2565;
$b8: result:= #$2566; $b9: result:= #$2567;
$ba: result:= #$2568;
$bb: result:= #$2569; $bc: result:= #$256a; $bd: result:= #$256b;
$be: result:= #$256c; $bf: result:= #$00a9; $c0: result:= #$044e; $c1: result:= #$0430; $c2: result:= #$0431; $c3: result:= #$0446; $c4: result:= #$0434; $c5: result:= #$0435; $c6: result:= #$0444; $c7: result:= #$0433; $c8: result:= #$0445; $c9: result:= #$0438; $ca: result:= #$0439; $cb: result:= #$043a; $cc: result:= #$043b; $cd: result:= #$043c; $ce: result:= #$043d; $cf: result:= #$043e; $d0: result:= #$043f; $d1: result:= #$044f; $d2: result:= #$0440; $d3: result:= #$0441; $d4: result:= #$0442; $d5: result:= #$0443; $d6: result:= #$0436; $d7: result:= #$0432; $d8: result:= #$044c; $d9: result:= #$044b; $da: result:= #$0437; $db: result:= #$0448; $dc: result:= #$044d; $dd: result:= #$0449; $de: result:= #$0447; $df: result:= #$044a; $e0: result:= #$042e; $e1: result:= #$0410; $e2: result:= #$0411; $e3: result:= #$0426; $e4: result:= #$0414; $e5: result:= #$0415; $e6: result:= #$0424; $e7: result:= #$0413; $e8: result:= #$0425; $e9: result:= #$0418; $ea: result:= #$0419; $eb: result:= #$041a; $ec: result:= #$041b; $ed: result:= #$041c; $ee: result:= #$041d; $ef: result:= #$041e; $f0: result:= #$041f; $f1: result:= #$042f; $f2: result:= #$0420; $f3: result:= #$0421; $f4: result:= #$0422; $f5: result:= #$0423; $f6: result:= #$0416; $f7: result:= #$0412; $f8: result:= #$042c; $f9: result:= #$042b; $fa: result:= #$0417; $fb: result:= #$0428; $fc: result:= #$042d; $fd: result:= #$0429; $fe: result:= #$0427; $ff: result:= #$042a;
else result:=WideChar(ord(P));
end;
end;
Цитата:
Originally posted by Delpher
Почему так получается?
Зависит ли IdMessage1.Body.Text от кодировки сообщения?
Почему так получается?
Зависит ли IdMessage1.Body.Text от кодировки сообщения?
Represents the body of the message.
property Body: TStrings;
Description
Body is a TStrings property that contains the textual values that make up the body of the message. Body normally contains values when the ContentType for the message is a member of the "text/*" MIME family.
When IsEncoded is True, Body contains values that are encoded using the encoding scheme identified in ContentTransferEncoding. When IsEncoded is False, Body contains ASCII text that represents the contents of the message.
When ContentType contains a value in the "multipart/*" MIME family, use MessageParts to access the TIdText or TIdAttachment instances that make up the message.