madbombX has asked for the wisdom of the Perl Monks concerning the following question:
I am looking to download all messages from an IMAP server (Exchange) from two folders to two files in mbox format. I have done this using Mail::IMAPClient; more specifically in the following manner:
This seems to work just fine except the files HAM.msgs and SPAM.msgs aren't in mbox format, they are just files with lists of messages in them. In an attempt to convert them, I am using the following command: `formail < /home/mail/mbox/HAM.msgs > HAM`. However, that leaves me with an mbox file that just has 1 long messgae according to mbox readers (however that long message contains all the messages in the file).foreach my $mbox qw( SPAM HAM ) { $imap->select($mbox); my @msgs = $imap->search("ALL"); $imap->message_to_file("/home/mail/mbox/$mbox".".msgs",@msgs); $imap->delete_message(@msgs); $imap->close(); }
Therefore my question is threefold:
Ultimate goal: To download the 2 folders which contain HAM and SPAM messages, feed them through sa-learn (spamassassin which requires mbox format), convert them to Maildir format using mb2md (which I already have done) so I can have dspam_train learn them (because dspam requires Maildir format to learn).
UPDATE:
This is the code that eventually ended up doing exactly what I needed it to do. Thanks to everyone for all the help, it is greatly appreciated. I will be putting the final script up on my webpage next week (http://eric.lubow.org/projects), it will be the IMAP SPAM learning script for those interested:
use Mail::IMAPClient; my $imap = Mail::IMAPClient->new( Server => 'imap.server.com:14 +3', User => 'user', Password => 'pass') or die "IMAP Failure: $@"; foreach my $box qw( SPAM HAM ) { my $file = "/home/mail/mbox/". $box; $imap->select($box); my @msgs = $imap->search('ALL') or die "Couldn't get all messages\n"; foreach my $msg (@msgs) { open my $pipe, "| formail >> $file" or die("Formail Open Pipe Error: $!"); $imap->message_to_file($pipe, $msg); close $pipe or die("Formail Close Pipe Error: $!"); $imap->delete_message($msg); } # Now expunge the messages and close the folder $imap->expunge($box); $imap->close($box); } $imap->logout();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Downloading IMAP Folders to mbox file
by sgifford (Prior) on Jun 17, 2006 at 21:04 UTC | |
by madbombX (Hermit) on Jun 18, 2006 at 01:21 UTC | |
by sgifford (Prior) on Jun 18, 2006 at 02:18 UTC | |
by madbombX (Hermit) on Jun 18, 2006 at 21:58 UTC | |
by sgifford (Prior) on Jun 18, 2006 at 22:11 UTC | |
| |
|
Re: Downloading IMAP Folders to mbox file
by TilRMan (Friar) on Jun 19, 2006 at 06:17 UTC |