简体   繁体   English

如何使用python在imaplib中按时间对电子邮件进行排序

[英]How to sort email by time in imaplib using python

I would like to sort the emails by arrival time.我想按到达时间对电子邮件进行排序。

Here is the code:这是代码:

data = get_credential('info.txt')
imap_conn = create_connection(data, 'outlook.office365.com')
imap_conn.select('INBOX', readonly=False)
result, messages = imap_conn.sort('ARRIVAL', 'UTF-8', 'FROM peter@gmail.com SINCE "'+(datetime.date.today()-datetime.timedelta(4)).strftime('%d-%b-%Y')+'" 

It returns the following error:它返回以下错误:

File "C:\Program Files\Python37\lib\imaplib.py", line 794, in sort
    typ, dat = self._simple_command(name, sort_criteria, charset, *search_criteria)
  File "C:\Program Files\Python37\lib\imaplib.py", line 1196, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "C:\Program Files\Python37\lib\imaplib.py", line 1027, in _command_complete
    raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.IMAP4.error: SORT command error: BAD [b'Command Error. 12']

How to solve the problem?如何解决问题?

Is the input charset UTF-8 correct?输入字符集UTF-8是否正确? How to get it from messages ?如何从messages获取?

Office365 doesn't support the SORT extension. Office365 不支持SORT扩展。

* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+

You should check CAPABILITY before using any extensions.在使用任何扩展之前,您应该检查CAPABILITY

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

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