I am sysadmin of a small mail server with around 15 users, about half of
which maintain IMAP mailboxes (vice pop). I am running Red Hat 8 distro,
with the IMAP (which is believe is UW IMAP) right out of the box. My
users are uneducated/uninterested in expunging their email instead of
just deleting it, and a lot of server space is taken up with deleted
email that is never expunged.  Quotas are not a good option because my
users receive rather large attachments.  Also, they are not computer
literate enough to grasp the concept and need of delete vs.
delete/expunge, despite my best efforts at education.  Regrettably, many
of them use Outlook, which does not offer an expunge on exit option.
I would like to execute a script as a cron task to find all IMAP mail
boxes and expunge deleted mail.  I have written the two scripts below.
The first is a script to generate the list of mailboxes and then call
the second. The second is a perl script that actually expunges the
boxes.  This solution does not work because I cannot log into the IMAP
server as root, and I can't extract each user's password to log on as
each user.
Is there a method for automatically expunging deleted mail from an IMAP
server?
Thanks.
Travis Beal

========================================
SCRIPT 1:
#!/bin/bash
#broadcast stop
echo 'Starting purge of folders.'
date

#stop internet services
/etc/init.d/httpd stop
/etc/init.d/sendmail stop
/etc/init.d/xinetd stop

#generate list of IMAP mailboxes
ls /home/*/.mailboxlist > /root/listofmailboxlists

#Perl purge script
/root/purge_folders_perl

#start services
/etc/init.d/xinetd start
/etc/init.d/sendmail start
/etc/init.d/httpd start

#remove the list
rm -rf /root/listofmailboxlists

#broadcast
echo 'Purge of folders complete.'
date


========================================
SCRIPT 2:
#!/usr/bin/perl

#get the IMAP tools
use Mail::IMAPClient;
print "Entering Perl section.....\n";

#read only open this list of mailbox lists
open (LISTOFMAILBOXLISTS, "<listofmailboxlists");

#go through file
#while(<LISTOFMAILBOXLISTS> ){
#load next line in file
chop;
#parse out next data file
($mailboxlisttoscan) = split (/\n/, $_);
#debug print "Next is $mailboxlisttoscan.\n";
#get absolute address prefix
($file_prefix,$junk) = split (/\/.mailbox/,$mailboxlisttoscan);
#parse out user_name
($trash, $user_name) = split (/ome\//,$file_prefix);

# (returns a new, authenticated Mail::IMAPClient object)
$host = "127.0.0.1";
$id = "$user_name";
$pass = "?????????";
$imap = Mail::IMAPClient->new( 
Server => $host,
User => $id,
Password=> $pass,
) or die "Cannot connect to $host as $id: $@";

#read only open this mailbox list
open (MAILBOXLIST, "<$mailboxlisttoscan");
#go through this list
while(<MAILBOXLIST> ){
#load next line in file
chop;
#parse out based on CSV
($mailboxtopurge) = split (/\n/, $_);
#debug print "Purging $mailboxtopurge for user $user_name.\n";
$imap->expunge($file_prefix/$mailboxtopurge) or die "Could not expunge:
[EMAIL PROTECTED]";
} #end of mailboxlists while
close (MAILBOXLIST);
} #end of listofmailboxlists while
close (LISTOFMAILBOXLISTS); 

print "Exiting Perl section.\n";

-- 
------------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/imap/c-client-list.html
------------------------------------------------------------------

Reply via email to