python imaplib 在看不见的邮箱中收到一封看见的电子邮件

问题描述 投票:0回答:1

我收到了一些标记为 mail_status="UNSEEN" 的电子邮件。下面是我的代码。如果您能帮助我,我将非常感激。

def get_email(self, mail_index=None,  mail_status="UNSEEN", mailbox="INBOX"):       
    self.imap_client.select(mailbox,readonly=False)
    _, dat = self.imap_client.search(None, mail_status)
   if not dat\[0\]:
       raise RuntimeError("not email")

    if mail_index is None:
        mail_index = dat[0].decode("utf-8").split(" ")[-1]
    mail_index = str(mail_index)
    #@patch:some seen email appear
    self.is_may_seen_before=False
    if self.is_email_seen(mail_index):
        self.is_may_seen_before=True
    
    _, dat = self.imap_client.fetch(mail_index, '(RFC822)')
    dat_obj = ParseEmail(dat[0][1])
    
    return dat_obj

def is_email_seen(self, mail_index):
   try:
        _, status = self.imap_client.fetch(mail_index, '(FLAGS)')
        return "\\Seen" in status\[0\].decode()
    except Exception as e:
        del_err(e)
        return False
python email imaplib
1个回答
0
投票

抱歉,我在 get_email 函数中又敲了一个 dat[0]

© www.soinside.com 2019 - 2024. All rights reserved.