#!/usr/local/bin/perl # unread.pl # Checks for unread mail in mh folders # Anoop Sarkar $|=1; $home = $ENV{"HOME"}; $allread = 1; $verbose = 1; # set to 1 to print subject lines $folder_cmd = "/pkg/mh-6.8/bin/folder"; # set to mh folder command # location of exmh folder cache (usually ~/Mail/.folders) # if not using exmh use `folders -fast -recurse > ~/Mail/.folders` # to create a one time cache. update once folders are modified. $exmh_cache = ".folders"; # make sure that the following entries are defined in # your .mh_profile: Path, Unseen-sequence, and mh-sequences open(PROFILE,"$home/.mh_profile"); while () { chop; $maildir = "$home/$_" if s/^Path:\s*//i; $unseenseq = $_ if s/^Unseen-Sequence:\s*//i; $seqfile = $_ if s/^mh-sequences:\s*//i; } open(UNSEENFOL,"$maildir/$exmh_cache"); chdir "$maildir"; foreach $folder () { chop($folder); $list = ""; open(FOLDER,"$maildir/$folder/$seqfile"); while () { if (s/^$unseenseq: *//) { $list = "unread mail in $folder: $_" ; $allread = 0; system("$folder_cmd +$folder $unseenseq:first >/dev/null 2>/dev/null"); $list .= `scan $unseenseq` if ($verbose); } } print "$list" unless $list eq ""; } print "No unread messages\n" if ($allread && $verbose); exit 0;