(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



Automatically cleaning Kerio Mail Folders


2006/11/16

Some users just won't clean up their mail folders. They may delete stuff from their Inbox, but they'll never touch their Junk Mail folders or the deleted items. You can set quotas, but that's annoying, and if the offending party is a boss, you mind find yourself facing salary quotas or worse.

If you are running Kerio on a Linux or Mac OS X server, there is a solution: a shell script run with cron (or Launchd for Mac OS X) can automatically clean up whatever you like. Here's the basic script:


#!/bin/bash
user=$1
dir=$2
test "$dir" || exit 1
cd "/opt/kerio/mailserver/store/mail/aplawrence.org/$user/$dir/#msgs" || exit 0
find . -mtime +1 -exec rm -f {} \;
cd "/opt/kerio/mailserver/store/mail/aplawrence.org/$user/$dir/" || exit 0
/bin/mv index.fld index.bad

You'd call that with the users and directories you want to clean. For example:

#!/bin/bash
/etc/init.d/keriomailserver stop
cleankerio tony "Junk Mail"
cleankerio tony "Deleted"
cleankerio same "Deleted"
/etc/init.d/keriomailserver start

You need to adjust this script to reflect the proper directory for your system: Mac is different than Linux and both allow you to put the "store" directory wherever you like. You'd run this with a cron job, probably after working hours to avoid complaints from users.

A couple of things: stopping the mail server in the calling script is absolutely necessary, as is renaming the "index.fld" files in the working script. The "cd .. || exit 0" is important to guard against accidentally removing the wrong files. You can adjust the -mtime argument to "find" if you want to leave files in the directories longer.

By the way, this same technique can be used to add messages to a user's mailboxes without going through the smtp process. You do have to be concerned about overwriting existing emails, but basically you just stop the server, copy the messages in, rename the "index.fld" file, and restart the server.




Click here to add your comments





Wed Jun 18 19:14:31 2008: Subject:   mvgfr
http://mvgfr-geek.blogspot.com/

Cool script; thanks.

Are you certain stopping the server is necessary?

The docs seem to indicate that in some cases it's not - for instance, if you can ensure the user is not logged on, you can use the "index.bad" method of resetting that user's indices.

- Marc



Wed Jun 18 19:19:54 2008: Subject:   TonyLawrence

gravatar
Right.. but since we can't know when someone will try to connect, it's safer to just stop - unless you are just fixing one user and you are certain they are out.



Wed Jun 18 23:39:17 2008: Subject:   mvgfr
http://mvgfr-geek.blogspot.com/

OK; so I'm not crazy. :)

So, and I ask this in all seriousness, how do you stop the server - politically? Isn't email a critical enough service that virtually any outage, any time of day, is undesirable? Doesn't stopping the server that way have the potential to leave some user high and dry, with an unsaved change?

As to making sure a user is not connected, can't this be easily accomplished by: a) checking to see that they're really not connected via Kerio admin (not sure if there's a way via the command line), and b) for extra safety if desired, temporarily disabling the account, perhaps by something interesting like switching the password "pointer" in OD?

- Marc



Wed Jun 18 23:49:51 2008: Subject:   TonyLawrence

gravatar
Well, users can retry, but we run this at a time of day when it's unlikely for anyone to be on.

If users would clean up their own junk, we wouldn't need things like this.

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - Kerio
       - Kerio Info
       - Kerio Pricing
       - Mail


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress