Exemplo n.º 1
0
 async def get_mailbox(self,
                       name: str,
                       try_create: bool = False) -> MailboxData:
     if name.upper() == 'INBOX':
         return self._inbox
     async with self._set_lock.read_lock():
         if name not in self._set:
             raise MailboxNotFound(name, try_create)
         return self._set[name]
Exemplo n.º 2
0
 async def delete_mailbox(self, name: str) -> None:
     try:
         self._layout.remove_folder(name, self.delimiter)
     except FileNotFoundError:
         raise MailboxNotFound(name)
     except OSError as exc:
         if exc.errno == errno.ENOTEMPTY:
             raise MailboxHasChildren(name) from exc
         raise exc
Exemplo n.º 3
0
 async def delete_mailbox(self, name: str) -> None:
     redis = self._redis
     name_key = modutf7_encode(name)
     await redis.unwatch()
     multi = redis.multi_exec()
     multi.hget(self._keys.mailboxes, name_key)
     multi.hdel(self._keys.mailboxes, name_key)
     mbx_id, _ = await multi.execute()
     if mbx_id is None:
         raise MailboxNotFound(name)
     mbx_keys = MailboxKeys(self._keys, mbx_id)
     pipe = redis.pipeline()
     pipe.zrem(self._keys.order, mbx_id)
     pipe.set(mbx_keys.abort, 1)
     self._cleanup.add_mailbox(pipe, mbx_keys)
     await pipe.execute()
Exemplo n.º 4
0
 async def get_mailbox(self, name: str,
                       try_create: bool = False) -> MailboxData:
     if name == 'INBOX':
         maildir = self._inbox_maildir
     else:
         try:
             maildir = self._layout.get_folder(name, self.delimiter)
         except FileNotFoundError:
             raise MailboxNotFound(name, try_create)
     if name in self._cache:
         mbx = self._cache[name]
     else:
         path = self._layout.get_path(name, self.delimiter)
         async with UidList.with_open(path) as uidl:
             mailbox_id = ObjectId(uidl.global_uid)
         mbx = MailboxData(mailbox_id, maildir, path)
         self._cache[name] = mbx
     return await mbx.reset()
Exemplo n.º 5
0
 async def rename_mailbox(self, before: str, after: str) -> None:
     async with self._set_lock.read_lock():
         tree = ListTree(self.delimiter).update('INBOX', *self._set.keys())
         before_entry = tree.get(before)
         after_entry = tree.get(after)
         if before_entry is None:
             raise MailboxNotFound(before)
         elif after_entry is not None:
             raise MailboxConflict(after)
     async with self._set_lock.write_lock():
         for before_name, after_name in tree.get_renames(before, after):
             if before_name == 'INBOX':
                 self._set[after_name] = self._inbox
                 self._inbox = MailboxData(self._content_cache,
                                           self._thread_cache)
             else:
                 self._set[after_name] = self._set[before_name]
                 del self._set[before_name]
Exemplo n.º 6
0
 async def get_mailbox(self,
                       name: str,
                       try_create: bool = False) -> MailboxData:
     redis = self._redis
     name_key = modutf7_encode(name)
     while True:
         pipe = watch_pipe(redis, self._keys.mailboxes)
         pipe.hget(self._keys.mailboxes, name_key)
         _, _, mbx_id = await pipe.execute()
         if mbx_id is None:
             raise MailboxNotFound(name, try_create)
         multi = redis.multi_exec()
         multi.hget(self._keys.uid_validity, name_key)
         try:
             uidval, *_ = await multi.execute()
         except MultiExecError:
             if await check_errors(multi):
                 raise
         else:
             mbx_keys = MailboxKeys(self._keys, mbx_id)
             return MailboxData(redis, mbx_id, int(uidval), mbx_keys,
                                self._keys, self._cleanup)
Exemplo n.º 7
0
 async def delete_mailbox(self, name: str) -> None:
     async with self._set_lock.read_lock():
         if name not in self._set:
             raise MailboxNotFound(name)
     async with self._set_lock.write_lock():
         del self._set[name]