Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python imaplib不会将消息标记为不可见_Python_Imaplib - Fatal编程技术网

Python imaplib不会将消息标记为不可见

Python imaplib不会将消息标记为不可见,python,imaplib,Python,Imaplib,我正在开发一个从电子邮件中收集数据的功能,它有一个开关,可以将邮件标记为看不见。在开发过程中,它开始失败,我不知道为什么。我在文档中查找了它,搜索了stackoverflow(找到了线程,但没有帮助)。无论如何代码如下: mail = imaplib.IMAP4_SSL('imap.gmail.com', '993') mail.login(settings.INVOICES_LOGIN, settings.INVOICES_PASSWORD) mail.select('

我正在开发一个从电子邮件中收集数据的功能,它有一个开关,可以将邮件标记为看不见。在开发过程中,它开始失败,我不知道为什么。我在文档中查找了它,搜索了stackoverflow(找到了线程,但没有帮助)。无论如何代码如下:

    mail = imaplib.IMAP4_SSL('imap.gmail.com', '993')
    mail.login(settings.INVOICES_LOGIN, settings.INVOICES_PASSWORD)
    mail.select('inbox')

    result, data = mail.uid('search', '(UNSEEN)', 'X-GM-RAW',
                            'SUBJECT: "{0}" FROM: "{1}"'.format(attachment_subject, attachment_from))
    uids = data[0].split()
    for uid in uids:
        result, data = mail.uid('fetch', uid, '(RFC822)')
        m = email.message_from_string(data[0][1])

        if m.get_content_maintype() == 'multipart':
            for part in m.walk():
                if part.get_content_maintype() == 'multipart':
                    continue
                if part.get('Content-Disposition') is None:
                    continue
                if re.match(attachment_filename_re, part.get_filename()):
                    attachments.append({'uid': uid, 'data': part.get_payload(decode=True)})

        if set_not_read:
            mail.store(uid, '-FLAGS', '(\Seen)')
我已经调试了它,我确信有了这个标志,输入了
mail.store(uid,'-FLAGS','(\Seen)
部分,我还尝试切换到
\Seen
\Seen
,而不是(\Seen)

编辑:

我正在尝试做的是制作一个脚本,允许用户将电子邮件标记为“未看到”(未读),这是重置“已看到”(未读)标志,而不是允许它将电子邮件标记为“已看到”(已读)。

我相信您需要

mail.store(uid, '+FLAGS', '(\\Seen)')
我认为你现在正在做的是移除被看见的旗帜。但我会查一下RFC来确定

编辑:是的。这就是问题所在

-标志
从消息的标志中删除参数。新的
将返回标志的值,就好像已获取这些标志一样
完成。
您可能会发现相关的其他位:

The currently defined data items that can be stored are:

      FLAGS <flag list>
         Replace the flags for the message (other than \Recent) with the
         argument.  The new value of the flags is returned as if a FETCH
         of those flags was done.

      FLAGS.SILENT <flag list>
         Equivalent to FLAGS, but without returning a new value.

      +FLAGS <flag list>
         Add the argument to the flags for the message.  The new value
         of the flags is returned as if a FETCH of those flags was done.

      +FLAGS.SILENT <flag list>
         Equivalent to +FLAGS, but without returning a new value.

      -FLAGS <flag list>
         Remove the argument from the flags for the message.  The new
         value of the flags is returned as if a FETCH of those flags was
         done.

      -FLAGS.SILENT <flag list>
         Equivalent to -FLAGS, but without returning a new value.
当前定义的可存储数据项包括:
旗帜
将消息的标志(而不是\Recent)替换为
论点将返回标志的新值,就像获取一样
这些旗子中的一个已经完成。
沉默
等同于标志,但不返回新值。
+旗帜
将参数添加到消息的标志中。新价值
返回这些标志的个数,就好像完成了对这些标志的提取一样。
+沉默
等同于+标志,但不返回新值。
-旗帜
从消息的标志中删除参数。新的
将返回标志的值,就好像已获取这些标志一样
完成。
-沉默
等效于-FLAGS,但不返回新值。

最近我自己使用了
imaplib
,我可以确认问题的状态非常可怜。
mail.store(uid,'-FLAGS','(\\SEEN)
的输出是什么?不,它就是不工作。“不工作”-这是否意味着它会产生错误?什么也不生产?因为
mail.store
应该生成一个结果。您可以执行
print(mail.store(uid),“-FLAGS',”(\\SEEN)
,它应该会产生一些东西,即使这些东西是回溯。如果什么都没有发生,那么就会发生一些非常奇怪的事情。我的意思是结果是一个元组('OK',[None])邮箱中的邮件仍然标记为已读。是的,这正是我正在尝试做的。将电子邮件标记为
未看到
。我认为标题很清楚,我现在就更正它。那么,您是否尝试过-FLAGS(\\Seen)?您没有使用原始字符串,因此需要避开反斜杠。
The currently defined data items that can be stored are:

      FLAGS <flag list>
         Replace the flags for the message (other than \Recent) with the
         argument.  The new value of the flags is returned as if a FETCH
         of those flags was done.

      FLAGS.SILENT <flag list>
         Equivalent to FLAGS, but without returning a new value.

      +FLAGS <flag list>
         Add the argument to the flags for the message.  The new value
         of the flags is returned as if a FETCH of those flags was done.

      +FLAGS.SILENT <flag list>
         Equivalent to +FLAGS, but without returning a new value.

      -FLAGS <flag list>
         Remove the argument from the flags for the message.  The new
         value of the flags is returned as if a FETCH of those flags was
         done.

      -FLAGS.SILENT <flag list>
         Equivalent to -FLAGS, but without returning a new value.