Mark all messages as read in an imap folder

The follow script marks all files in a folder as read. You need to pass hostname, username and password as commandline parameters to the script and the script is hardwired to mark all files in a folder call “INBOX.spam” (Cyrus IMAP folder naming convention).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl -w
use strict;
 
use Mail::IMAPClient::BodyStructure;
use Mail::IMAPClient;
 
my ($serv, $usr, $pwd) = (@ARGV); # server, username and password as comandline parameters...
 
my $imap = Mail::IMAPClient->new(Server=>$serv,User=>$usr,Password=>$pwd);
my @folders = $imap->folders;
 
foreach my $f (@folders) {
  print 	"$f is a folder with ", $imap->message_count($f), " messages.n";
}
 
exit();
  • Hans Wurst

    I’m sorry, but where exactly does it set the Seen-flag on the messages? It just prints every folder with its message counts…