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

David Jarvie djarvie at kde.org
Wed Jan 20 22:22:14 GMT 2010


On Wednesday 20 Jan 2010 19:22:42 Ingo Klöcker wrote:
> On Wednesday 20 January 2010, David Jarvie wrote:
> > On Wed, January 20, 2010 12:03 am, David Jarvie wrote:
> > > Hi Ingo,
> > >
> > > On Tuesday 19 Jan 2010 23:24:23 Ingo Klöcker wrote:
> > >> On Tuesday 19 January 2010, David Jarvie wrote:
> > >> > 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.
> > >
> > > I'm not sure how that would have been done, since converting to
> > > UTF-8 changes it to a QByteArray, not a QString. Would a double
> > > conversion be produced by this? (Note that I'm not aware of this
> > > actually having happened):
> > >
> > >    bodyText = QString(originalBodyText.toUtf8())
> 
> No. The QString-c'tor will interpret the byte array as a local-encoded 
> string and since the local encoding is mostly UTF-8 nowadays (on Linux 
> anyway) this will not produce a double conversion.
> 
> 
> > >> 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.
> > >
> > > I've printed out the bodyText QString using kDebug(), and it shows
> > > the correct Cyrillic text on konsole (which has UTF-8 set as the
> > > default character encoding). Is this sufficient evidence that it
> > > contains the correct Unicode string, or could that be misleading?
> >
> > I've checked further, and I'm convinced that the QString supplied to
> > fromUnicodeString() is the same as is supplied to
> > KCal::Alarm::setEmailAlarm() when writing to the calendar. It is
> > stored correctly as Cyrillic text in the calendar file.
> 
> Hmm, then I'm out of ideas as I don't really know KMime.

I now discover that the encoded text works correctly if KAlarm sends the message via KDE's MailTransport class - the error only occurs when using sendmail to transmit the email. it must be due to a conversion error when KAlarm writes the text to a pipe.

In other words, kmime is not to blame. Sorry for the noise.

-- 
David Jarvie.
KDE developer.
KAlarm author -- http://www.astrojar.org.uk/kalarm
_______________________________________________
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