APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











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





Yesterday I mentioned testing how well Kerio® Connect's new automatic reindexing responds to deliberate abuse. It turns out that it responds well, so I took advantage of that to create an automatic archiving script.

This is a simple need that I am sure Kerio will add someday. The problem is that some users simply will not ever clean up their INBOX. As it grows larger, the system slows down because it has to search the #msgs directory for free slots. Large directories just bog things down; archiving prevents that.

As written here, this should run once a month. It creates dated subfolders of INBOX and moves older email into these. Here i used the "ctime" to decide age, but you could also open each message and use internal dates.

You can see the result here:

archive folder

The 2011_11_16 folder was by this script created from older messages in INBOX. When it runs next month, it will create another subfolder of INBOX.

As it can take time for the automatic index checking to take place, I have this set to run at 1 minute past midnight on the 1st of the month. By the time I get up in the morning, the reindexing should be long done.

This script is provided without guarantee, warranty or anything else. Use at your own risk and check results carefully. IF YOU DON'T UNDERSTAND THE SCRIPT, YOU PROBABLY SHOULDN'T USE IT!

(Article continues after the break)



This script depends apon the background reindexing features introduced in Kerio Connect 7.3 and will not work on earlier versions. It may not work on later versions because of structural changes to Kerio..

Finally, this was tested on a Linux system. Perl can run on Windows but you would need to change the script.

I use the temporary directory with the rename to avoid the reindexer finding messages before everything is copied into place.. this way, it all appears at once.

#!/usr/bin/perl
$KERIO="/opt/kerio/mailserver/store/mail/aplawrence.com/";
$SAFE="/root/kdir";  # put it wherever you like
@t=localtime(time()-(3600 * 24)); # go back one day

chdir($KERIO);
foreach (<*>) {
  next if /#public$/;
  # add anyone else you want to skip
  $who=$_;
  print "$_\n";
$dir=sprintf("%4d_%0.2d_%0.2d",$t[5]+1900,$t[4]+1,$t[3]);
exit 1 if (-e "$KERIO/$who/INBOX/$dir");
# already exists
if (not -e "$SAFE/$who") {
  mkdir("$SAFE/$who") or exit 1;
}
if (not -e "$SAFE/$who/$dir") {
  mkdir("$SAFE/$who/$dir") or exit 1;
  mkdir("$SAFE/$who/$dir/#msgs") or exit 1;
  mkdir("$SAFE/$who/$dir/#assoc") or exit 1;
}
chdir ("$KERIO/$who/INBOX/");
foreach (<*.fld>) {
  print "$who $_\n";
  system("/bin/cp $_ $SAFE/$who/$dir");
  # for windows   system("copy  $_ $SAFE/$who/$dir");
  # I'm not sure this is needed - I think you just need an empty status.fld
  # doing it this way causes errors about 
  # "two different folders with the same GUID"
  #  Folders work, but those errors are in Error log.
  # 
  # So, this section can probably just be:
  #  open(STATUS,">$SAFE/$who/$dir/status.fld"); close STATUS;
  #
}
chdir("#msgs");
$rightnow=time();
foreach(<*.eml>) {
  @stats=stat $_;
  $howold=($rightnow - $stats[10]) / (3600 * 24); # days old
  next if $howold < 7;
  print "$who $_ $howold\n";
  rename $_,"$SAFE/$who/$dir/#msgs/$_";
}
rename "$SAFE/$who/$dir","$KERIO/$who/INBOX/$dir";
}
 

A more complex script could archive by the correspondent or anything else you might glean from the message content. Your imagination is the only limit.


Kerio®, and related trademarks, names and logos are the property of Kerio Technologies, Inc. and are registered and/or used in the U.S. and other countries. Used under license from Kerio Technologies, Inc.

We offer competitive pricing and complete, no extra charge support on all Kerio products.


If this page was useful to you, please help others find it:  





Comments?




More Articles by - Find me on Google+



Click here to add your comments



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


Kerio Connect Mailserver

Kerio Control Firewall

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.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

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.

pavatar.jpg

This post tagged:

       - Kerio Connect
       - Kerio
       - Kerio Info
       - Kerio Pricing
       - Kerio RSS Feed
       - Mail


















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


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals