MailCleaner + Exchange + IMAP Bayes Training

Users tips and ideas

Moderators: FlorianB, Pascal, bourgeois, mentor

somitec
Posts: 14
Joined: Fri May 18, 2007 1:10 pm

Error on the imap script

Postby somitec » Fri May 18, 2007 1:17 pm

Hello everybody,

i tried to install the imap script and got this error message:
Looking in spam folder Public Folders/SPAM
Can't call method "select" on an undefined value at ./imap-sa-learn.pl line 110.
mailcleaner:~#

I check the script, but can't find he mistake.
Maybe you can help me with that. Thak u very much!

Greetings

Michael

Here ist my configruation:

#!/usr/bin/perl

# Imap Interface to SpamAssassin Learn v0.03
# ------------------------------------ -----
#
# Connects to an imap server, and filters the messages from the INBOX
# and SpamTrap (unless otherwise told) through sa-learn
#
# usage:
# imap-sa-learn.pl <-hamfolder HAM> <-spamfolder SPAM>
#
# Other options:
# -skips nnn skips over the first nnn messages in the folder(s)
# -deletespam after learning from a spam message, delete it
# -delete-spam (as above)
# -dangerous-delete-ham after learning from a ham (real email),
# delete it. Most people don't want this...
# -dangerous-delete-all after learning from any message, delete
# it, spam or ham
#
# Uses Mail::IMAPClient and SpamAssassin (sa-learn)
#
# Needs a version of SpamAssassin with the Bayesian filtering support,
# i.e. 2.50 or later
#
# Nick Burch <nick@tirian.magd.ox.ac.uk>
# 25/06/2003
#
use Mail::IMAPClient;

# Define our server and credentials here
# * Really ought to able to have several accounts defined
#
# ** fix me ** your details go below
my $username = 'mailcleaner';
my $password = '12345678';
my $server = '172.17.32.10';

# Define where to find messages
my $defspamfolder = 'Public Folders/SPAM';
my $defhamfolder = 'Public Folders/HAM';
my $deletespam = 1;
my $deleteham = 1;
my $default = 1;

my $skips = 0;

my @spams;
my @hams;

while(my $arg = shift) {
if($arg eq "-spamfolder") {
my $spam = shift;
push @spams,$spam;
print "Using spam folder $spam\n";
$default = 0;
}
if($arg eq "-hamfolder") {
my $ham = shift;
push @hams,$ham;
print "Using normal (ham) folder $ham\n";
$default = 0;
}
if($arg eq "-deletespam" || $arg eq "-deletespams" || $arg eq "-delete-spam" || $arg eq "-delete-spams") {
$deletespam = 1;
}
if($arg eq "-dangerous-delete-ham" || $arg eq "-dangerous-delete-hams") {
$deleteham = 1;
}
if($arg eq "-dangerous-delete-all") {
$deletespam = 1;
$deleteham = 1;
}
if($arg eq "-skips" || $arg eq "-skip") {
$skips = shift;
}
if($arg eq "-?" || $arg eq "-h") {
print "Usage:\n";
print " imap-sa-learn.pl [-spamfolder f]* [-hamfolder f]*\n\n";
print "with no argumnets, uses default folders\n";
print "(a few other options exist, see the header of the program)\n";
exit;
}
}

if($default) {
push @hams,$defhamfolder;
push @spams,$defspamfolder;
}

my %folders;
$folders{'spam'} = \@spams;
$folders{'ham'} = \@hams;


# Normal (1), Debugging (2), or silent(0)?
my $debug = 1;

# Connect to the IMAP server in peek (i.e. don't set read flag) mode
my $imap = Mail::IMAPClient->new(Server => $server,
User => $username,
Password => $password,
Peek => 1);
foreach my $type(keys %folders) {
foreach my $folder (@{$folders{$type}}) {
print "\nLooking in $type folder $folder\n";

# Pick the folder
$imap->select($folder);

# Enable peek mode
$imap->Peek(1);

# Fetch messages
my @mails = ($imap->seen(),$imap->unseen);

my $count = 0;

foreach my $id (@mails) {
$count++;
if($count < $skips) { next; }

print " Learning on $type message $id\n";
my $mail = $imap->message_string($id);
open SA, "| sa-learn -p /usr/mailcleaner/etc/mailscanner/spam.assassin.prefs.conf --siteconfigpath /usr/mailcleaner/share/spamassassin --no-sync --$
type --single";
print SA $mail;
close SA;

if($type eq "spam" && $deletespam) {
# If you want to move the message rather than deleting it,
# uncomment the line below, change the folder, but _don't_
# remove the delete line!
#$imap->append('TrashBin', $mail );

print "Deleting Spam Message $id\n";
$imap->delete_message($id);
}
if($type eq "ham" && $deleteham) {
print "Deleting Ham (normal email) Message $id\n";
$imap->delete_message($id);
}
}
if($deleteham || $deletespam) {
# Only expunge now, rather than on every message
$imap->expunge();
}
}
}

print "\nNow rebuilding the Bayesian filters\n";
`sa-learn -p /usr/mailcleaner/etc/mailscanner/spam.assassin.prefs.conf --siteconfigpath /usr/mailcleaner/share/spamassassin --sync`;

$imap->close;
exit;
User avatar
suhasingale
Posts: 298
Joined: Mon Nov 13, 2006 2:30 pm
Location: India
Contact:

Postby suhasingale » Sat May 19, 2007 5:06 am

Code: Select all

my $defspamfolder = 'Public Folders/SPAM';
my $defhamfolder = 'Public Folders/HAM';


I doubt the space between 'Public' & 'Folder' is creating problem here.
Promise only what you can deliver...
somitec
Posts: 14
Joined: Fri May 18, 2007 1:10 pm

Did not solve the problem

Postby somitec » Sun May 20, 2007 2:13 pm

Hello and thank u for the fast answer!

Unfortunely your Tip dos not solve the Problem.
The error occurs on lin 110
109 # Pick the folder
110 $imap->select($folder);

Any idea about it?

Thanks a lot

Greetings

Micha
the_fbi
Posts: 49
Joined: Sat Dec 09, 2006 11:28 am
Location: Oxfordshire, UK

Postby the_fbi » Sun May 20, 2007 3:38 pm

Blank space after $folder before (@ in the middle line?

foreach my $type(keys %folders) {
foreach my $folder (@{$folders{$type}}) {
print "\nLooking in $type folder $folder\n";
somitec
Posts: 14
Joined: Fri May 18, 2007 1:10 pm

blank dosn't fix

Postby somitec » Mon May 21, 2007 8:16 am

Hello again,

i checked the blanks, everything seemed to be ok.
Now i try the whole procedure on an other machine wich is running mailcleaner. The same error occours.
Can sombody please post his skript, so i can copy and paste them.
Is it possible that i make a mistake with the installation of the imap clinet? (No error was printed by the installation.)

Thanks a lot, hope someone can help me trough.

Bye

micha
somitec
Posts: 14
Joined: Fri May 18, 2007 1:10 pm

One Step further.

Postby somitec » Mon May 21, 2007 2:36 pm

Hello!

the skript runs now. I donwload the original skript from http://www.gagravarr.org/code/ as in a fomer reply was wrote and
edit the sa-learning part.
Now the script runs without an error but did not delete anything.
I gave the User mailcleaner full permissions on this 2 public folders.
In the Spam Folder are about 33 Mails in the HAM 1.

I am unsure if the skript ist really learning now?
Is there anything more configuration on the exchange server to do?

Thank u..

Micha

Code: Select all

Looking in spam folder Public Folders/SPAM
 Learning on spam message
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting Spam Message
 Learning on spam message
Learned tokens from 1 message(s) (1 message(s) examined)
Deleting Spam Message

Looking in ham folder Public Folders/HAM
 Learning on ham message
Learned tokens from 0 message(s) (1 message(s) examined)
Deleting Ham (normal email) Message
 Learning on ham message
Learned tokens from 0 message(s) (1 message(s) examined)
Deleting Ham (normal email) Message
Now rebuilding the Baysean filters

msweany
Posts: 52
Joined: Thu Nov 30, 2006 3:21 pm

Postby msweany » Tue May 29, 2007 9:11 pm

AWESOME Script! Thanks for the detailed info, I just did this and it works like a champ...
msweany
Posts: 52
Joined: Thu Nov 30, 2006 3:21 pm

Re: Error on the imap script

Postby msweany » Mon Jul 16, 2007 8:57 pm

somitec wrote:Hello everybody,

i tried to install the imap script and got this error message:
Looking in spam folder Public Folders/SPAM
Can't call method "select" on an undefined value at ./imap-sa-learn.pl line 110.
mailcleaner:~#



I have implemented this on 3 different mailcleaner systems sucesfully. Recently, one started having the above error?

Any idea on how I can fix that?

I didnt change anything on the MC end, we just implemented it and had users start dumping mail in it..

Any ideas?
swemic
Posts: 60
Joined: Tue May 29, 2007 1:58 pm
Location: Sweden
Contact:

Re: Error on the imap script

Postby swemic » Tue Jul 17, 2007 4:16 pm

msweany wrote:
somitec wrote:Hello everybody,

i tried to install the imap script and got this error message:
Looking in spam folder Public Folders/SPAM
Can't call method "select" on an undefined value at ./imap-sa-learn.pl line 110.
mailcleaner:~#



I have implemented this on 3 different mailcleaner systems sucesfully. Recently, one started having the above error?

Any idea on how I can fix that?

I didnt change anything on the MC end, we just implemented it and had users start dumping mail in it..

Any ideas?


Have you double checked the user/password and exchange server IP defined at line 35-37?

I.e.
my $username = 'your-imap-user';
my $password = 'your-imap-password';
my $server = 'your-ip-to-exchange-server';

Because it really sounds like your user don't have access to the Pubic Folder.

If that is OK, try: telnet your-exchange-ip 143
and see if you get in contact with the Exchange server, if not, check your firewall or routing.
msweany
Posts: 52
Joined: Thu Nov 30, 2006 3:21 pm

Re: Error on the imap script

Postby msweany » Tue Jul 17, 2007 6:40 pm

swemic wrote:
msweany wrote:
somitec wrote:Hello everybody,

i tried to install the imap script and got this error message:
Looking in spam folder Public Folders/SPAM
Can't call method "select" on an undefined value at ./imap-sa-learn.pl line 110.
mailcleaner:~#



I have implemented this on 3 different mailcleaner systems sucesfully. Recently, one started having the above error?

Any idea on how I can fix that?

I didnt change anything on the MC end, we just implemented it and had users start dumping mail in it..

Any ideas?


Have you double checked the user/password and exchange server IP defined at line 35-37?

I.e.
my $username = 'your-imap-user';
my $password = 'your-imap-password';
my $server = 'your-ip-to-exchange-server';

Because it really sounds like your user don't have access to the Pubic Folder.

If that is OK, try: telnet your-exchange-ip 143
and see if you get in contact with the Exchange server, if not, check your firewall or routing.


Thank you..

Yeah, I was having a hard time with this, the bolded part helped me resolve this.

I didnt think to try that before since it worked at one point, but It looks like the IMAP virtual server needs to be started manually upon reboot.
swemic
Posts: 60
Joined: Tue May 29, 2007 1:58 pm
Location: Sweden
Contact:

Re: Error on the imap script

Postby swemic » Mon Aug 06, 2007 12:31 pm

msweany wrote:but It looks like the IMAP virtual server needs to be started manually upon reboot.

Yes, I did notice that on our Exchange server as well, I don't know if it is a (miss) configure issue from Micro$oft. I did though change the settings for the virtual IMAP server on the Exchange, from using "All unassigned" IP interface to a static IP interface. I have not tried to restart the server after that. (And I have of course set the service to Automatic in the services as well)
User avatar
jordant
Posts: 218
Joined: Sat Sep 16, 2006 2:48 pm
Location: Perth, Western Australia

Postby jordant » Mon Sep 10, 2007 5:32 am

Updated URL for downloads. check original post for new link.
msweany
Posts: 52
Joined: Thu Nov 30, 2006 3:21 pm

Postby msweany » Wed Oct 03, 2007 3:48 pm

jordant wrote:Updated URL for downloads. check original post for new link.


Hey Jordant,

I havent been reading the boards much as I had been waiting for the pre-release to become official. But I need to get MC updated and this is one script I was using.

Is this updated to work with the newest pre-release?

Or wont it matter because of the new bayes filter?

Thanks,

Mike
User avatar
jordant
Posts: 218
Joined: Sat Sep 16, 2006 2:48 pm
Location: Perth, Western Australia

Postby jordant » Thu Oct 04, 2007 9:44 am

I havn't actually used any patches higher than the ones this patch was made for however i plan to migrate the patches to the latest version in the next 2 months. sorry for the long ETA but im working on my employers spare time.

Il keep the forum posted to any updates i make.
lesliem
Posts: 9
Joined: Thu Sep 20, 2007 7:23 am
Location: Cape Town
Contact:

Postby lesliem » Tue Oct 16, 2007 3:52 pm

Hi,
I have changed your connection method to the imap server as follows:
From:
# Connect to the IMAP server in peek (i.e. don't set read flag) mode
my $imap = Mail::IMAPClient->new(Server => $server,
User => $username,
Password => $password,
Peek => 1);

To:
# Connect to the IMAP server in peek (i.e. don't set read flag) mode
my $imap = Mail::IMAPClient->new(Server => $server,
User => $username,
Password => $password,
Peek => 1) or die "Cannot connect to $server as $username: $@";

This gives some feedback to diagnose connectivity problems to the imap server. Hope this helps!
Leslie Maclachlan
http://www.owdsa.com

Return to “Tips”

Who is online

Users browsing this forum: No registered users and 1 guest