#!/usr/bin/perl # Print a summary of mail messages. # Usage: # mail_header mail_box_file # # For example, # mail_header /usr/spool/mail/user_name # # If the mail_box_file is not set, the default is /usr/spool/mail/user_name # # The output is much like mail -H, but this program allows more control over # what the output fields are. # # T. Metcalf 1996-03-15 # Copyright (C) 1996 Thomas R. Metcalf # # This software is provided "as is" and is subject to change without # notice. No warranty of any kind is made with regard to this software, # including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose. The author shall # not be liable for any errors or for direct, indirect, special, # incidental or consequential damages in connection with the furnishing, # performance, or use of this software: use it at your own risk. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this library; if not, write to the Free # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # if ($#ARGV >= 0) { $FILE = $ARGV[0]; } else { $FILE = "/var/mail/$ENV{'LOGNAME'}"; } open(FILE, $FILE) || exit; $message = 0; $last_line_blank = 1; # start of file treated as a blank line while () { chop; # The start of a message is defined to be a line with format exactly like # From owner-wx-tropl@POSTOFFICE.CSO.UIUC.EDU Fri Mar 15 02:52:05 1996 # or # From owner-wx-tropl@POSTOFFICE.CSO.UIUC.EDU Fri Mar 15 02:52 HST 1996 # or # From owner-wx-tropl@POSTOFFICE.CSO.UIUC.EDU Fri Mar 15 02:52:05 HST 1996 # or # From owner-wx-tropl Fri Mar 15 02:52:05 1996 # etc. # preceded by either the start of the file or a blank line. # This seems to mimic the mail command pretty well. if (/^From\s+(\S+)(@(\S+)|)\s+((Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+(\d+)\s+(\d{1,2}:\d{1,2}(:\d{1,2}|))\s+(\S*)\s*(\d{4,4}))\s*$/i && ($last_line_blank)) { if ($message > 0) { &OUTPUT();} &RESET(); $from = $1.$2; $date = $4; $dow = $5; $mon = $6; $day = $7; $time = $8; $zone = $10; $year = $11; } ++$lines; if (/^Return-Path:\s+\<(\S+)(@(\S+)|)\>/i) { $from = $1.$2; } if (/^Subject:\s*(.*)/i) {$subject=$1;} if (/^$/) {$last_line_blank = 1;} else {$last_line_blank = 0;} } &OUTPUT(); exit; sub RESET { ++$message; $from = ""; $subject = ""; $date = ""; $dow = ""; $mon = ""; $day = ""; $time = ""; $zone = ""; $year = ""; $lines = 0; } sub OUTPUT { print "$message $from $date $lines $subject\n"; }