in reply to Re: Downloading IMAP Folders to mbox file
in thread Downloading IMAP Folders to mbox file

I don't see how this can work in conjunction with Mail::IMAPClient's message_to_file since message_to_file's messages already have message id's which, according to Mail::Box::Mbox, they will then get passed over. And also, I wouldn't be able to pass it a message object like it wants, I would only be able to pass it (at best) a message individually from the IMAP download. This also doesn't seem to have the ability to repair an mbox mailbox which is what seems like it could help.

Eric

  • Comment on Re^2: Downloading IMAP Folders to mbox file

Replies are listed 'Best First'.
Re^3: Downloading IMAP Folders to mbox file
by sgifford (Prior) on Jun 18, 2006 at 02:18 UTC
    You should be able to construct a Mail::Box::Message object from the IMAP data. Alternatively, it looks like Mail::Box::IMAP4 might help you get messages in the right format easily.

    Update: Here's an example:

    #!/usr/bin/perl use warnings; use strict; use Mail::Box::Manager; my $mgr = Mail::Box::Manager->new or die "Couldn't create manager\n"; my $imap_client = Mail::IMAPClient->new(Server => 'suspectclass.com', User => 'username', Password => 'pass') or die "Couldn't create IMAP client\n"; my $imap = $mgr->open(type => 'imap', imap_client => $imap_client, folder => 'INBOX') or die "Couldn't create IMAP client\n"; open(M,'>> INBOX.mbox') or die "Couldn't create INBOX.mbox: $!\n"; close(M); my $mbox = $mgr->open(type => 'mbox', folder => './INBOX.mbox', access => 'rw') or die "Couldn't open MBOX folder\n"; my @m = $imap->messages('ALL') or die "Couldn't get all messages\n"; $mgr->copyMessage($mbox,@m) or die "Couldn't copy messages\n";
      You have been a great help so far and the code you gave me is working like a charm. I am just having a real problem grasping the concept of how this module works. I have been sitting here for a few hours now trying to figure out the best way to delete (or mark for deletion) and then expunge all the messages in both folders that I am attempting to work with.
      my $imap_client = Mail::IMAPClient->new( Server => 'imapserver.com:14 +3', User => 'uname', Password => 'pass') or die "IMAP Failure: $!"; foreach my $box qw( SPAM HAM ) { my $imap = $mgr->open( type => 'imap', imap_client => $imap_client, folder => "$box") or die "Couldn't create IMAP Client: $!\n"; open (MBOX, ">/home/mail/mbox/$box") or die "Couldn't create MBOX folder: $!\n"; close(MBOX); my $mbox = $mgr->open( type => 'mbox', folder => "/home/mail/mbox/$box", access => 'rw') or die "Couldn't open MBOX folder\n"; my @msgs = $imap->messages('ALL') or die "Couldn't get all messages\n"; $mgr->copyMessage($mbox,@msgs) or die "Couldn't copy messages\n"; # ... I know the msgs delete code goes here ... } $imap->logout();

      Basically I know what needs to be done, but I just can't grasp how to do it. Thanks again for all the help thus far.

      Eric

        You could try the moveMessage method, which is supposed to copy and delete in one function call. Or you could try the delete method.