[Kde-pim] Using kmime lib to create UTF-8 email message

Ingo Klöcker kloecker at kde.org
Tue Jan 19 23:24:23 GMT 2010


On Tuesday 19 January 2010, David Jarvie wrote:
> Hi Thomas,
>
> On Tuesday 19 Jan 2010 00:04:03 Thomas McGuire wrote:
> > On Tuesday 19 January 2010 00:32:35 David Jarvie wrote:
> > > I'm trying to use the kmime library to compile an email message
> > > in KAlarm, but can't get it to work with non-Latin scripts. I've
> > > looked at both mailody and the new kmail for inspiration, and
> > > can't see where I'm going wrong. For a plain text message with no
> > > attachments, I've tried
> > >
> > >    KMime::Message message;
> > >    // Set headers ....
> > >    message.contentType()->setMimeType("text/plain");
> > >    // the message doesn't work with or without the following
> > > line: message.contentType()->setCharset("utf-8");
> > >    message.setBody(bodyText.toUtf8());
> > >    message.assemble();
> > >
> > > I also tried, instead of setBody():
> > >
> > >    message.fromUnicodeString(bodyText);
> > >
> > > I retrieved the final QByteArray to send using
> > >
> > >    message.encodedContent();
> >
> > Hmm, setting the content type to text/plain and then calling
> > fromUnicodeString() with the QString as argument, followed by an
> > assemble(), should be enough.
> >
> > If that doesn't work, can you attach the encodedContent() here so I
> > can have a closer look?
>
> I attach the whole email text which was returned by encodedContent().
> The two ways of producing it (setBody() and fromUnicodeString()) both
> produce the same result. The original body text was some Cyrillic
> text conveniently provided by a spam email which I was sent):
>
> Під час клацання

The problem is that this Cyrillic text was converted twice from Unicode 
to utf-8, i.e. the result of the first conversion was again interpreted 
as Unicode and then recoded to utf-8.

Are you sure that bodyText contains the correct Unicode string? How did 
you set bodyText? If bodyText does already contain a utf-8 encoded 
version of the text instead of the Unicode version then this would 
explain your observations.


Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20100120/7e518f60/attachment.sig>
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list