Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Mail::IMAPClient setting flags?

by edwyr (Sexton)
on Dec 10, 2007 at 19:21 UTC ( [id://656200]=perlquestion: print w/replies, xml ) Need Help??

edwyr has asked for the wisdom of the Perl Monks concerning the following question:

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 --------------------------------------------------------- ------ .

Replies are listed 'Best First'.
Re: Mail::IMAPClient setting flags?
by naChoZ (Curate) on Dec 10, 2007 at 20:15 UTC

    What version of Mail::IMAPClient are you running? MARKOV recently took over maintainership of the module, which is good because he's written some very useful mail modules already. If you haven't upgraded to the lastest version 3.02, give that a spin and see if that works for you.

    If you're already running MARKOV's version, try backreving to the last version by DJKERNEN 2.2.9. MARKOV has been doing some rewriting, so it might help flush out any potential bugs in his new code.

    I would test it near the end of your script by grabbing a list from $imap->seen and comparing it to @msgs in your code to make sure the "Seen" flag was really changed.

    --
    naChoZ

    Therapy is expensive. Popping bubble wrap is cheap. You choose.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://656200]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-29 12:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found