def get_mail(self, which: int): """Get a mail from mailbox.""" server = self._init_pop3() mail = server.get_mail(which) server.logout() return mail_decode(mail, which)
def get_latest(self): """Get latest mail in mailbox.""" server = self._init_pop3() latest_num = server.stat()[0] mail = server.get_mail(latest_num) server.logout() return mail_decode(mail, latest_num)
def get_mails(self, subject=None, after=None, before=None, sender=None): """Get a list of mails from mailbox.""" info = self.get_info() mail_id = [] for index, mail in enumerate(info): if self._match(decode_headers(mail), subject, after, before, sender): mail_id.append(index + 1) server = self._init_pop3() mail_id.sort() mail_as_bytes_list = server.get_mails(mail_id) server.logout() return [mail_decode(mail_as_bytes, mail_id[index]) for index, mail_as_bytes in enumerate(mail_as_bytes_list)]