[Dovecot] Forcibly emptying a POP3 mailbox

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


-----BEGIN PGP SIGNED MESSAGE-----
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

Maybe:

# 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
done

> 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:
http://wiki.dovecot.org/PostLoginScripting
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.

Regards,

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

iQEVAwUBS2qSnb+Vh58GPL/cAQKZSgf+Ohy80TcJhGppStH5DLScZ86MVbgNYKhJ
Bgtvy3tU7wZGa4ZJJKNwEIlHKayJV7zgIhQehvSJmg53827BSgJ9kF6f+iBMCOZ6
Ye6UG5549sMicpTezs0MtYnv+xc8qWJs4mhAyjUblfHtiBvQYOxDqcX5uKvHpcqC
Bp9GVYpo0TZCPw3qoixfN2aFL6xBDofxBk45uohWe4xWwwQZMwJt0AWbxNdpHtFV
hVKlafgJqmvaOzdHq18zUjrdinBuvx60RSV9+XIReSf/Ig2dMK8KoGxi+nzLAg77
HW78XIdzRxmp9sAjedGIw46IlvCp+wq6qcm0jI7wk60ccb1m1fd3Vw==
=7FlQ
-----END PGP SIGNATURE-----


More information about the dovecot mailing list