Delphi:CDO.Message编码问题

发布于 2024-09-18 00:50:23 字数 900 浏览 6 评论 0原文

我们编写了一个 Delphi 程序,用 CDO 发送一些信息。

在我的 Win7 机器(匈牙利语)中,重音工作正常。

因此,如果我发送一封带有“ÁÉÍÓÖŐÚÜŰ”的邮件,我就会收到这种格式的邮件。 我在正文中使用了 iso-8859-2 编码,这对主题和电子邮件地址进行了编码(发件人地址包含姓名)。

我以为我就这样结束了。

但是当我尝试从 Win2k3 英文机器发送邮件时(邮件服务器是相同的!),结果是截断一些重音: Ű = U Ő = O

接下来我尝试在这里使用UTF-8编码。

这提供了口音——但口音是错误的。

邮件包含带有 ^ 符号的重音符号。

ê <> é

这不是有效的匈牙利字母... :-(

所以我想知道,如何转换或设置输入以获得良好的结果。

我尝试记录正文以查看更改...

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

... 或但

这些日志提供了良好的结果,

因此在 CDO 生成消息时可能会丢失和错误转换,

如果我可以将 ANSI 文本编码为真正的 UTF。 但在 Delphi 转换器函数中没有“CodePage”参数。 在Python中我可以说:

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

或者

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

但是在Delphi中我没有看到这个参数。

有谁知道如何保留重音,如何转换带重音的匈牙利字符串以保留它们的重音格式?

我想知道,不发邮件可以查结果吗?

感谢您的帮助: DD

We wrote 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-09-25 00:50:23

通过 Google 快速搜索“delphi string codepage”,我找到了 terry 的 delphi 页面
也许还有以下代码片段(在此处)可以阐明您的问题:

{: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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文