简体   繁体   English

带有 GMail 的 Imaplib 偏移 uid

[英]Imaplib with GMail offsets uids

I'm querying my gmail inbox using pythons ImapLib with a range parameter, but my returned uids are offset from what I request.我正在使用带有范围参数的 python ImapLib 查询我的 gmail 收件箱,但我返回的 uid 与我请求的有所偏移。 My request is as follows:我的要求如下:

M = imaplib.IMAP4_SSL('imap.gmail.com')
M.login(USER, PASS)
# Choose the inbox for finding mail
M.select('INBOX')
rv, data = M.uid("search", None, '29540:*')

This returns a single UID, 29725.这将返回一个 UID,29725。

If I subtract 421 (found by trial and error) from the beginning range I get the full list of uids from from 29540 to 29725. I am stumped.如果我从开始范围中减去 421(通过反复试验发现),我会得到从 29540 到 2972​​5 的完整 uid 列表。我很难过。 Could it be that it is not using UID in this range and is somehow having problems with deleted emails?可能是因为它没有在此范围内使用 UID,并且在删除电子邮件时遇到了问题?

It seems like M.uid simply specifies that the return value will be UID's, so it is still necessary to specify that the parameters sent will be UID's and not message ID's.似乎M.uid只是简单地指定返回值将是 UID,因此仍然需要指定发送的参数将是 UID 而不是消息 ID。 This fixes it:这修复了它:

rv, data = M.uid("search", None, 'UID', '29540:*')

rv, data = M.uid("search", None, '(UID 29540:*)')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM