我正在使用 imaplib 和 Python 来获取我的收件箱或 GMail 标签的内容。
我的问题是:当我查询收件箱时,imaplib 返回 UID,而不是我的电子邮件标签。
如果我查询收件箱,我会得到 UID:
inbox EMAIL_UIDS: 24408 24599 25193 25224 25237 25406 25411 25412 25413 25415
但是,如果我查询我的标签“New”(其中包含收件箱中的两条消息,因此应该包含上述两个 UID),我只会得到有序索引:
New EMAIL_UIDS: 1 2
我的代码是:
#Main file
if folder_name is None:
email_uids = obtain_inbox_email_uids(mail)
else:
email_uids = obtain_folder_email_uids(folder_name,mail)
email_uids = list(email_uids)
和:
#Email utilities file
def obtain_folder_email_uids(folder_name, mail):
"""
Given an IMAP instance,
return the UIDs of the emails in a specific folder.
"""
mail.select(folder_name)
result, data = mail.uid('search', None, "ALL")
print "RESULT, DATA",result,data
email_uids = data[0]
print folder_name,"EMAIL_UIDS:",email_uids
email_uids = email_uids.split(" ")
email_uids = reversed(email_uids)
return email_uids
def obtain_inbox_email_uids(mail):
"""
Given an IMAP instance,
return the UIDs of the inbox emails.
"""
return obtain_folder_email_uids('inbox', mail)
有谁知道为什么 imaplib 返回收件箱的 UID 但为特定标签排序索引,我怎样才能让它返回 UID?
谢谢