[Dovecot] Forcibly emptying a POP3 mailbox

Steffen Kaiser skdovecot at smail.inf.fh-brs.de
Thu Feb 4 11:25:47 EET 2010

Hash: SHA1

On Wed, 3 Feb 2010, Răzvan Sandu wrote:

> - IMAP is allowed only locally, in order to be used together via stock
> squirrelmail Web interface (for emergencies only)
> However, there are users that check the infamous „Leave a copy on the server” 
> checkbox (or equivalent) in their mail clients, eventually adding „Delete 
> messages after X days”.
> Since I have no direct administrative control on the clients, I
> absolutely need a way to forbid the above behaviour at server level, in order 
> to enforce the policy. The server's HDD is meant to store received messages 
> from reception to the first access only.
> Filesystem quotas are not an option in this scenario, since the UID/GID is 
> the same for all virtual users.
> What I need is way to make sure that "cur" and "tmp" subdirectories are 
> perfectly empty after the user downloads his mail.

"tmp" is temp, hence, I do:

find /path -maxdepth 4 -name tmp -type d -print0 | \
   xargs -r0  /usr/local/sbin/emptyDir

==== emptyDir

find "$@" -type f -mtime +2 -delete


once a day anyway.

> (I will also need a way to make sure that users using squirrelmail leave no 
> populated "Sent" and "Trash" folders on server's HDD, but that's offtopic 
> here).

Well, find /path -maxdepth 3 \( -name .Sent -o -name .Trash \) -print0 | \
  xargs -r0 /usr/local/sbin/emptyDir


# delete any Maildir mailboxes except INBOX
for user in /path/*/Maildir; do
   # Maildir mailboxes start with a dot
   find "$user"/.[^.]* -type f -mtime +2 -delete
   rmdir -p "$user"/.[^.]*/* > /dev/null 2>&1

> Could you please suggest a way to solve this ?

The problem IMHO is: that you allow IMAP access for emergency, but then 
want to delete cur/.

How about these:

1) Once a day you traverse the logs and check when an user has logged in 
with POP and IMAP, if login(POP) > login(IMAP), empty cur/ .

2) You do postlogin scripting:
for IMAP only. The script sets a flag to _not_ purge cur/ of the 
particular user once a day.

I would use "-mtime +1" to give each user one day to re-download the mail 
in case, well, of a problem.


- -- 
Steffen Kaiser
Version: GnuPG v1.4.6 (GNU/Linux)


More information about the dovecot mailing list