#!/usr/bin/perl

use Net::IMAP::Simple;

$server = new Net::IMAP::Simple('localhost');
$server->login('amavis', '*****************');
@folders = $server->mailboxes();
# print @folders;

$mesg_num = $server->select('Other Users/florin/bayes/spam');
print "$mesg_num\n";
#exit;
foreach $msg (1 .. $mesg_num) {
    $lines = $server->get($msg);
    # I am lame and cannot figure out how to
    # feed spam/ham to spammassassin using only Perl
    # so i have to run sa-learn
    $pid = open(WRITEME, "| /usr/bin/sa-learn --spam");
    print WRITEME @$lines;
    close(WRITEME);
    $res = $server->delete($msg);
}
$server->expunge_mailbox('Other Users/florin/bayes/spam');

$mesg_num = $server->select('Other Users/florin/bayes/ham');
foreach $msg (1 .. $mesg_num) {
    $lines = $server->get($msg);
    # I am lame and cannot figure out how to
    # feed spam/ham to spammassassin using only Perl
    # so i have to run sa-learn
    $pid = open(WRITEME, "| /usr/bin/sa-learn --ham");
    print WRITEME @$lines;
    close(WRITEME);
    $res = $server->delete($msg);
}
$server->expunge_mailbox('Other Users/florin/bayes/ham');
