从网络邮件中删除邮件-不适用于所有文件夹

问题描述

我正在使用以下代码从网络邮件删除电子邮件

def process_webmail():
    Box = imaplib.IMAP4_SSL(server)
    Box.login(username,password)
    print("Connected to webmail")
    _tuple = Box.list()
    if len(_tuple) <= 0:
        return

    before_date = (datetime.date.today() - datetime.timedelta(30)).strftime("%d-%b-%Y") 
    for folder in _tuple[1]:
        _folder_name = folder.split('\"/\"')
                    
        f = _folder_name[1].strip().strip('\"')
        if f.lower() == "inBox":
            pass
        else:
            Box.select(f)
            # typ,data = Box.search(None,'ALL')
            typ,'(BEFORE {0})'.format(before_date))
            if data != ['']:
                for num in data[0].split():
                    Box.store(num,'+FLAGS','\\Deleted')

    print(Box.expunge())
    Box.close()
    Box.logout()

我们有2种类型的文件夹。 1)创建文件夹并将邮件手动复制到该文件夹​​。 2)已应用过滤器以复制邮件

以上代码在1上有效,而在2的情况下仅将电子邮件标记为已删除。不知道是什么问题。有人请帮助我了解这个问题。

Roundcube是正在使用的网络邮件

解决方法

以下代码有效。错误放置的.expunge()

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin: /usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d