[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    [PATCH] Fixes Bug#26930: encryption problems with commas in address
From:       Ingo =?iso-8859-1?q?Kl=F6cker?= <ingo.kloecker () epost ! de>
Date:       2001-06-17 22:48:20
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This bug occured for example if you try to send an encrypted message to 
"Doe, John" <jd@somewhere>.
The old code simply split the addresses after each "," disregarding the 
fact that commas inside quoted strings or comments have to be ignored. 
The new code splits lists of addresses which conform to RFC822.

BTW, there are some more places in KMail which don't split lists of 
email addresses correctly.

For example is the following address a valid email address:
"Kloecker,I\"x,y" <ingo@localhost>

But it is not possible to send a message to this address with KMail 
because KMail seems to split the address at the second "," into the two 
invalid addresses "Kloecker,I\"x and y" <ingo@localhost>.
Obviously the code performing the splitting doesn't ignore the escaped 
quote as it should.

Another place where the address is split in the same wrong manner is 
the splitting which is performed to make "mailto:" URLs out of 
addresses which are shown in the message pane.

BTW, in the header pane this address is shown correctly as 
Kloecker,I\"x,y

Regards,
Ingo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7LTO5GnR+RTDgudgRAoKzAJ4itJtyvRZhatQDMWyAMfM+whCgzQCeOLCK
PFv9zdu8420HcAxKJ9AxZ9E=
=8vV5
-----END PGP SIGNATURE-----

["fix_splitting_of_addresses-2001-06-18-0015.diff" (text/x-c++)]

Index: kmcomposewin.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmcomposewin.cpp,v
retrieving revision 1.356
diff -u -3 -p -r1.356 kmcomposewin.cpp
--- kmcomposewin.cpp	2001/06/17 20:15:11	1.356
+++ kmcomposewin.cpp	2001/06/17 21:35:16
@@ -1192,9 +1192,6 @@ QCString KMComposeWin::pgpProcessedMsg(v
   Kpgp *pgp = Kpgp::getKpgp();
   bool doSign = signAction->isChecked();
   bool doEncrypt = encryptAction->isChecked();
-  QString _to, receiver;
-  int index, lastindex;
-  QStrList persons;
   QString text;
   QCString cText;
 
@@ -1252,24 +1249,72 @@ QCString KMComposeWin::pgpProcessedMsg(v
   else
   {
     // encrypting
-      _to = to();
+
+// FIXME: Use QStringList instead of QStrList in order to support unicode
+    QStrList recipients;
+    QString _to = to();
+
     if(!cc().isEmpty()) _to += "," + cc();
     if(!bcc().isEmpty()) _to += "," + bcc();
-    lastindex = -1;
-    do
-    {
-      index = _to.find(",",lastindex+1);
-      receiver = _to.mid(lastindex+1, index<0 ? 255 : index-lastindex-1);
-      if (!receiver.isEmpty())
-      {
-// FIXME: Kpgp::encryptFor() has to support unicode
-	persons.append(receiver.latin1());
+    // split the to, cc and bcc header into separate addresses
+    // important: always ignore quoted characters
+    //            ignore '(', ')' and ',' inside quoted strings
+    //            comments may be nested
+    //            ignore '"' and ',' inside comments
+    if (!_to.isEmpty()) {
+      QString recipient;
+      int addrstart = 0;
+      int commentlevel = 0;
+      bool insidequote = false;
+
+      for (int index=0; index<_to.length(); index++) {
+        // the following conversion to latin1 is o.k. because
+        // we can safely ignore all non-latin1 characters
+        switch (_to[index].latin1()) {
+        case '"' : // start or end of quoted string
+          if (commentlevel == 0)
+            insidequote = !insidequote;
+          break;
+        case '(' : // start of comment
+          if (!insidequote)
+            commentlevel++;
+          break;
+        case ')' : // end of comment
+          if (!insidequote) {
+            if (commentlevel > 0)
+              commentlevel--;
+            else
+              kdDebug(5006) << "Error in address splitting: Unmatched ')'"
+                            << endl;
+          }
+          break;
+        case '\\' : // quoted character
+          index++; // ignore the quoted character
+          break;
+        case ',' : 
+          if (!insidequote && (commentlevel == 0)) {
+            recipient = _to.mid(addrstart, index-addrstart);
+            kdDebug(5006) << "Found recipient: " << recipient << endl;
+            if (!recipient.isEmpty())
+              recipients.append(recipient.simplifyWhiteSpace().latin1());
+            addrstart = index+1;
+          }
+          break;
+        }
+      }
+      // append the last address to the list of recipients
+      if (!insidequote && (commentlevel == 0)) {
+        recipient = _to.mid(addrstart, _to.length()-addrstart);
+        kdDebug(5006) << "Found recipient: " << recipient << endl;
+        if (!recipient.isEmpty())
+          recipients.append(recipient.simplifyWhiteSpace().latin1());
       }
-      lastindex = index;
+      else
+        kdDebug(5006) << "Error in address splitting: "
+                      << "Unexpected end of address list";
     }
-    while (lastindex > 0);
     
-    if(pgp->encryptFor(persons, pgpUserId, doSign))
+    if(pgp->encryptFor(recipients, pgpUserId, doSign))
       return pgp->message();
   }
 

_______________________________________________
Kmail Developers mailing list
Kmail@master.kde.org
http://master.kde.org/mailman/listinfo/kmail


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic