Spamassin server-side rule to filter spam

Discuss the Scalix Server software

Moderators: ScalixSupport, admin

btisdall
Scalix Star
Scalix Star
Posts: 373
Joined: Tue Nov 22, 2005 12:13 pm
Contact:

Postby btisdall » Wed Sep 20, 2006 12:15 am

You're absolutely right! The posting in question actually describes the procmail filtering I set up on a postfix box, information which I omitted because I didn't believe it to be relevant. Since then I learned that Scalix, unlike procmail, doesn't stop processing a message once a rule has been matched, causing the effect you mentioned.

Thanks for pointing that out.
Ben Tisdall
www.redcircleit.com
London

ianare
Posts: 61
Joined: Tue Sep 19, 2006 1:13 pm

Postby ianare » Fri Oct 06, 2006 6:07 pm

if anyone is interested I made a small script to make adding rules a bit easier:

Code: Select all

#!/usr/bin/perl
#
# Creates 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: create_spam_filter.pl [user_name | all]
#
use strict;
use warnings;
use Mail::IMAPClient;

my $host="hostname";
my $username="mboxadmin";
my $password="password";
my $createFolder="/Inbox/spam";

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 next;
       print "Found user: ".$punter."\n";
       $imap->create($createFolder) or die "Could not create spam folder\n";
       system('/usr/bin/sxaa --user '.$punter.' --file "$createFolder" --subject "[SPAM]" --title "spam filter"');
   }

}


Came in handy during initial install, and now if extra users need to be added to the system.

sk8conz
Posts: 26
Joined: Fri Dec 01, 2006 6:19 am

Postby sk8conz » Sun Dec 10, 2006 8:42 pm

Can anyone help out with this script ??

I'm a linux noob, but have the script running.

It seems to work, in that it creates the SPAM folder, but doesn't create the rule.

If I login to webmail I can see the created folder but if I do an sxaa --user user there are no rules set.

Being a noob, can someone please :-

a) Tell me what folder the create_spam_filter.pl should be in

b) What folder should I run it from ?

c) The correct command. I am using Perl creat_spam_filter.pl username

I am running FC5

Thanks

milanm
Posts: 10
Joined: Tue Aug 22, 2006 9:14 am

Postby milanm » Thu Jan 04, 2007 5:21 pm

Hello,

The reason that the rules are not created is because the script assumes that sxaa lives in a directory called /usr/bin. You can see it from this liine in the script:

system('/usr/bin/sxaa --user '.$punter.' --file "$createFolder" --subject "[SPAM]" --title "spam filter"');


There are two ways to handle this, and they both require you to locate where sxaa lives on your system. Typically, it should be found in this directory:

/usr/local/src/scalix-core-intel-redhat-10.0.1/admin_resource_kit/

(this is assuming you're running the scalix version that I am running). If you cannot find it, then you can use the unix command called "locate". It goes through the database of all files on linux and tells you where a file is. issue the following two commands on linux prompt:

updatedb (now go have a coffee, because this will take 2 minutes. It builds the database with location of every single file on your system)

locate sxaa (this will tell you where sxaa is).


If "locate sxaa" returns with nothing found, then please download the admin_resource_kit from scalix website. It will contain sxaa utility and you can put it anywhere you want.

Now that you know where sxaa lives, you can:

1. modify the original script so that the offending line reads :

system('/usr/local/src/scalix-core-intel-redhat-10.0.1/admin_resource_kit/sxaa --user '.$punter.' --file "$createFolder" --subject "[SPAM]" --title "spam filter"');


2. or if the modifying script is something you don't want to do, you can actually make a link to sxaa so that it is found from /usr/bin/ directory by typing this on linux prompt:

ln -s /usr/local/src/scalix-core-intel-redhat-10.0.1/admin_resource_kit/sxaa /usr/bin

Now when you type "ls -l /usr/bin/sxaa" you will see that it points to the original location and the script will now work.


Now, for my questions:

The script seems buggy. If you hack around and print out the array that $imap->folders() returns, you will see that the inbox folder is not called "Inbox" but "INBOX". This caused me a lot of grief. The original script assumed that the folder should be called "/Inbox/spam" and not "/INBOX/spam" so now I have two inboxes (!)

I also can't select "Spam" folder, because of some imap problems. When I click on spam folder thunderbird, I get:

"cannot SELECT mailbox" error.

I don't know why this happens. I can't delete it, rename it, do anything with it. It is as if this user does not even own the bloody folder.

My planned solution: write a script that connects through imap and calls on remove/delete what have you. I have to read up on cpan.org on this module first.

sk8conz
Posts: 26
Joined: Fri Dec 01, 2006 6:19 am

Postby sk8conz » Thu Jan 04, 2007 5:26 pm

Thanks for the reply and detailed howto.

I did manage to work it out and get the script running, but wouldn't you know it !!!! I now have the same problems you do, namely two in boxes and folders that can't be deleted, renamed or moved.

I have spent quite a bit of time playing with the different om- CLI commands but so far nothing budges these stubborn mailboxes.

I would certainly be very keen to see if you come up with a solution to remove them

milanm
Posts: 10
Joined: Tue Aug 22, 2006 9:14 am

Postby milanm » Thu Jan 04, 2007 6:35 pm

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.


Return to “Scalix Server”



Who is online

Users browsing this forum: Bing [Bot] and 6 guests