【问题标题】:Python imaplib search VariablesPython imaplib 搜索变量
【发布时间】:2016-03-07 02:43:48
【问题描述】:

我正在尝试使用带有变量的 imaplib 进行搜索。当我对信息进行硬编码时,搜索效果很好。

result, data = mail.search(None,'(SENTSINCE "15-Oct-2015" SENTBEFORE "19-Oct-2015")'.format(date=date))

我尝试了很多设置变量的方法,从其他帖子看来,最好的方法是将整个搜索参数设置为变量并以这种方式调用它。

search_string = '(SENTSINCE \"' + start_date_format + '\" SENTBEFORE \"' + format_endday + '\" )\'.format(date=date)'
result, data = mail.search(None, search_string)

变量设置的打印看起来很准确:

(SENTSINCE "12-Oct-2015" SENTBEFORE "19-Oct-2015" )'.format(date=date)

我收到以下错误:

    Traceback (most recent call last):
  File "infringment-report.py", line 74, in <module>
    result, data = mail.search(None, search_string)
  File "/usr/lib/python2.7/imaplib.py", line 639, in search
    typ, dat = self._simple_command(name, *criteria)
  File "/usr/lib/python2.7/imaplib.py", line 1087, in _simple_command
    return self._command_complete(name, self._command(name, *args))
  File "/usr/lib/python2.7/imaplib.py", line 917, in _command_complete
    raise self.error('%s command error: %s %s' % (name, typ, data))
imaplib.error: SEARCH command error: BAD ['The specified message set is invalid.']

我一直在努力解决这个问题,不胜感激。

【问题讨论】:

  • 我也很想知道如何在 imaplib 搜索中使用变量!

标签: python imaplib


【解决方案1】:

我也是 python 和 imaplib 的新手,但我想这会很好。

用于检索名称存储在变量中的邮件,例如 fromname 那么

let criteria = ['From', fromname]
typ, [msg_id] = mail.search(None, *criteria).

【讨论】:

    猜你喜欢
    • 2011-10-03
    • 2013-08-05
    • 1970-01-01
    • 2017-04-05
    • 2015-08-04
    • 2016-08-15
    • 2011-07-06
    • 2018-10-26
    • 1970-01-01
    相关资源
    最近更新 更多