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

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";

Replies are listed 'Best First'.
Re^4: Downloading IMAP Folders to mbox file
by madbombX (Hermit) on Jun 18, 2006 at 21:58 UTC
    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.
        I apologize, I should have been clearer with the with actual. I can't seem to get it to close the mailbox thereby expunging the messages. When I try to connect to the Exchange server using the builtin method of Mail::IMAP4, then I get an error saying "Can't use 'NTLM' as array ref in strict subs". Ok, no problem, I'll connect to the server via another perl module. I do and I can't open the imap folders 'rw' which means that when I close them, it won't let me WRITE my changes thus expunging the mail. (This script is killing me).

        Eric