Development

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). #!/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.

Parsing RSS feeds

del.icio.us is a neat service for managing an online bookmark collection. With a little bit of Perl and a few CPAN modules, you can fetch your most recent bookmarks and include them as links on your homepage. The sample script could be used in a cronjob and creates a file on you local server. It downloads my del.icio.us bookmark feed, chops it down to the ten most recent bookmarks and writes a unordered bullet list.

POP3: List messages in mailbox

Lists sender and subject on all mails in mailbox. MIME::WordDecoder is used to parse heads as most mails often has ISO-8859-1 encoded parts. It should be save to test it on any mailbox as it dosn’t change or remove anything from the mailbox. #!/usr/local/bin/perl -w use strict; use Mail::POP3Client; use MIME::WordDecoder; my ($serv, $usr, $pwd) = (@ARGV); # server, username and password as comandline parameters... my $wd = default MIME::WordDecoder; my $pop = new Mail::POP3Client( USER => $usr, PASSWORD => $pwd, HOST => $serv ); print "Found " .

Search in a LDAP directory

This example connects to a LDAP server and makes a search for a name. The name was choosen by random (among those who returned an answer from the queried LDAP). The LDAP used in this example includes a binary certificate. To prevent this from trashing you terminal, it is not printed to the screen (binary field filtered in the attribute loop). #!/usr/bin/perl -w use strict; use Net::LDAP; my $ldap = Net::LDAP->new('directory.

Which IMAP-folders exist?

The following script will make a list of which folders exist in an IMAP account. The script requires you pass hostname, accountname and password on the commandline, but it should be quite easy to change as you like. #!/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.