[Dovecot] Marking messages read / retaining date with Sieve

Ben Morrow ben at morrow.me.uk
Thu Jan 31 03:39:40 EET 2013

At  7PM -0500 on 30/01/13 you (Bret Martin) wrote:
> On Jan 30, 2013, at 6:56 PM, Ben Morrow <ben at morrow.me.uk> wrote:
> > I would do this by scripting IMAP access. Perl's Mail::IMAPClient has
> > explicit support for running dovecot/imap in preauth mode, so you don't
> > even have to authenticate. Of course, you need a Dovecot user account
> > with access to all the relevant messages.
> Thanks so much for your help! This sounds like a great option to me.
> For "explicit" support, I'm having a lot of trouble finding out how to
> have Mail::IMAPClient invoke /usr/lib/dovecot/imap instead of
> connecting over the network -- could you provide any pointers?

Ack, sorry, I was misremembering: it's Net::IMAP::Simple that has
explicit support (note that the dovecot invocation example in the
perldoc is for dovecot 1.x, for 2.x you just run
$prefix/libexec/dovecot/imap directly). 

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)

    use Socket;

    socketpair my $DOVE, my $CLIENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC;

    unless (fork) {
        open STDIN, "<&", $CLIENT;
        open STDOUT, ">&", $CLIENT;
        exec "/usr/local/libexec/dovecot/imap";
    close $CLIENT;

    my $IMAP = Mail::IMAPClient->new(
        Socket  => $DOVE,
        # other options

    # don't forget to wait for the imap process when you've finished


More information about the dovecot mailing list