Html mail displays differently than the body text does...

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Html mail displays differently than the body text does...

Bo Berglund
I am using Indy 10 (latest trunk version) in Lazarus to create a
command line utility to interface with our new Subversion repository
server. It sends commit emails to select users with some information
including a list of changed files and with a URL line to allow the
recipient to access the file from the VisualSVN web interface.

This has worked fine until today when I tried a test case where the
file is named with the Swedish characters ÅÄÖåäö as part of the file
name. When I commit this file all seems to go fine and the file
appears as expected in the VSVN web interface with the correct name.

But in the received email the file name and URL is corrupted and
cannot be read or used. THe Swedish characters have been replaced by
question marks in black diamonds.

As part of the email sending the program logs stuff and it also
creates a file on disk with the mail body content (basically
message.body.savetofile(somename.html).

If I open this file in Chrome it displays properly with the correct
URL and name.
But in the received email I don't see this, neither in Outlook on the
PC nor in the Samsung Mail app on my phone.

Question:
---------
How should I format the html part of the email when loading it into
the TIdSMTP component for sending?

Currently I use a TStringList container as follows:

function CreateFileURL(Server, Repo, FilePath: string): string;
var
  sURL: string;
begin
  sURL := Server + '/!/#' + Repo + '/view/head/' + FilePath;
  Result := '<a href="' + sURL + '">' + ExtractFileName(FilePath) +
'</a>';
end;

In the caller:
slBody.Add('<html><head>' +
'<style type="text/css"><!--p,td { font-family: arial,helvetica;
font-size: 10pt }--></style>'+
'</head><body><table border=0>');
sLine := '<tr><td><b>SVN Server:</b></td><td>' + Computer +
'</td></tr>';
slBody.Add(sLine);
---- Lots of lines more ----
sTmp := SVNX.SvnData.FileList[i]; // <4 char OP><file path>
sTmp := CreateFileURL(SERVER_URL, REPONAME, CurDir + sTmp);
slBody.Add(sTmp + '</td></tr>');


The only thing I can think of now is to somehow tell the html part
that it is dealing with utf-8 data, but how? Should I put something
into the <head> part maybe?

I have already set the message to use UTF-8 via the messagebuilder:

IB := TIdMessageBuilderHtml.Create;
....
IB.HtmlCharSet := 'UTF-8';
IB.Html.Text := slBody.Text;
IB.PlainText.Text := slTxtBody.Text;
IB.FillMessage(SVNM.MailMessage);

Any ideas?

--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Html mail displays differently than the body text does...

Bo Berglund
On Thu, 18 Jan 2018 18:46:28 +0100, Bo Berglund
<[hidden email]> wrote:

>I have already set the message to use UTF-8 via the messagebuilder:
>
>IB := TIdMessageBuilderHtml.Create;
>....
>IB.HtmlCharSet := 'UTF-8';
>IB.Html.Text := slBody.Text;
>IB.PlainText.Text := slTxtBody.Text;
>IB.FillMessage(SVNM.MailMessage);
>
>Any ideas?

I ended up completely removing the line
IB.HtmlCharSet := 'UTF-8';
above.
Then I added a "translator" function which replaces Swedish characters
in a string with the HTML escape sequences. I call this function to
wash text before inserting into the HTML mail body.

This solved the mailing problem for the case where new files and
folders are using these characters. But the existing names erroneously
converted (from cvs to svn) I have to manually rename via Subversion
to get right for the future. Hopefully there are only a handful of
such files/folders (I have so far found about a dozen).


--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal