Delete all emails before X date

Discussion in 'ISPConfig 3 Priority Support' started by Stelios, Jan 5, 2021.

  1. Stelios

    Stelios Member HowtoForge Supporter

    Hi all,

    I'm trying to figure out how to clear a mailbox somehow automatically.
    What I want is to delete any email that is older than X days from the imap folders.

    I tried as per Dovecot docs:
    Code:
    doveadm expunge -u [email protected] mailbox INBOX SENTBEFORE 1-Jan-2020
    but it doesn't delete any email. The command ends without errors but emails before 1-Jan-2020 are still there.

    Any help is more than welcome.

    Thanks
     
  2. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    Try 2020-01-01 as date format.
     
  3. Stelios

    Stelios Member HowtoForge Supporter

    Same problem; it doesn't delete any email and there are hundreds before that date.
    Code:
    [email protected]:/var/vmail/mydomain.com/info/Maildir# du -csh ../Maildir/
    3.2G    ../Maildir/
    3.2G    total
    [email protected]:/var/vmail/mydomain.com/info/Maildir# doveadm expunge -u [email protected] mailbox INBOX SENTBEFORE 2020-01-01
    [email protected]:/var/vmail/mydomain.com/info/Maildir# du -csh ../Maildir/
    3.2G    ../Maildir/
    3.2G    total
     
  4. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    In the inbox, or in other folders?
     
  5. Stelios

    Stelios Member HowtoForge Supporter

    I'm not sure what you are saying Thom. The largest folder is the cur inside the Maildir folder.
    This particular email that I'm trying to cleanup has no custom folders.
     
  6. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    doveadm-expunge man page tells how to test which e-mails match the query. Have you tried that?
     
  7. Stelios

    Stelios Member HowtoForge Supporter

    There isn't any doveadm-expunge command, it is used as the command I pasted above (command with argument).
     
  8. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

  9. Stelios

    Stelios Member HowtoForge Supporter

  10. Th0m

    Th0m ISPConfig Developer Staff Member ISPConfig Developer

    Can you run the expunge command with the -D parameter for debug output?
     
  11. till

    till Super Moderator Staff Member ISPConfig Developer

    ahrasis and Th0m like this.
  12. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    I never said there was.
    However, the man page exists. At least on my Debian 9 system.
    Code:
    # man doveadm-expunge  | head
    DOVEADM-EXPUNGE(1)                  Dovecot                 DOVEADM-EXPUNGE(1)
    
    NAME
           doveadm-expunge - Expunge messages matching given search query
    
    SYNOPSIS
           doveadm [-Dv] expunge [-S socket_path] [-d] search_query
           doveadm [-Dv] expunge [-S socket_path] [-d] -A search_query
           doveadm [-Dv] expunge [-S socket_path] [-d] -F file search_query
           doveadm [-Dv] expunge [-S socket_path] [-d] -u user search_query
    
     
    ahrasis likes this.
  13. Stelios

    Stelios Member HowtoForge Supporter

    @Taleman, I've read the man page and tried a few things which didn't work and this is why I'm posting in the forums.

    Here is the output with the debug enabled:

    Code:
    [email protected]:# doveadm -D expunge -u [email protected] mailbox '*' before 30w
    Debug: Loading modules from directory: /usr/lib/dovecot/modules
    Debug: Module loaded: /usr/lib/dovecot/modules/lib10_quota_plugin.so
    Debug: Loading modules from directory: /usr/lib/dovecot/modules/doveadm
    Debug: Skipping module doveadm_acl_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/lib10_doveadm_acl_plugin.so: undefined symbol: acl_user_module (this is usually intentional, so just ignore this message)
    Debug: Skipping module doveadm_expire_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/lib10_doveadm_expire_plugin.so: undefined symbol: expire_set_deinit (this is usually intentional, so just ignore this message)
    Debug: Module loaded: /usr/lib/dovecot/modules/doveadm/lib10_doveadm_quota_plugin.so
    Debug: Module loaded: /usr/lib/dovecot/modules/doveadm/lib10_doveadm_sieve_plugin.so
    Debug: Skipping module doveadm_fts_lucene_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/lib20_doveadm_fts_lucene_plugin.so: undefined symbol: lucene_index_iter_deinit (this is usually intentional, so just ignore this message)
    Debug: Skipping module doveadm_fts_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/lib20_doveadm_fts_plugin.so: undefined symbol: fts_user_get_language_list (this is usually intentional, so just ignore this message)
    Debug: Skipping module doveadm_mail_crypt_plugin, because dlopen() failed: /usr/lib/dovecot/modules/doveadm/libdoveadm_mail_crypt_plugin.so: undefined symbol: mail_crypt_box_get_pvt_digests (this is usually intentional, so just ignore this message)
    doveadm([email protected])<31431><>: Debug: auth USER input: [email protected] home=/var/vmail/mydomain.com/info mail=maildir:/var/vmail/mydomain.com/info/Maildir uid=5000 gid=5000 quota_rule=*:storage=4294967296B sieve=/var/vmail/mydomain.com/info/.sieve
    doveadm([email protected])<31431><>: Debug: Added userdb setting: mail=maildir:/var/vmail/mydomain.com/info/Maildir
    doveadm([email protected])<31431><>: Debug: Added userdb setting: plugin/quota_rule=*:storage=4294967296B
    doveadm([email protected])<31431><>: Debug: Added userdb setting: plugin/sieve=/var/vmail/mydomain.com/info/.sieve
    doveadm([email protected]): Debug: Effective uid=5000, gid=5000, home=/var/vmail/mydomain.com/info
    doveadm([email protected]): Debug: Quota root: name=user backend=dict args=:file:/var/vmail/mydomain.com/info/.quotausage
    doveadm([email protected]): Debug: Quota rule: root=user mailbox=* bytes=4294967296 messages=0
    doveadm([email protected]): Debug: Quota grace: root=user bytes=429496729 (10%)
    doveadm([email protected]): Debug: dict quota: [email protected], uri=file:/var/vmail/mydomain.com/info/.quotausage, noenforcing=0
    doveadm([email protected]): Debug: Namespace inbox: type=private, prefix=, sep=., inbox=yes, hidden=no, list=yes, subscriptions=yes location=maildir:/var/vmail/mydomain.com/info/Maildir
    doveadm([email protected]): Debug: maildir++: root=/var/vmail/mydomain.com/info/Maildir, index=, indexpvt=, control=, inbox=/var/vmail/mydomain.com/info/Maildir, alt=
    doveadm([email protected]): Debug: quota: quota_over_flag check: quota_over_script unset - skipping
    doveadm([email protected]): Debug: Mailbox Notes: Mailbox opened because: expunge
    doveadm([email protected]): Debug: Mailbox INBOX.Trash: Mailbox opened because: expunge
    doveadm([email protected]): Debug: Mailbox Sent: Mailbox opened because: expunge
    doveadm([email protected]): Debug: expunge: box=Sent uid=432
    doveadm([email protected]): Debug: expunge: box=Sent uid=433
    doveadm([email protected]): Debug: expunge: box=Sent uid=434
    doveadm([email protected]): Debug: expunge: box=Sent uid=435
    doveadm([email protected]): Debug: expunge: box=Sent uid=436
    doveadm([email protected]): Debug: expunge: box=Sent uid=437
    doveadm([email protected]): Debug: expunge: box=Sent uid=438
    doveadm([email protected]): Debug: expunge: box=Sent uid=439
    doveadm([email protected]): Debug: expunge: box=Sent uid=440
    doveadm([email protected]): Debug: expunge: box=Sent uid=441
    doveadm([email protected]): Debug: expunge: box=Sent uid=442
    doveadm([email protected]): Debug: expunge: box=Sent uid=443
    doveadm([email protected]): Debug: expunge: box=Sent uid=444
    doveadm([email protected]): Debug: expunge: box=Sent uid=445
    doveadm([email protected]): Debug: expunge: box=Sent uid=446
    doveadm([email protected]): Debug: expunge: box=Sent uid=447
    doveadm([email protected]): Debug: expunge: box=Sent uid=448
    doveadm([email protected]): Debug: expunge: box=Sent uid=449
    doveadm([email protected]): Debug: expunge: box=Sent uid=450
    doveadm([email protected]): Debug: expunge: box=Sent uid=451
    doveadm([email protected]): Debug: expunge: box=Sent uid=452
    doveadm([email protected]): Debug: expunge: box=Sent uid=453
    doveadm([email protected]): Debug: expunge: box=Sent uid=454
    doveadm([email protected]): Debug: expunge: box=Sent uid=455
    doveadm([email protected]): Debug: expunge: box=Sent uid=456
    doveadm([email protected]): Debug: expunge: box=Sent uid=457
    doveadm([email protected]): Debug: Mailbox Trash: Mailbox opened because: expunge
    doveadm([email protected]): Debug: Mailbox Drafts: Mailbox opened because: expunge
    doveadm([email protected]): Debug: Mailbox Junk: Mailbox opened because: expunge
    doveadm([email protected]): Debug: Mailbox INBOX: Mailbox opened because: expunge
     
  14. Stelios

    Stelios Member HowtoForge Supporter

    The last command with '*' worked and cleanup the emails/reduce size.

    Thanks a lot
     
    till and ahrasis like this.

Share This Page