views:

92

answers:

1

Hi!

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

A: 

hi!

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

pastacool
Hi! I used your code to convert string. When I make this in hungarian Windows, the CDO send normal, accented characters. When I send in english machine, the accent lost. Nevertheless I convert them to WideString before I send, and set BodyPart.CharSet to iso-8859-2, or utf-8... :-(
durumdara
Plus I tested the two machines with a simple code. This not uses CDO, only WideString, and UTF-s. I generated them into a file. I compared the two files, and they are identical, not matter, where I generated. So it is seems to be CDO problem - but I don't know, where I search for solution... :-(
durumdara
I tested today with Python and CDO. Python strings are converted as needed into mail. The accents are appearing good. So that is the question: what we do wrong in Delphi side to lost accents from WideStrings, and what Python do to they remaining?
durumdara
I tried with 28592, and 1250, but every failed with Delphi and english windows... :-(
durumdara
I solved the problem. The problem was that I used a Delphi object, a wrapper for CDO. And this used String properties what silently and transparenly converted the WideStrings to Strings... Sorry for disturbing and thanks for the good solution!
durumdara
@durumdara: sorry, haven't been able to reply earlier - is your problem now solved or do you still have issues with missing accents?
pastacool