def rename(self, oldname, newname): """ Renames a mailbox. :param oldname: old name of the mailbox :type oldname: str :param newname: new name of the mailbox :type newname: str """ oldname = self._parse_mailbox_name(oldname) newname = self._parse_mailbox_name(newname) if oldname not in self.mailboxes: raise imap4.NoSuchMailbox(repr(oldname)) inferiors = self._inferiorNames(oldname) inferiors = [(o, o.replace(oldname, newname, 1)) for o in inferiors] for (old, new) in inferiors: if new in self.mailboxes: raise imap4.MailboxCollision(repr(new)) for (old, new) in inferiors: self._memstore.rename_fdocs_mailbox(old, new) mbox = self._get_mailbox_by_name(old) mbox.content[self.MBOX_KEY] = new self._soledad.put_doc(mbox) self._load_mailboxes()
def addMailbox(self, name, creation_ts=None): """ Add a mailbox to the account. :param name: the name of the mailbox :type name: str :param creation_ts: an optional creation timestamp to be used as mailbox id. A timestamp will be used if no one is provided. :type creation_ts: int :returns: True if successful :rtype: bool """ name = self._parse_mailbox_name(name) if name in self.mailboxes: raise imap4.MailboxCollision(repr(name)) if not creation_ts: # by default, we pass an int value # taken from the current time # we make sure to take enough decimals to get a unique # mailbox-uidvalidity. creation_ts = int(time.time() * 10E2) mbox = self._get_empty_mailbox() mbox[self.MBOX_KEY] = name mbox[self.CREATED_KEY] = creation_ts doc = self._soledad.create_doc(mbox) self._load_mailboxes() return bool(doc)
def rename_inferiors((inferiors, mailboxes)): rename_deferreds = [] inferiors = [ (o, o.replace(oldname, newname, 1)) for o in inferiors] for (old, new) in inferiors: if new in mailboxes: raise imap4.MailboxCollision(repr(new)) for (old, new) in inferiors: d = self.account.rename_mailbox(old, new) rename_deferreds.append(d) d1 = defer.gatherResults(rename_deferreds, consumeErrors=True) return d1