Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Nov : Re: Sending a SMTP message with UTF-8 subject

www.cryer.info
Managed Newsgroup Archive

Re: Sending a SMTP message with UTF-8 subject

Subject:Re: Sending a SMTP message with UTF-8 subject
Posted by:"Richard" (ritchie8..@yahoo.com)
Date:Tue, 27 Nov 2007 21:53:34

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:474c7c20$2@newsgroups.borland.com...
>
>
> As far as I know, you can't have 3 different code pages in a single
> string, or even multiple code pages active in a given thread at the same
> time.  Even if you could, there is no way to know which characters are
> using which codepage so they can be encoded separately.

I am using Tnt unicode components and sure I can have all three languages
at the same time. I no longer work with ANSI.  My app is completly unicode
and runs only on NT based systems. A typical example of various languages in
one line: using some e-mail program in russian, when you reply, the subject
will be "Reply to: original subject".  Reply to will be written by the
program in russian, and if the original subject was in greek, here we go,
now you have 2 charsets (talking in Ansi ) in one line. Normal e-mail
programs like The-bat. OE, etc will just encode this as UTF-8, which I am
trying to do with Indy.

>
> That happens when a WideString contains characters that cannot be
> converted to Ansi or MBCS at all.  There is nothing Indy can do about
> that.  The conversion is happening outside of Indy, in the RTL itself.

Im not blaming indy at all. Note that I say "as it should be".


>
> will have to use the TIdMessage.OnInitializeISO event to set the
> HeaderEncoding to '8' and the CharSet to 'ISO-8859-1' or 'US-ASCII' or
> even just '' (empty string).  Then Indy shold be able to transmit your
> input data as-is.

Noe THIS actually gives some results. The subject is now pure UTF-8, so it
works on some clients (like The Bat!) that are smart enough to guess the
encoding, so I made some modifications:

Mess.Subject := '=?utf-8?B?+ IdEncoderMIME1.Encode( UTF8Encode('My
widestring')) + '?=';

Now the subject is "standard" and can be interpreted by aöö (hopefully)
decent clients.


I had the same problem with the name of the attachments (that will only
acept AnsiStrings as the FileName header). . I use a TIdAttachmentMemoryto
load a UNICODE named file name. No problems at all, so this is solved as
well:

AFileName:= 'C:\Documents and Settings\cobian\Desktop\NewText Document
(2).txt';

// a WIDE string


try
      AStr:= TTntFileStream.Create(AFileName, fmOpenRead); //WIDE
      with TIdAttachmentMemory.Create(Mess.MessageParts, Astr) do
      begin

        FileName:=
        '=?utf-8?B?'+IdEncoderMIME1.Encode(
         UTF8Encode( 'My new file name UNICODE'))+'?=';
        ContentType := 'text/html';
      end;
    finally
      FreeAndNil(Astr);
    end;

Works like a charm, shows the unicode name without problems....

BTW,does HeaderEncoding = '8'  means to use 8bit (no encoding?). I know that
the values can be 'B' and 'Q' but did not know about the 8.

Anyway, thanks a lot. This has been a GREAT help.

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive