简体   繁体   English

Python中imaplib.IMAP4_SSL()。search的输出是什么意思?

[英]What does the output mean of imaplib.IMAP4_SSL().search in Python?

m = imaplib.IMAP4_SSL('imap.gmail.com')
typ, accountDetails =m.login(userName, passwd)
m.select("inbox")
resp, data = m.search(None, "(ON {0})".format( time.strftime("%d-%b-%Y") ),'(FROM "email")' )
print(resp)
print(data)

This gives me the output: 这给了我输出:

OK
[b'6391 6395']

So I assume 'OK' means it found an email but I'm not sure what the ' [b '6391 6395'] means. 因此,我认为“确定”表示找到了电子邮件,但是我不确定“ [b'6391 6395”]是什么意思。 What do those numbers represent? 这些数字代表什么?

imaplib does not really parse responses, so you're getting a fairly raw response from the library. imaplib并未真正解析响应,因此您从库中获得了相当原始的响应。 The OK is the overall response to the command, which means that the server understood your request. OK是对命令的总体响应,这意味着服务器可以理解您的请求。

Each line of the response is returned as an item in a list. 响应的每一行作为列表中的项目返回。 SEARCH only returns one line, so you have a list of one item. SEARCH只返回一行,因此您具有一项的列表。 Since imaplib does not do any parsing, you are getting the text of that response in it's original format: a bytes object of space separated numbers, representing Message Sequence Numbers. 由于imaplib不进行任何解析,因此您将以原始格式获取该响应的文本:用空格分隔数字的字节对象,表示消息序列号。

You should be able to get a list of MSNs with msns = data[0].split(b' ') . 您应该能够获得msns = data[0].split(b' ')的MSN列表。

You can then loop over this list to obtain further information, for example: 然后,您可以遍历此列表以获得更多信息,例如:

for msn in msns:
  resp, data = m.fetch(msn, '(RFC822)')

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

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