in reply to finding unread emails in IMAP maildir

Sometimes, Email::Simple and friends are too simple. I strongly suggest you look at Mail::Box. It looks big and complicated because of the incredibly complex class heirarchy, but read the Mail::Box::Cookbook and experiment with it and you'll find it's not terribly hard to use. Once you get used to it (and there is a big learning curve) it's a swiss-army-chainsaw for mail processing.

Given your question, you probably want something like this (not tested):

my $manager = Mail::Box::Manager->new; my $folder = $manager->open( folder => $ENV{MAIL} ); foreach my $message ( $folder->messages ) { next if $message->label( 'seen' ); my $bounce = $message->bounce( To => 'you@somewhere.com' ); $bounce->send; $message->label( 'seen' => 1 ); } $folder->close;

Look at Mail::Message for other things you can do with a message (reply, forward, etc.) There's also very good online documentation with links for a mailing list that is very responsive to questions.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^2: finding unread emails in IMAP maildir
by chrisj0 (Acolyte) on Aug 08, 2005 at 20:54 UTC
    Yes, you're right about Email::Simple being too simple. I really didn't want to rewrite the whole thing, but I guess it's good practice.
    I'll take a look at the Mail::Box suite of modules and see how hard it would be to intregrate.
    Thanks for your help,
    chrisj

      One nice feature about Mail::Box is that it tries to make things as consistent as possible across backends. So, for example, $message->label( 'seen' ) is the same whether you're using Maildirs or IMAP, even though the way the two signal seen vs. unseen messages is very different. Shifting my example above to an IMAP routine instead of a Maildir routine probably only requires changing the way in which you call $manager->open( ... ) to include the right parameters for an IMAP type folder (server, user, password, etc.). (Assuming everything else is supported in the new type of folder, of course.)

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        awesome. Thanks.
        I'll give this a try asap
        Thanks again,
        chrisj