]> code.delx.au - offlineimap/blobdiff - offlineimap/imapserver.py
* Remove second docbook-utils build dependency.
[offlineimap] / offlineimap / imapserver.py
index 9ebdb2e17eaa815c049ec76f496f1a4c3c0bcb95..6ca1fbcff3969ea489e6c0c88bd8883bd056824d 100644 (file)
@@ -1,5 +1,5 @@
 # IMAP server support
-# Copyright (C) 2002, 2003 John Goerzen
+# Copyright (C) 2002 - 2007 John Goerzen
 # <jgoerzen@complete.org>
 #
 #    This program is free software; you can redistribute it and/or modify
@@ -16,7 +16,8 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
-from offlineimap import imaplib, imaputil, threadutil
+import imaplib
+from offlineimap import imaplibutil, imaputil, threadutil
 from offlineimap.ui import UIBase
 from threading import *
 import thread, hmac, os
@@ -31,8 +32,8 @@ class UsefulIMAPMixIn:
         return None
 
     def select(self, mailbox='INBOX', readonly=None, force = 0):
-        if (not force) and self.getselectedfolder() == mailbox:
-            self.is_readonly = readonly
+        if (not force) and self.getselectedfolder() == mailbox \
+           and self.is_readonly == readonly:
             # No change; return.
             return
         result = self.__class__.__bases__[1].select(self, mailbox, readonly)
@@ -43,9 +44,18 @@ class UsefulIMAPMixIn:
         else:
             self.selectedfolder = None
 
-class UsefulIMAP4(UsefulIMAPMixIn, imaplib.IMAP4): pass
-class UsefulIMAP4_SSL(UsefulIMAPMixIn, imaplib.IMAP4_SSL): pass
-class UsefulIMAP4_Tunnel(UsefulIMAPMixIn, imaplib.IMAP4_Tunnel): pass
+    def _mesg(self, s, secs=None):
+        imaplibutil.new_mesg(self, s, secs)
+
+class UsefulIMAP4(UsefulIMAPMixIn, imaplib.IMAP4):
+    def open(self, host = '', port = imaplib.IMAP4_PORT):
+        imaplibutil.new_open(self, host, port)
+
+class UsefulIMAP4_SSL(UsefulIMAPMixIn, imaplibutil.WrappedIMAP4_SSL):
+    def open(self, host = '', port = imaplib.IMAP4_SSL_PORT):
+        imaplibutil.new_open_ssl(self, host, port)
+
+class UsefulIMAP4_Tunnel(UsefulIMAPMixIn, imaplibutil.IMAP4_Tunnel): pass
 
 class IMAPServer:
     def __init__(self, config, reposname,
@@ -57,6 +67,7 @@ class IMAPServer:
         self.username = username
         self.password = password
         self.passworderror = None
+        self.goodpassword = None
         self.hostname = hostname
         self.tunnel = tunnel
         self.port = port
@@ -77,6 +88,9 @@ class IMAPServer:
         self.reference = reference
 
     def getpassword(self):
+        if self.goodpassword != None:
+            return self.goodpassword
+
         if self.password != None and self.passworderror == None:
             return self.password
 
@@ -99,6 +113,7 @@ class IMAPServer:
 
 
     def releaseconnection(self, connection):
+        """Releases a connection, returning it to the pool."""
         self.connectionlock.acquire()
         self.assignedconnections.remove(connection)
         self.availableconnections.append(connection)
@@ -167,6 +182,8 @@ class IMAPServer:
                 UIBase.getglobalui().connecting(self.hostname, self.port)
                 imapobj = UsefulIMAP4(self.hostname, self.port)
 
+            imapobj.mustquote = imaplibutil.mustquote
+
             if not self.tunnel:
                 try:
                     if 'AUTH=CRAM-MD5' in imapobj.capabilities:
@@ -180,6 +197,7 @@ class IMAPServer:
                         self.plainauth(imapobj)
                     # Would bail by here if there was a failure.
                     success = 1
+                    self.goodpassword = self.password
                 except imapobj.error, val:
                     self.passworderror = str(val)
                     self.password = None