[PATCH 1/6] Recognize configuration for idlefolders
Ethan Glasser-Camp
ethan at betacantrips.com
Wed May 18 13:48:52 BST 2011
This code was originally by James Bunton <jamesbunton at fastmail.fm>.
Signed-off-by: Ethan Glasser-Camp <ethan at betacantrips.com>
---
offlineimap.conf | 13 +++++++++++++
offlineimap/imapserver.py | 6 +++++-
offlineimap/repository/IMAP.py | 12 +++++++++++-
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/offlineimap.conf b/offlineimap.conf
index 33a0810..39cded6 100644
--- a/offlineimap.conf
+++ b/offlineimap.conf
@@ -364,6 +364,19 @@ remoteuser = username
#
# reference = Mail
+# In between synchronisations, OfflineIMAP can monitor mailboxes for new
+# messages using the IDLE command. If you want to enable this, specify here
+# the folders you wish to monitor. Note that the IMAP protocol requires a
+# separate connection for each folder monitored in this way, so setting
+# this option will force settings for:
+# maxconnections - to be at least the number of folders you give
+# holdconnectionopen - to be true
+# keepalive - to be 29 minutes unless you specify otherwise
+# This option should return a Python list. For example
+#
+# idlefolders = ['INBOX', 'INBOX.Alerts']
+#
+
# OfflineIMAP can use multiple connections to the server in order
# to perform multiple synchronization actions simultaneously.
# This may place a higher burden on the server. In most cases,
diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 7703879..58e7e57 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -43,7 +43,7 @@ class IMAPServer:
username = None, password = None, hostname = None,
port = None, ssl = 1, maxconnections = 1, tunnel = None,
reference = '""', sslclientcert = None, sslclientkey = None,
- sslcacertfile= None):
+ sslcacertfile = None, idlefolders = []):
self.ui = getglobalui()
self.reposname = reposname
self.config = config
@@ -72,6 +72,7 @@ class IMAPServer:
self.semaphore = BoundedSemaphore(self.maxconnections)
self.connectionlock = Lock()
self.reference = reference
+ self.idlefolders = idlefolders
self.gss_step = self.GSS_STATE_STEP
self.gss_vc = None
self.gssapi = False
@@ -386,6 +387,7 @@ class ConfigedIMAPServer(IMAPServer):
sslclientkey = self.repos.getsslclientkey()
sslcacertfile = self.repos.getsslcacertfile()
reference = self.repos.getreference()
+ idlefolders = self.repos.getidlefolders()
server = None
password = None
@@ -397,6 +399,7 @@ class ConfigedIMAPServer(IMAPServer):
IMAPServer.__init__(self, self.config, self.repos.getname(),
tunnel = usetunnel,
reference = reference,
+ idlefolders = idlefolders,
maxconnections = self.repos.getmaxconnections())
else:
if not password:
@@ -405,6 +408,7 @@ class ConfigedIMAPServer(IMAPServer):
user, password, host, port, ssl,
self.repos.getmaxconnections(),
reference = reference,
+ idlefolders = idlefolders,
sslclientcert = sslclientcert,
sslclientkey = sslclientkey,
sslcacertfile = sslcacertfile)
diff --git a/offlineimap/repository/IMAP.py b/offlineimap/repository/IMAP.py
index 0bc84eb..1d40a8f 100644
--- a/offlineimap/repository/IMAP.py
+++ b/offlineimap/repository/IMAP.py
@@ -79,9 +79,13 @@ class IMAPRepository(BaseRepository):
self.imapserver.close()
def getholdconnectionopen(self):
+ if self.getidlefolders():
+ return 1
return self.getconfboolean("holdconnectionopen", 0)
def getkeepalive(self):
+ if self.getidlefolders():
+ return 29*60
return self.getconfint("keepalive", 0)
def getsep(self):
@@ -163,8 +167,14 @@ class IMAPRepository(BaseRepository):
def getreference(self):
return self.getconf('reference', '""')
+ def getidlefolders(self):
+ localeval = self.localeval
+ return localeval.eval(self.getconf('idlefolders', '[]'))
+
def getmaxconnections(self):
- return self.getconfint('maxconnections', 1)
+ num1 = len(self.getidlefolders())
+ num2 = self.getconfint('maxconnections', 1)
+ return max(num1, num2)
def getexpunge(self):
return self.getconfboolean('expunge', 1)
--
1.7.4.1
More information about the OfflineIMAP-project
mailing list