[PATCH] encode mail address when passing via KApplication::invokeMailer

Tobias Koenig tokoe at kde.org
Fri Jan 7 15:40:10 GMT 2005


Hi,

when you pass an email address with non-latin1 characters in the name to
invokeMailer, in KMail you'll end up with '??????'.

The problem is, that the name is given on the command line to kmail in
latin1. To fix this, the attached patch encodes the name according to
RFC2047, which can be read by KMail without problems. Ok to commit?

FIXES: #94905

Ciao,
Tobias
-- 
Separate politics from religion and economy!
-------------- next part --------------
? patchme
Index: kapplication.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kapplication.cpp,v
retrieving revision 1.696
diff -p -u -b -r1.696 kapplication.cpp
--- kapplication.cpp	29 Dec 2004 22:05:41 -0000	1.696
+++ kapplication.cpp	7 Jan 2005 15:34:30 -0000
@@ -72,6 +72,7 @@
 #include <kshell.h>
 #include <kprotocolinfo.h>
 #include <kkeynative.h>
+#include <kmdcodec.h>
 
 #if defined Q_WS_X11
 #include <kstartupinfo.h>
@@ -2301,7 +2302,27 @@ void KApplication::invokeMailer(const QS
 #ifndef Q_WS_WIN
 // on win32, for invoking browser we're using win32 API
 // see kapplication_win.cpp
-void KApplication::invokeMailer(const QString &to, const QString &cc, const QString &bcc,
+
+static QString simpleRFC2047Encode( const QString &email )
+{
+  int end = email.findRev( '>' );
+
+  if ( end == -1 ) // no part to encode
+    return email;
+
+  int index = end - email.length() - 1;
+  int begin = email.findRev( '<', index );
+
+  QString address = email.mid( begin + 1, end - begin - 1 );
+  QString name = email.left( begin ).stripWhiteSpace();
+
+  QString result = QString( "=?utf8?b?%1?= <%2>" )
+                   .arg( KCodecs::base64Encode( name.utf8(), false ), address );
+
+  return result;
+}
+
+void KApplication::invokeMailer(const QString &_to, const QString &cc, const QString &bcc,
                                 const QString &subject, const QString &body,
                                 const QString & /*messageFile TODO*/, const QStringList &attachURLs,
                                 const QCString& startup_id )
@@ -2314,10 +2335,23 @@ void KApplication::invokeMailer(const QS
    config.setGroup( QString("PROFILE_%1").arg(group) );
    QString command = config.readPathEntry("EmailClient");
 
+   QString to;
    if (command.isEmpty() || command == QString::fromLatin1("kmail")
-       || command.endsWith("/kmail"))
+       || command.endsWith("/kmail")) {
      command = QString::fromLatin1("kmail --composer -s %s -c %c -b %b --body %B --attach %A -- %t");
 
+     if ( !_to.isEmpty() )
+     {
+       QStringList tos = QStringList::split( ',', _to );
+       for (QStringList::ConstIterator it = tos.begin(); it != tos.end(); ++it) {
+         to += simpleRFC2047Encode( *it ) + ", ";
+       }
+
+       to.truncate( to.length() - 2 ); // strip last commata
+     }
+   } else
+    to = _to;
+
    if (config.readBoolEntry("TerminalClient", false))
    {
      KConfigGroup confGroup( KGlobal::config(), "General" );
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050107/555d778e/attachment.sig>


More information about the kde-core-devel mailing list