Clean up several mailboxes but keep directories untouch

Discussion in 'Installation/Configuration' started by W-C, Jun 8, 2017.

  1. W-C

    W-C New Member

    Hello,

    I need to clean up several mailbox accounts from the server, Is there anyway to delete the mails from a specific user mailbox via command line?. If so, could you please provide me the steps to properly delete the mails without affect the directories created by postfix?.

    Linux Distro: Centos 6.3
    ISPConfig Version: 3.0.4.1

    Thanks in advance...
     
    Last edited: Jun 8, 2017
  2. Jesse Norell

    Jesse Norell Well-Known Member

    You don't say if you're using courier or dovecot, but if dovecot you would use the doveadm command. You use 'expunge' to delete mail, and 'doveadm expunge' requires a mailbox name, so you must loop through them, eg.
    Code:
    doveadm mailbox list -u [email protected] | while read mbox; do echo doveadm expunge -u [email protected] "${mbox}" all; done
     
    W-C likes this.
  3. W-C

    W-C New Member

    Hello Jesse,
    We are using courier-imap, sorry my bad I forgot this big detail.

    Thanks
     
  4. Jesse Norell

    Jesse Norell Well-Known Member

    Dunno for courier offhand, I suspect just rm the files (and recalculate or clean up maildirsize file if you care about quotas). I'm sure google searches will find some info if noone else replies here.
     
    W-C likes this.
  5. W-C

    W-C New Member

    I been searching for this in google for some time but without luck, anyway thanks for all your help.
     

Share This Page