#!/usr/bin/perl # # $Id: find-largest-mail,v 1.1 2005/07/26 21:39:14 vogelke Exp $ # # NAME: # find-largest-mail # # SYNOPSIS: # find-largest-mail [-v] files # # DESCRIPTION: # "find-largest-mail" finds the biggest messages in my # RMAIL mailbox. # # OPTIONS: # "-v" prints the current version and exits. # # AUTHOR: # Karl Vogel # Sumaria Systems, Inc. require "getopts.pl"; # command line args. $ENV{"PATH"} = "/bin:/usr/sbin:/usr/local/bin"; $tmp = "/tmp/find-largest-mail.$$"; ($myname) = split(/\//, reverse($0)); $myname = reverse($myname); # script basename. # # Handle command line arguments (if any). # &usage unless &Getopts('v'); &version if $opt_v; # # Look for "EOOH" at the beginning of each line, keep track of # line counts, and print the messages which are over 500 # lines long. # $line = 0; # line number. $msg = 1; # message number. $max = 500; # number of lines in mail message. $start = 0; $top = $ENV{"HOME"}; $mbox = "$top/Emacs-mail/RMAIL"; open(IN, "$mbox") || die "$mbox: $!\n"; print "msg#\tLines\tSubject\n"; print "----\t-----\t-----------------------------------------\n"; while () { chop; $line++; # # Start of new message. Find and store the subject line. # if (/^\*\*\* EOOH/) { $msg++; if ($start > 0) { $size = $line - $start; # size of previous msg. if ($size > $max) # msg over 500 lines. { print "$msg\t$size\t$sub\n"; } } while () { chop; $line++; if (/^Subject: /) { s/^Subject: //; $sub = $_; last; } } $start = $line; } } close(IN); exit(0); #--------------------------------------------------------------------- # Print a short usage message from the comment header and exit. # sub usage { if (open(PROG, "$myname")) { while () { last if /^# NAME:/; } print STDERR " NAME:\n"; while () { last if /^\s*$/; last if /^# AUTHOR:/; s/^#//; print STDERR; } close(PROG); } else { print STDERR "No usage information available.\n"; } exit(1); } #--------------------------------------------------------------------- # Print the current version and exit. # sub version { $_ = '$RCSfile: find-largest-mail,v $ $Revision: 1.1 $ ' . '$Date: 2005/07/26 21:39:14 $'; s/RCSfile: //; s/.Date: //; s/,v . .Revision: / v/; s/\$//g; print "$_\n"; exit(0); }