Bug 140291 - Imap password should be properly escaped
Summary: Imap password should be properly escaped
Status: RESOLVED FIXED
Alias: None
Product: mailody
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Tom Albers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-19 14:34 UTC by Tommi Tervo
Modified: 2007-01-20 21:06 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tommi Tervo 2007-01-19 14:34:17 UTC
Version:           0.3.1-svn (using KDE 3.5.5, compiled sources)
Compiler:          Target: i486-linux-gnu
OS:                Linux (i686) release 2.6.12-10-386

mailody: IMAP C   : a02 login "luser" "pass"Word"
mailody: IMAP S(0): a02 BAD Protocol Error: "Unexpected additional characters at the end of command".
Comment 1 Tom Albers 2007-01-19 14:57:46 UTC
SVN commit 625208 by toma:

Quote login and password. Please check if it works, there is nothing in the IMAP rfc about this. Copied KDE kioslave behaviour, so should be ok.
BUG: 140291


 M  +22 -3     imap.cpp  
 M  +1 -0      imap.h  


--- trunk/playground/pim/mailody/src/imap.cpp #625207:625208
@@ -95,7 +95,8 @@
     else
     {
         m_queue.prepend(Queue(Queue::Auth, "",
-                    "login \"" + login + "\" \"" + pass + "\""));
+                    "login \"" + quoteIMAP(login) 
+                    + "\" \"" + quoteIMAP(pass) + "\""));
         m_currentQueueItem=Queue();
         emit statusReady();
 
@@ -125,8 +126,8 @@
     }
     if (result == KPasswordDialog::Accepted)
         m_queue.prepend(Queue(Queue::Auth, "",
-                        "login \"" + login + "\" \"" +
-                                QString(password) + "\""));
+                        "login \"" + quoteIMAP(login) + "\" \"" +
+                                quoteIMAP(QString(password)) + "\""));
     password.fill(0); // safe enough?
     m_currentQueueItem=Queue();
     emit statusReady();
@@ -1145,6 +1146,24 @@
     m_imap->reconnect();
 }
 
+/* Copy from KDE/3.5/kdepim/kioslaves/imap4/rfcdecoder.cc */
+/* Copyright (C) 2000 s.carstens@gmx.de */
+/* replace " with \" and \ with \\ " and \ characters */
+QString Imap::quoteIMAP(const QString &src)
+{
+    uint len = src.length();
+    QString result;
+    result.reserve(2 * len);
+    for (unsigned int i = 0; i < len; i++)
+    {
+        if (src[i] == '"' || src[i] == '\\')
+            result += '\\';
+        result += src[i];
+    }
+    //result.squeeze(); - unnecessary and slow
+    return result;
 }
 
+}
+
 #include "imap.moc"
--- trunk/playground/pim/mailody/src/imap.h #625207:625208
@@ -232,6 +232,7 @@
     void integrity(const QString& mb, int);
     void timerEvent( QTimerEvent * );
     void getCapabilities();
+    QString quoteIMAP(const QString &src);
 
   signals:
     /**
Comment 2 Tommi Tervo 2007-01-20 21:06:36 UTC
Confirmed, fix works fine