>> 
>> Hi,
>> 
>> > Do you just want to re-scan the whole mbox and see what rules hit now
>> > for research reasons?
>> 
>> That's a good start, but I'd like to see if I can break out the ham to
>> train bayes.
>> 
> 
>> Yeah, that's kind of what I thought. Maybe a program that can split
>> each message back into an individual file? Would procmail even help
>> here? Or even a simple shell script that looks for '^From ', redirects
>> it to a file, runs spamassassin -d on it, then re-runs SA on each
>> file? I could then concatenate each of them back together and pass it
>> through sa-learn.
>> 
Hi Alex,

I recall using a perl script when I migrated from mbox mail files to a local 
imap server.
It would just split the mbox into messages and do an imap append for every one.
Should be the same process when you want to feed into spamc instead.
I am attaching that file for reference

Wolfgang

>> Thanks,
>> Alex

################
#!/usr/bin/perl -w
#
# mbox2imap - convert user mbox files to IMAP mailboxes
# Written by Steve "Pheran" Snodgrass <ssnod...@fore.com>
# This script is public domain; you may do whatever you want with it!
# You must have the NetxAP module from CPAN to run this script.
# Please note that there is a bug in NetxAP 0.01 that causes setquota to
# fail.
# To fix it, change IMAP.pm line 458 to read 'setquota' instead of getquota'
#
# This script accepts a list of mbox file names as parameters.  These names
# are also assumed to correspond to user names.  It will prompt for a
# username
# and password on the IMAP server.  The account you login as will need to
# have admin privileges.  Each mbox file is copied into a folder called
# user.filename, where filename is the name of the mbox file being copied.
#
# Example (assumes no junk files lying around in /var/mail):
# $ cd /var/mail
# $ mbox2cyrus *

    use File::Basename;
    use Net::IMAP;

    # Set this to the hostname of your IMAP server
    $IMAPSERVER = "192.168.3.41"

    #
    # Get username and password information
    # Returns: (username, password)
    #
    sub GetLogin {
        my ($username, $password);

        print "Enter your IMAP username: ";
        chop ($username = <STDIN>);
        system "stty -echo";
        print "Enter your IMAP password: ";
        chop ($password = <STDIN>);
        system "stty echo";
        print "\n";
        return ($username, $password);
    }


    #
    # Dump a Unix-style mbox file into an IMAP folder
    # Arguments: IMAP connection, IMAP mailbox name, mbox file name
    #
    sub TransferMbox {
        my ($imap, $mailbox, $mboxfile) = @_;

        my $blank = 1;
        my $count = 0;
        my $message = "";
        my $response;

        print "Transferring $mboxfile...\n";
        open(MBOX, $mboxfile);
        if(!open(MBOX, $mboxfile))
                {       print "Open: no-cannot open $mboxfile\n";
                        return;
                }
        while (<MBOX>) {
            if ($blank && /^From /) {
                if ($message) {
                    chop $message;  # Remove extra blank line before next From
                                        if(length($message) > 1) {
                        $response = $imap->append($mailbox, $message);
                        $count++;
    #                   print $response->status, "-", $response->text, "\n";
                                        }
                }
                $message = "";
            }
            else {
                s/\r?\n//;
                $message .= $_ . "\n";
            }
            $blank = /^$/ ? 1 : 0;
        }
        $response = $imap->append($mailbox, $message) if $count;
        $count++;
    #   print $response->status, "-", $response->text, "\n";
        close(MBOX);
        print "Transferred $count messages from $mboxfile to $mailbox.\n";
    }


    #
    # Main Code
    #

    # Login to IMAP server
    ($user, $pass) = GetLogin();
    $imap = new Net::IMAP($IMAPSERVER, Synchronous => 1);
    $response = $imap->login($user, $pass);
    print "Login: ", $response->status, "-", $response->text, "\n";

        $prefix = "";
        if($ARGV[0] eq "-p") {
                shift(@ARGV);
                $prefix = shift(@ARGV);
        } elsif($ARGV[0] =~ /^-p(.*)/) {
                $prefix = $1;
                shift(@ARGV);
        }
        $prefix .= "." if($prefix =~ /.[^\.]$/);
        
    # Process each filename argument
    foreach $mbox (@ARGV) {
        $mailbox = "user.$prefix" . basename($mbox);

        # Create the new mailbox
        $response = $imap->create($mailbox);
        print "Create: ", $response->status, "-", $response->text, "\n";

        # Modify the ACL on the mailbox so we can add messages
        $response = $imap->setacl($mailbox, $user, "di");
        print "Set ACL: ", $response->status, "-", $response->text, "\n";

        # Set a 100 Meg quota on the new mailbox
        $response = $imap->setquota($mailbox, "STORAGE", 100000);
        print "Set Quota: ", $response->status, "-", $response->text, "\n";

        # Copy the mbox
        if (-s $mbox) {
            TransferMbox($imap, $mailbox, $mbox);
        }
    }

    # Disconnect from IMAP server
    $response = $imap->logout();
    print "Logout: ", $response->status, "-", $response->text, "\n";






Reply via email to