On Jan 30, 2013, at 8:39 PM, Ben Morrow <ben@morrow.me.uk> wrote: [...]
Mail::IMAPClient (which I usually prefer) will work with a preauthenticated socket, but you need to create a socketpair explicitly, fork and exec dovecot/imap with one end of the pair on STDIN/STDOUT, then pass the other end to Mail::IMAPClient->new as the Socket parameter. Something like this (I've left out error checking) [...]
Thanks again for your help!
To close the loop on this, I ended up doing the following, although it seems to fail on mailboxes with large numbers of messages (on the order of 10,000 or so; I didn't test carefully enough to find the exact number)
use Mail::IMAPClient;
use Socket;
use strict;
socketpair( my $dovecot, my $client, AF_UNIX, SOCK_STREAM, PF_UNSPEC );
unless ( fork() ) {
open( STDIN, '<&', $client );
open( STDOUT, '>&', $client );
exec( '/usr/lib/dovecot/imap' );
}
close( $client );
my $imap = Mail::IMAPClient->new( Socket => $dovecot );
foreach my $folder( sort $imap->folders() ) {
print( "$folder\n" );
$imap->select( $folder );
$imap->set_flag( 'Seen', $imap->search( 'ALL' ) );
}
For the moment the failure on large folders was easier to handle by just doing those folders manually, although I'm curious if anyone knows the reason that might fail.
--Bret