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


Hate these ads?

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.



Comments /Kerio/clean_folders.html


Wed Jun 18 19:14:32 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


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


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.

Add your comments

Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner


ad

Views for this page
Today This Week This Month This Year  Overall
9302071,328 4,524

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

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




Unix/Linux Consultants

Your ad here - $24.00 yearly!

http://www.m3ipinc.com Security, firewalls, ids, audits, vulnerability assesments, BS7799, HIPAA, GLB, incident handling


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


UBB Computer Services Support for Openserver, Unixware and Linux. Windows integration with Unix/Linux servers. Hardware, Backup and Networking issues. Located near Sacramento CA, we provide onsite support throughout Northern CA and Nationwide via remote access. We are a SCO Authorized Partner and a Microlite BackupEdge Certified Reseller.









Change Congress

Related Posts