def update_metadata(self, key: str, msg: MaildirMessage) -> None: """Uses :func:`os.rename` to atomically update the message filename based on :meth:`~mailbox.MaildirMessage.get_info`. """ subpath = self._lookup(key) subdir, name = os.path.split(subpath) new_subdir = msg.get_subdir() new_name = key + self.colon + msg.get_info() if subdir != new_subdir: raise ValueError('Message subdir may not be updated') elif name != new_name: new_subpath = os.path.join(msg.get_subdir(), new_name) old_path = os.path.join(self._path, subpath) new_path = os.path.join(self._path, new_subpath) os.rename(old_path, new_path) self._toc[key] = new_subpath
def from_maildir(cls, uid: int, maildir_msg: MaildirMessage, maildir: Maildir, key: str, email_id: Optional[ObjectId], thread_id: Optional[ObjectId], maildir_flags: MaildirFlags) -> Message: flag_set = maildir_flags.from_maildir(maildir_msg.get_flags()) recent = maildir_msg.get_subdir() == 'new' msg_dt = datetime.fromtimestamp(maildir_msg.get_date()) return cls(uid, msg_dt, flag_set, email_id=email_id, thread_id=thread_id, recent=recent, maildir=maildir, key=key)
def from_maildir(cls, uid: int, maildir_msg: MaildirMessage, maildir_flags: 'MaildirFlags', metadata_only: bool) -> 'Message': flag_set = maildir_flags.from_maildir(maildir_msg.get_flags()) recent = maildir_msg.get_subdir() == 'new' msg_dt = datetime.fromtimestamp(maildir_msg.get_date()) if metadata_only: return cls(uid, flag_set, msg_dt, recent=recent, maildir_flags=maildir_flags) else: msg_data = bytes(maildir_msg) return cls.parse(uid, msg_data, flag_set, msg_dt, recent=recent, maildir_flags=maildir_flags)