Below I have pasted some code that seems to work for setting the \Seen flag to a Cyrus IMAP store, however when looking at the store through mutt or Outlook the messages have not had the \Seen flag attached. Does anyone know why or see something I have wrong?
#!/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 [-vs]";
$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'), # f
+handle
)
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.user.sales/oi;
$nfolders++;
unless ($imap->select($f) ) {
$imap->setacl($f, $u, 'lrswipcda') or warn "$0: Cannot setacl
+for $f: $@\n" and next;
$imap->select($f) or warn "$0: 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 messa
+ges 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 Purged
--------------------------------------------------------- ------
.