Saturday, October 08, 2005

Delete trash from Courier IMAP Maildir

Outlook doesn't move deleted mails to the IMAP server's Trash folder, and apparently cannot be told to do so. It doesn't move them to it's own local trash folder either. Depending on configuration, it either:
  • deletes them straight away
  • shows them greyed out and overlined
  • marks them as deleted, and hides them
Most users prefer the latter option (not that it is good, but it's a lesser evil).

This means the Maildir on the server is filled up with mails marked for deletion, which users cannot (easily) delete since they don't even see them.

Convincing the users that Outlook is a bad email client is hopeless, so we need another way to get rid of these old files.

Fortunately, on my Courier IMAP server, files marked for deletion are easily recognized by the "T" at the end of the file name. (See "Reading mail from maildirs" in the Courier documentation).

So what I do is delete files which have been marked for deletion for some time (30 days in the example below). When it is marked, the file's ctime changes.

Adapt to your needs:

find /home/*/Maildir/ -ctime +30 -type f -name "*T" -exec rm -f "{}" \;


Anonymous Anonymous said...

rming deleted files tends to cause problems with certain kinds of users. Unfortunately, those users are the kind that write the checks. So I'm intending to write a utility that will move messages marked with a T into a .Trash folder and remove the T. I'll let you know how it goes.

30 November, 2005 23:16  
Anonymous Anonymous said...

Not sure if you ever got it done but here's my dirty script to move to trash file:

while true
find /home/e-smith/files/users/*/Maildir/ -type f -name "*T*" -exec echo {} >> /tmp/deleted.imap \;
exec 3<&0
exec 0</tmp/deleted.imap
while read line
filename=${line##*/}; newfilename=${filename//T/}
mv "$line" "$moveto"
exec 0<&3
if [ $i -gt 0 ]
echo "$i messages moved from $filepath"
rm -f /tmp/deleted.imap

I run it in a screen so I can reconnect and check they're still moving...

03 August, 2010 15:31  

Post a Comment

<< Home