Sure, I came up with the script below since the last post. It was written very quickly, with majority of the time spent by me sitting and waiting for my users' mail stores to be backed up by omcpoutu.
Four points to note:
1. I assume absolutely no responsibility if this bombs for you. It worked for me. Please backup all the mail stores for everyone affected. It might take you a long time to do this, but it is completely necessarry. Read up on "omcpoutu" if you don't know how to use it. When you omcpoutu a user, that user must NOT be logged onto the system.
2. I do not update the sxaa rules. Delete them by hand (frankly, it's 5:30pm and I am too tired to sift through docs for sxaa).
3. The code will appear to halt for a bit after you start it. This is intentional, so that you can hit ctrl+c and exit the script if you didn't heed warning no. 1. If you have backed up users' mailboxes, then touch nothing -- the script will start after roughly 5 seconds.
4. Update values for host, password, etc.
Code: Select all
#!/usr/bin/perl
#
# Deletes a "spam" folder in the user's inbox and sets a
# filterset redirecting all messages marked "[SPAM]" there.
#
# make sure to copy the 'sxaa' file from the scalix
# admin_resource_kit to /usr/bin
#
# usage: deleteFolder.pl [user_name | all]
#
use strict;
use warnings;
use Mail::IMAPClient;
print "WARNING! MAKE SURE THAT YOUR USERS' MAILBOXES ARE BACKED UP WITH omcpoutu COMMAND!\n";
print "You have 5 seconds to press CTRL+C and abort this program if above is not done!\n";
sleep (5);
my $host="192.168.x.y";
my $username="Mbox.AdminUserThatYouShouldHave\@yourhost.com";
my $password="theDudesPassword";
my $deleteFolder="/Inbox/spam";
my $wrongInbox = "/Inbox";
my $checkUser=$ARGV[0];
my @all_users=`/opt/scalix/bin/omshowu -m all -i`;
foreach my $punter (@all_users){
if ($punter eq $checkUser || $checkUser eq "all"){
chomp $punter;
my $user="mboxadmin:$username:$punter";
my $imap = new Mail::IMAPClient( 'Server' => $host , 'User' => $user , 'Password' => $password ) or die "ERROR ($@)\n";
print "+++ Processing user: ".$punter."\n";
print "+++ DELETING $deleteFolder +++\n";
$imap->delete($deleteFolder) or die "DELETE FAILED for $deleteFolder: ($@)\n";
print "+++ DELETING $wrongInbox +++\n";
$imap->delete($wrongInbox) or die "DELETE FAILED for $wrongInbox: ($@)\n";
my @fArray = $imap->folders;
print "Total folders for $punter: " . scalar @fArray . "\n";
print "I will now list all the folders found for $punter: \n";
for (my $i = 0; $i < @fArray ; $i++)
{
print "Folder...\t$fArray[$i]\n";
}
}
}
In the end, when the code prints out the folders left after all deletions, you should see that, for any given user, these look like what they see in webclient or thunderbird. I did immediately log onto webclient and, to my dismay, I saw two inboxes (!). However, I am expecting the "wrong one" to disappear after a while (I don't know how to "flush" or refresh the view). Rest assured, it IS deleted, because $imap->folder looks at the bare bone level... at least I hope.