Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dax/jmc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rousselie <dax@happycoders.org>2008-07-26 01:53:23 +0400
committerDavid Rousselie <dax@happycoders.org>2008-07-26 01:53:23 +0400
commit56eb2f004ca5a4099dfd783290c60b2a1c10a461 (patch)
tree8fd8ecf90c30c59cc8599ffe9259f0e6e5be8250
parent5cdb8e8ba6d5057893ecebb57f6521e1ee44dc5d (diff)
Correct IMAPAccount populate_handler
IMAP list with wrong delimiter could return [None], so trying with another delimiter in that case darcs-hash:20080725215323-86b55-f4b7cc15e8b30aaebf2fe5233ab40e4409ebf9a2.gz
-rw-r--r--src/jmc/model/account.py29
-rw-r--r--src/jmc/model/tests/account.py20
2 files changed, 38 insertions, 11 deletions
diff --git a/src/jmc/model/account.py b/src/jmc/model/account.py
index 105463f..9d79695 100644
--- a/src/jmc/model/account.py
+++ b/src/jmc/model/account.py
@@ -435,7 +435,7 @@ class IMAPAccount(MailAccount):
current_folder = current_folder[folder]
return current_folder.keys()
- def populate_handler(self):
+ def populate_handler(self, try_other_delimiter=True, testing_delimiter="/"):
"""
Handler called when populating account
"""
@@ -445,20 +445,31 @@ class IMAPAccount(MailAccount):
typ, data = self.connection.list(self.mailbox)
if typ == 'OK':
line = data[0]
- match = self._regexp_list.match(line)
- if match is not None:
- self.delimiter = match.group(2)
+ if line is None:
+ if try_other_delimiter:
+ self.mailbox = self.mailbox.replace(testing_delimiter,
+ ".")
+ self.populate_handler(False, ".")
+ return
+ else:
+ self.disconnect()
+ raise Exception("Cannot find mailbox " + self.mailbox)
else:
- self.disconnect()
- raise Exception("Cannot find delimiter for mailbox "
- + self.mailbox)
+ match = self._regexp_list.match(line)
+ if match is not None:
+ self.delimiter = match.group(2)
+ else:
+ self.disconnect()
+ raise Exception("Cannot find delimiter for mailbox "
+ + self.mailbox)
else:
self.disconnect()
raise Exception("Cannot find mailbox " + self.mailbox)
self.disconnect()
# replace any previous delimiter in self.mailbox by "/"
- if self.delimiter != "/":
- self.mailbox = self.mailbox.replace(self.delimiter, "/")
+ if self.delimiter != testing_delimiter:
+ self.mailbox = self.mailbox.replace(testing_delimiter,
+ self.delimiter)
class POP3Account(MailAccount):
diff --git a/src/jmc/model/tests/account.py b/src/jmc/model/tests/account.py
index e811ce9..a46236f 100644
--- a/src/jmc/model/tests/account.py
+++ b/src/jmc/model/tests/account.py
@@ -730,10 +730,10 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
def test_populate_handler(self):
self.assertEquals(".", self.imap_account.delimiter)
- self.imap_account.mailbox = "INBOX.dir1.subdir2"
+ self.imap_account.mailbox = "INBOX/dir1/subdir2"
def call_func(self):
self.imap_account.populate_handler()
- self.assertEquals("INBOX/dir1/subdir2", self.imap_account.mailbox)
+ self.assertEquals("INBOX.dir1.subdir2", self.imap_account.mailbox)
test_func = self.make_test(\
[lambda data: '* LIST () "." "INBOX.dir1.subdir2"\r\n' + \
data.split()[0] + ' OK LIST completed\r\n'],
@@ -741,6 +741,22 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
call_func)
test_func()
+ def test_populate_handler_wrong_default_delimiter(self):
+ self.imap_account.delimiter = "/"
+ self.imap_account.mailbox = "INBOX/dir1/subdir2"
+ def call_func(self):
+ self.imap_account.populate_handler()
+ self.assertEquals("INBOX.dir1.subdir2", self.imap_account.mailbox)
+ self.assertEquals(".", self.imap_account.delimiter)
+ test_func = self.make_test(\
+ [lambda data: data.split()[0] + ' OK LIST completed\r\n',
+ lambda data: '* LIST () "." "INBOX.dir1.subdir2"\r\n' + \
+ data.split()[0] + ' OK LIST completed\r\n'],
+ ["^[^ ]* LIST \"?INBOX/dir1/subdir2\"? \*",
+ "^[^ ]* LIST \"?INBOX.dir1.subdir2\"? \*"],
+ call_func)
+ test_func()
+
def test_populate_handler_wrong_mailbox(self):
self.assertEquals(".", self.imap_account.delimiter)
self.imap_account.mailbox = "INBOX.dir1.subdir2"