开发者

Delphi: CDO.Message encoding problems

We w开发者_如何学JAVArote a Delphi program that send some informations with CDO.

In my Win7 machine (hungarian) the accents are working fine.

So if I sent a mail with "ÁÉÍÓÖŐÚÜŰ", I got it in this format. I used iso-8859-2 encoding in the body, and this encode the subject, and the email addresses to (the sender address is contains name).

I thought that I finished with this.

But when I try to send a mail from a Win2k3 english machine (the mailing server is same!), the result is truncate some accents: Ű = U Ő = O

Next I tried to use UTF-8 encoding here.

This provided accents - but wrong accents.

The mail contains accents with ^ signs.

ê <> é

This is not valid hungarian letter... :-(

So I want to know, how to I convert or setup the input to I got good result.

I tried to log the body to see is changes...

Log(SBody);
Msg.Body := SBody;
Log(Msg.Body);

... or not.

But these logs are providing good result, the input is good.

So it is possible lost and misconverted on CDO generate the message.

May I can help the CDO if I can encode the ANSI text into real UTF. But in Delphi converter functions don't have "CodePage" parameters. In Python I can said:

s.encode('iso-8859-2')

or

s.decode('iso-8859-2')

But in Delphi I don't see this parameter.

Is anybody knows, how to preserve the accents, how to convert the accented hungarian strings to preserve them accented format?

And I want to know, can I check the result without sending the mail?

Thanks for your help: dd


a quick google search with "delphi string codepage" got me to torry's delphi pages and maybe the following codesnippets (found here) can shed some light on your problem:

{:Converts Unicode string to Ansi string using specified code page.
  @param   ws       Unicode string.
  @param   codePage Code page to be used in conversion.
  @returns Converted ansi string.
}

function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
var
  l: integer;
begin
  if ws = ' then
    Result := '
  else 
  begin
    l := WideCharToMultiByte(codePage,
      WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
      @ws[1], - 1, nil, 0, nil, nil);
    SetLength(Result, l - 1);
    if l > 1 then
      WideCharToMultiByte(codePage,
        WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR,
        @ws[1], - 1, @Result[1], l - 1, nil, nil);
  end;
end; { WideStringToString }


{:Converts Ansi string to Unicode string using specified code page.
  @param   s        Ansi string.
  @param   codePage Code page to be used in conversion.
  @returns Converted wide string.
}
function StringToWideString(const s: AnsiString; codePage: Word): WideString;
var
  l: integer;
begin
  if s = ' then
    Result := '
  else 
  begin
    l := MultiByteToWideChar(codePage, MB_PRECOMPOSED, PChar(@s[1]), - 1, nil, 0);
    SetLength(Result, l - 1);
    if l > 1 then
      MultiByteToWideChar(CodePage, MB_PRECOMPOSED, PChar(@s[1]),
        - 1, PWideChar(@Result[1]), l - 1);
  end;
end; { StringToWideString }

--reinhard

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜