Anyone use MAIL::IMAPClient?

Mike Eggleston mikeegg1 at mac.com
Mon Dec 10 10:54:57 EST 2007


I know this is a perl question and not an imap-specific question,
but I don't have access to my perl lists from this computer.

The script below compiles and seems to run just fine, but the
message flags are not set to \\Seen in the line

$imap->see(@msgs);

Is there something I'm missing?

Mike


---------------------------------------------
#!/usr/bin/perl

#$Id$
# copied from cyrus_expunge.pl
# given a date on the command line
# select all messages in all folders before that date
# set the \Seen flag on all selected messages

# :!perl -d % -v three days ago
# :!perl -d % -v yesterday midnight
# :!perl -d % -v two hours ago
# :!perl -d % -v '12/07/07'

use Date::Manip;
use Mail::IMAPClient;
use IO::File;
use Getopt::Std;

# parse the command line
our($opt_v, $opt_s) = (0, 0);
getopts('sv') or die "usage: $0 [-v]";
$opt_s = 1 if $opt_v;

my $start = time;

# parse the command-line date
my $bdatestr = join(' ', @ARGV);
my $bdate = ParseDate($bdatestr);
my $bsecs = UnixDate($bdate, '%s');

# Change the following line (or replace it with something better):
my($h, $u, $p) = ('imap.example.com', 'cyrus','secret');

my $imap = Mail::IMAPClient->new(
					Server => "$h",			# imap host
					User    => "$u",			# $u,	
					Password=> "$p",			# $p,
					Uid	=> 1,				# True value
					Port    => 143,				# Cyrus
					Debug	=> 0,				# True value
					Buffer	=> 4096*10,			# True value
					Fast_io	=> 1,				# True value
					Timeout	=> 30,				# True value
					# Debug_fh=> IO::File->new('>/tmp/imap.out'),	# fhandle
				) 
or die "$@";
my $rfc2060date = $imap->Rfc2060_date($bsecs);

our($folder, $nchanged) = ('', 0);
our($nfolders, $nmessages, $ntotchanged) = (0, 0, 0);

for my $f ( $imap->folders ) {
	$folder = $f;
	next unless $f =~ /user.mikee.sales/oi;
	$nfolders++;
	unless ($imap->select($f) ) {
		$imap->setacl($f, $u, 'lrswipcda') or warn "Cannot setacl for $f: $@\n" and next;
		$imap->select($f) or warn "Cannot select $f: $@" and next;
	}
	my @msgs = $imap->before($rfc2060date);
	my $messages_before = $imap->message_count($f);
	if(defined($messages_before)) {
		$imap->see(@msgs) or warn "$0: cannot set \\Seen flag on messages in folder '$f': $@";
		$nchanged = scalar(@msgs);
		$ntotchanged += $nchanged;
	}
	write if $opt_v;
}

# write a summary
if($opt_s) {
	my $stop = time;
	print "\nSummary:\n";
	print "Elapsed Seconds: ", ($stop - $start), "\n";
	print "Total Folders: $nfolders\n";
	print "Total Messages: $nmessages\n";
	print "Total Changed: $ntotchanged\n";
}

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @>>>>>
$folder,                                                  $nchanged
.

format STDOUT_TOP =
Folder                                                    Reset
--------------------------------------------------------- ------
.
---------------------------------------------


More information about the Info-cyrus mailing list