#!/usr/bin/perl # # $Id: show_flags.pl,v 1.11 2003/01/13 05:28:42 jmates Exp $ # # Hacked together script to pull apart mailfolders via # the Mail::Cclient module. use Mail::Cclient; die "Usage: $0 mailfolder [mailfolders1 .. N]\n" unless @ARGV; # testing error logging... Mail::Cclient::set_callback( log => sub { warn "Log: $_[0]: $_[1]\n"; }, dlog => sub { warn "Debug: $_[0]\n"; } ); foreach my $mbox (@ARGV) { # readonly prevents lock conflicts with active clients like pine $foo = Mail::Cclient->new($mbox, "readonly"); unless ($foo) { warn "Could not open $mbox, skipping\n"; next; } print "New: ", $foo->recent, " of ", $foo->nmsgs, " in ", $mbox, "\n"; # way to get a list of messages with the \Recent flag set??? # $foo->setflag("2,4", '\Uffda'); print "\n"; # ergh... uid's bad to iterate over!!! # for ( 1 .. $foo->uid_last ) { for (1 .. $foo->nmsgs) { # get envelope & body structures... my ($env, $body) = $foo->fetchstructure($_); print "Message No ", $_, "\n"; print " Subject: ", $env->subject, "\n"; print " From: ", $env->from->[0]->{'mailbox'}, '@', $env->from->[0]->{'host'}, "\n"; print " Date: ", $env->date, "\n"; foreach (@{$env->to}) { print " To: ", $_->{'mailbox'}, '@', $_->{'host'}, "\n"; } foreach (@{$env->cc}) { print " Cc: ", $_->{'mailbox'}, '@', $_->{'host'}, "\n"; } # elt *must* be called after fetchstructure or similar as per # the Mail::Cclient documentation $e = $foo->elt($_); print " Flags: @{$e->flags}", "\n"; # $foo->setflag($_, '\Seen'); # $e = $foo->elt($_); # print "@{$e->flags}", "\n"; print "\n"; # $foo->gc("elt", "alt", "text"); } } # if ya want to save changes... #$foo->expunge; # sample mailbox munging... #$foo->create("/tmp/zot"); #$foo->rename("/tmp/zot", "/tmp/zot.old"); ###################################################################### # # DOCUMENTATION =head1 NAME show_flags.pl - a quick hack to list information about mail folders. =head1 SYNOPSIS $ show_flags.pl ~/IMAP/SomeFolder =head1 DESCRIPTION A quick little hack aimed at easily listing the various bits of information stored in mail folders via the Mail::Cclient module. =head1 USAGE $ show_flags.pl folder1 [folder2 .. folderN] =head1 BUGS Please send any bug reports (preferably with a patch) to: jmates@sial.org =head1 SEE ALSO perl(1). =head1 AUTHOR Jeremy Mates, jmates@sial.org =head1 COPYRIGHT Copyright (c) 2000, Jeremy Mates. All Rights Reserved. This file is licensed under the terms of the Artistic License: http://sial.org/artistic_license.txt =head1 VERSION $Id: show_flags.pl,v 1.11 2003/01/13 05:28:42 jmates Exp $ =cut