Re: finding unread emails in IMAP maildir
by xdg (Monsignor) on Aug 08, 2005 at 20:39 UTC
|
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.
| [reply] [d/l] |
|
|
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
| [reply] |
|
|
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.
| [reply] [d/l] [select] |
|
|
Re: finding unread emails in IMAP maildir
by davidrw (Prior) on Aug 08, 2005 at 20:05 UTC
|
use Mail::IMAPClient;
my $imap = Mail::IMAPClient->new(
Server => $host,
User => $id,
Password=> $pass,
) or die "Cannot connect to $host as $id: $@";
$imap->select($folder);
my @msgs = $imap->unseen();
foreach my $msgid( @msgs ){
...
}
| [reply] [d/l] |
|
|
Thanks,
I really don't want to make an IMAP connection to the server. I'd rather do this on at the filesystem. I'll look into the IMAPClient module. I have a feeling that you're right in saying the way to check for new messages is with an IMAP connection.
Thanks again,
chrisj
| [reply] |
Re: finding unread emails in IMAP maildir
by sgifford (Prior) on Aug 08, 2005 at 20:04 UTC
|
Unread messages should be in the new subdirectory of Maildir, and read messages in cur. Not sure about using those modules, but that's how Maildir works. See http://cr.yp.to/proto/maildir.html.
| [reply] |
|
|
Unread messages should be in the new subdirectory of Maildir, and read messages in cur. Not sure about using those modules, but that's how Maildir works. See http://cr.yp.to/proto/maildir.html.
That's basically correct but... at least with my Postfix / Courier IMAP / Squirrelmail setup, as soon as I use Squirrelmail any messages in the new dir are moved to cur - even if they're not read yet. When the message is read, :2,S is appended to the file name in cur. This is best explained at http://www.courier-mta.org/?maildir.html . Other MTA/IMAP server/MUA combinations may handle this differently.
| [reply] |
|
|
Yes I know,
I've tried giving Email::Folder just a subdirectory of the Maildir, but it errors out saying it's not a maildir.
| [reply] |
|
|
| [reply] |
Re: finding unread emails in IMAP maildir
by adb512 (Initiate) on Aug 15, 2015 at 09:25 UTC
|
Is this advice still current. Or has another modulce come along to "trump" Mail::Box | [reply] |
|
|
| [reply] |