Changeset 168

Show
Ignore:
Timestamp:
07/25/08 22:53:23 (6 months ago)
Author:
David Rousselie <dax@happycoders.org>
Message:

Correct IMAPAccount populate_handler

IMAP list with wrong delimiter could return [None], so trying with another delimiter in that case

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/jmc/model/account.py

    r167 r168  
    436436        return current_folder.keys() 
    437437 
    438     def populate_handler(self): 
     438    def populate_handler(self, try_other_delimiter=True, testing_delimiter="/"): 
    439439        """ 
    440440        Handler called when populating account 
     
    446446        if typ == 'OK': 
    447447            line = data[0] 
    448             match = self._regexp_list.match(line) 
    449             if match is not None: 
    450                 self.delimiter = match.group(2) 
     448            if line is None: 
     449                if try_other_delimiter: 
     450                    self.mailbox = self.mailbox.replace(testing_delimiter, 
     451                                                        ".") 
     452                    self.populate_handler(False, ".") 
     453                    return 
     454                else: 
     455                    self.disconnect() 
     456                    raise Exception("Cannot find mailbox " + self.mailbox) 
    451457            else: 
    452                 self.disconnect() 
    453                 raise Exception("Cannot find delimiter for mailbox " 
    454                                 + self.mailbox) 
     458                match = self._regexp_list.match(line) 
     459                if match is not None: 
     460                    self.delimiter = match.group(2) 
     461                else: 
     462                    self.disconnect() 
     463                    raise Exception("Cannot find delimiter for mailbox " 
     464                                    + self.mailbox) 
    455465        else: 
    456466            self.disconnect() 
     
    458468        self.disconnect() 
    459469        # replace any previous delimiter in self.mailbox by "/" 
    460         if self.delimiter != "/": 
    461             self.mailbox = self.mailbox.replace(self.delimiter, "/") 
     470        if self.delimiter != testing_delimiter: 
     471            self.mailbox = self.mailbox.replace(testing_delimiter, 
     472                                                self.delimiter) 
    462473 
    463474 
  • src/jmc/model/tests/account.py

    r154 r168  
    731731    def test_populate_handler(self): 
    732732        self.assertEquals(".", self.imap_account.delimiter) 
    733         self.imap_account.mailbox = "INBOX.dir1.subdir2" 
     733        self.imap_account.mailbox = "INBOX/dir1/subdir2" 
    734734        def call_func(self): 
    735735            self.imap_account.populate_handler() 
    736             self.assertEquals("INBOX/dir1/subdir2", self.imap_account.mailbox) 
     736            self.assertEquals("INBOX.dir1.subdir2", self.imap_account.mailbox) 
    737737        test_func = self.make_test(\ 
    738738            [lambda data: '* LIST () "." "INBOX.dir1.subdir2"\r\n' + \ 
    739739                 data.split()[0] + ' OK LIST completed\r\n'], 
    740740            ["^[^ ]* LIST \"?INBOX.dir1.subdir2\"? \*"], 
     741            call_func) 
     742        test_func() 
     743 
     744    def test_populate_handler_wrong_default_delimiter(self): 
     745        self.imap_account.delimiter = "/" 
     746        self.imap_account.mailbox = "INBOX/dir1/subdir2" 
     747        def call_func(self): 
     748            self.imap_account.populate_handler() 
     749            self.assertEquals("INBOX.dir1.subdir2", self.imap_account.mailbox) 
     750            self.assertEquals(".", self.imap_account.delimiter) 
     751        test_func = self.make_test(\ 
     752            [lambda data: data.split()[0] + ' OK LIST completed\r\n', 
     753             lambda data: '* LIST () "." "INBOX.dir1.subdir2"\r\n' + \ 
     754                 data.split()[0] + ' OK LIST completed\r\n'], 
     755            ["^[^ ]* LIST \"?INBOX/dir1/subdir2\"? \*", 
     756             "^[^ ]* LIST \"?INBOX.dir1.subdir2\"? \*"], 
    741757            call_func) 
    742758        test_func()