WPCubed Product Support

How to set charset for TWPRichText?

I try to display an Email Text taken from an Indy TIdMessage. UTF-8 encoded texts are not displayed correctly. I think the problem is that the charset is not part of the HTML of the message text but rather inside the TIdMeesage.

So if there was a method I could set the charset of the TWPRichText it probably would be fine. Maybe I overlooked it but I only found DefaultAttr.SetFontCharSet but this takes an Integer and I found no further description.

Maybe someone can help me out, please.

Regards,
Dirk.

Here are the details of my message I would like to display:

Content-Type: text/html ; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<html><head><style type=3D"text/css"><!-- DIV {margin:0px;} --></style=

</head><body><div style=3D"font-family:times new roman,new york,times=

,serif;font-size:12pt"><div>Sehr geehrte Damen und Herren,<br><br>ich =
m=C3=B6chte gerne <span style=3D"font-weight: bold;">10 Lizenzen</span=

bestellen.<br><br>Vielen Dank!<br><br>Gerd Gerdes<br></div></div><br=

</body></html>

#1 ♥ 0
4.9k Views 2 users read 3 min
support

Hi,

Try reading the HTML using the format string "HTML-utf8"

The TWPRichText does not realy have a charset - well, it does, but it is only for typing in text to select a code page.

The text is handled as widechars.

Julian

#2 ♥ 0

I am not sure if I understand that correctly. When I read the mail it is already in a TIdMessage object. I then iterate over the attachments and take the text from the Body property. Here is the function:

function GetTextFromMessage( const pMsg: TIdMessage ) : TStringList;
var
  i: Integer;
  lStrList: TStringList;
begin
  lStrList := TStringList.Create;

  for i := 0 to pMsg.MessageParts.Count-1 do
  begin
    if pMsg.MessageParts.Items[i] is TIdText then
    begin
      lStrList.Clear;
      lStrList.AddStrings( (pMsg.MessageParts.Items[i] as TIdText).Body );
    end;
  end;

  Result := lStrList;
end;

Where do you mean I could use the format string "HTML-utf8" ?

#3 ♥ 0
support

Hi,

Where do you mean I could use the format string "HTML-utf8" ?

You use this "Format String" in LoadFromSTream or LoadFromFile.

Or in propertty TextLoadFromat if you assign the message to property AsString.

Julian

#4 ♥ 0
This category is archived. No new posts are possible.