These are chat archives for IndySockets/Indy

28th
Sep 2018
Kudzu
@czhower
Sep 28 2018 14:08

Indy website may have a few issues for short periods today. We are moving and updating it. However to get our SSL certificate and other things I have to first update the public DNS to get the processes started. We apologize for any inconvenience.

When ready, it will be at the same url http://www.IndyProject.org

Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 18:15
I can see the new website and looks much better - congratulations guys!
Kudzu
@czhower
Sep 28 2018 18:27
Thanks!
Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 22:23
I have a problem, maybe you guys can help me.
I'm using this code to read the message parts:
        for x := 0 to msg.MessageParts.Count-1 do
        begin
          part := msg.MessageParts[x];
          if part.PartType = mptText then
          begin
            if IsHeaderMediaType(part.ContentType, 'text/html') then
            begin
              email.body := TIdText(part).Body.Text;
            end;
            if IsHeaderMediaType(part.ContentType, 'text/plain') then
            begin
              email.plain := TIdText(part).Body.Text;
            end;
          end;
        end;
My question is: is it possible that part.CharSet tells that is UTF-8 but it doesn't?
Remy Lebeau
@rlebeau
Sep 28 2018 22:24
@mdbs99 Sure, if the email is malformed. The CharSet property holds whatever value the email has in the charset attribute of the Content-Type header, Indy doesn't try to validate it. If the charset is wrong, the Body text won't be read correctly
Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 22:26
So, I don't know how to solve my problem :(
But it's occur all time...
Remy Lebeau
@rlebeau
Sep 28 2018 22:26
@mdbs99 what is the actual problem?
Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 22:27
Well, I'm using MSSQL - to put in a context - and my problem looks like that comes from this part ...Body.Text cause I got error message about encode
I'm using ZEOS - more context - and all fields looks good, with the exception of these 2 fields
Do you use ZEOS? Maybe it can help to understand
ZEOS 7.2.5-rc have to properties in Connection:
  • ClientCodePage
  • ControlsCodePage
    If I put both to UTF-8 - which is strange, cause MSSQL, AFAIK, do not work with UTF-8 - I can persist all fields that comes from IdMessage (without the Body) perfectly (subject, FromList.EMailAddresses, msg.Recipients.EMailAddresses...)
If I put the body, I got an error.
Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 22:32
If I use ClientCodePage = ISO-8859-1 (or WINDOWS-1252.. etc) and include Body, I got no error, but all fields in the MSSQL have a wrong encode - you can see "??"... like that
I know that I've mixed two big context in this issue, here, but I don't know what to do
Remy Lebeau
@rlebeau
Sep 28 2018 22:36
@mdbs99 No, I don't use ZEOS. What version of Delphi are you using? Did you check that Body.Text is correct before you put it into ZEOS/MSSQL?
Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 22:36
Another info is that email.body and email.plain are RawUTF8- comes from mORMot, which is type AnsiString(CP_UTF8) - and the same variable I'm using to set Parameters
I'm using Lazarus

that Body.Text is correct

Like what, save in a file?

The first thing to know is: Is my code above right?
Remy Lebeau
@rlebeau
Sep 28 2018 22:40
@mdbs99 Like, putting it in a MessageBox, for instance. Or just looking at it in the debugger. "I'm using Lazarus" - oh :-( That makes things a bit harder, because Lazarus uses UTF-8 encoded string but Indy expects a UTF-16 encoded string. Indy puts FPC into {$Mode Delphi} so string is AnsiString, which Lazarus then puts UTF-8 into, Indy does not put FPC into {$Mode DelphiUnicode} yet
Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 22:42

putting it in a MessageBox, for instance

Bigger to use like that - but looks ok if I save... some examples

That makes things a bit harder, because Lazarus uses UTF-8 encoded string but Indy expects a UTF-16 encoded string

Hmmmm

Are you saying that all text that comes from Indy, into FPC, will be AnsiString for sure?
Maybe I need to convert TIdText(part).Body.Text from ANSI to UTF8?
Other fields (subject, so on) look good - but they are "simpler" then the body
Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 23:03
and yes, a ShowMessage() show all good - so it is UTF-8
Remy Lebeau
@rlebeau
Sep 28 2018 23:12
@mdbs99 see http://wiki.freepascal.org/Unicode_Support_in_Lazarus and http://wiki.freepascal.org/FPC_Unicode_support but if the text appears fine in a MessageBox, or saved to file, then the problem is not with Indy, but in how you are using the text with ZEOS/MSSQL
Marcos Douglas B. Santos
@mdbs99
Sep 28 2018 23:19
Yes @rlebeau that was my conclusion - I'm still searching the problem... but thank you for try to help me