#!/usr/bin/perl -w # # $Id: newmail.pl,v 1.7 2003/01/13 05:28:42 jmates Exp $ # # Copyright (c) 2000-2001, Jeremy Mates. This script is free # software; you can redistribute it and/or modify it under the same # terms as Perl itself. # # Run perldoc(1) on this file for additional documentation. # ###################################################################### # # REQUIREMENTS require 5; use strict; ###################################################################### # # MODULES use Carp; # better error reporting use Getopt::Std; # command line option processing use Mail::Cclient; # requires UW-IMAP to build ###################################################################### # # VARIABLES my $VERSION; ($VERSION = '$Revision: 1.7 $ ') =~ s/[^0-9.]//g; my (%opts, $verbose); ###################################################################### # # MAIN # parse command-line options getopts('h?v', \%opts); help() if exists $opts{'h'} or exists $opts{'?'}; $verbose = 1 if exists $opts{'v'}; # read from STDIN if no args left chomp(@ARGV = ) unless @ARGV; # and flag the help text if nothing from STDIN help() unless @ARGV; # loop over supplied args as mailboxes, open readonly and determine # number of new messages therein for my $mailbox (@ARGV) { my $c = Mail::Cclient->new($mailbox, "readonly"); # 2000-10-23 c-client library doesn't like certain folders, # e.g. those that have spaces in their name, so skip 'em unless (defined $c) { warn "Problem with ", $mailbox, ", skipping\n" if $verbose; next; } my $total = $c->nmsgs; my $recent = $c->recent; if ($recent == 0) { print 'no new mail in ', $mailbox, "\n" if $verbose; } else { print $recent, ' new of ', $total, ' in ', $mailbox, "\n"; } } exit; ###################################################################### # # SUBROUTINES # a generic help blarb sub help { print <<"HELP"; Usage: $0 [options] Displays new mail counts in passed mailbox file names. Options for version $VERSION: -h/-? Display this message Run perldoc(1) on this script for additional documentation. HELP exit; } __END__ ###################################################################### # # DOCUMENTATION =head1 NAME newmail.pl - a perl script to report new mail using Mail::Cclient =head1 SYNOPSIS $ newmail.pl /var/mail/$USER =head1 DESCRIPTION newmail.pl is a utility capable of reporting how many new messages exist in specified local mail folders, using the Mail::Cclient module. To use, pass the script one or more paths to mailbox files. If none are mentioned on the command line, the script will attempt to read from STDIN. For instance, assuming your IMAP server stores everything under ~/IMAP, one could run: $ find ~/IMAP -type f | newmail.pl To get a listing of what folder have new mail in them. =head1 OPTIONS This script currently supports the following command line switches: =over 4 =item B<-h>, B<-?> Prints a brief usage note about the script. =back =head1 BUGS =head2 Reporting Bugs Newer versions of this script may be available from: http://sial.org/code/perl/ If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome. =head2 Known Issues No known bugs. =head1 SEE ALSO perl(1). =head1 AUTHOR Jeremy Mates, http://sial.org/contact/ =head1 COPYRIGHT Copyright (c) 2000-2001, Jeremy Mates. This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 VERSION $Id: newmail.pl,v 1.7 2003/01/13 05:28:42 jmates Exp $ =cut