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
This commit is contained in:
@@ -435,7 +435,7 @@ class IMAPAccount(MailAccount):
|
|||||||
current_folder = current_folder[folder]
|
current_folder = current_folder[folder]
|
||||||
return current_folder.keys()
|
return current_folder.keys()
|
||||||
|
|
||||||
def populate_handler(self):
|
def populate_handler(self, try_other_delimiter=True, testing_delimiter="/"):
|
||||||
"""
|
"""
|
||||||
Handler called when populating account
|
Handler called when populating account
|
||||||
"""
|
"""
|
||||||
@@ -445,6 +445,16 @@ class IMAPAccount(MailAccount):
|
|||||||
typ, data = self.connection.list(self.mailbox)
|
typ, data = self.connection.list(self.mailbox)
|
||||||
if typ == 'OK':
|
if typ == 'OK':
|
||||||
line = data[0]
|
line = data[0]
|
||||||
|
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:
|
||||||
match = self._regexp_list.match(line)
|
match = self._regexp_list.match(line)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
self.delimiter = match.group(2)
|
self.delimiter = match.group(2)
|
||||||
@@ -457,8 +467,9 @@ class IMAPAccount(MailAccount):
|
|||||||
raise Exception("Cannot find mailbox " + self.mailbox)
|
raise Exception("Cannot find mailbox " + self.mailbox)
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
# replace any previous delimiter in self.mailbox by "/"
|
# replace any previous delimiter in self.mailbox by "/"
|
||||||
if self.delimiter != "/":
|
if self.delimiter != testing_delimiter:
|
||||||
self.mailbox = self.mailbox.replace(self.delimiter, "/")
|
self.mailbox = self.mailbox.replace(testing_delimiter,
|
||||||
|
self.delimiter)
|
||||||
|
|
||||||
|
|
||||||
class POP3Account(MailAccount):
|
class POP3Account(MailAccount):
|
||||||
|
|||||||
@@ -730,10 +730,10 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
|
|
||||||
def test_populate_handler(self):
|
def test_populate_handler(self):
|
||||||
self.assertEquals(".", self.imap_account.delimiter)
|
self.assertEquals(".", self.imap_account.delimiter)
|
||||||
self.imap_account.mailbox = "INBOX.dir1.subdir2"
|
self.imap_account.mailbox = "INBOX/dir1/subdir2"
|
||||||
def call_func(self):
|
def call_func(self):
|
||||||
self.imap_account.populate_handler()
|
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(\
|
test_func = self.make_test(\
|
||||||
[lambda data: '* LIST () "." "INBOX.dir1.subdir2"\r\n' + \
|
[lambda data: '* LIST () "." "INBOX.dir1.subdir2"\r\n' + \
|
||||||
data.split()[0] + ' OK LIST completed\r\n'],
|
data.split()[0] + ' OK LIST completed\r\n'],
|
||||||
@@ -741,6 +741,22 @@ class IMAPAccount_TestCase(InheritableAccount_TestCase):
|
|||||||
call_func)
|
call_func)
|
||||||
test_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):
|
def test_populate_handler_wrong_mailbox(self):
|
||||||
self.assertEquals(".", self.imap_account.delimiter)
|
self.assertEquals(".", self.imap_account.delimiter)
|
||||||
self.imap_account.mailbox = "INBOX.dir1.subdir2"
|
self.imap_account.mailbox = "INBOX.dir1.subdir2"
|
||||||
|
|||||||
Reference in New Issue
Block a user