Article View: comp.mail.pine
Article #42Re: Getting Mail headers without mail prog???
From: Moritz D. Klingholz
Date: Sat, 04 Nov 1995 00:00
Date: Sat, 04 Nov 1995 00:00
109 lines
5187 bytes
5187 bytes
Paul O Bartlett (pobart@access.digex.net) wrote:
: On 17 Oct 1995, Danny van der Rijn wrote:
: | In article <45bj41$71u@nic-nac.CSU.net> dlegate@rsa.csuhayward.edu (Dan LeGate) writes:
: |
: | >So my question is: does anyone know of any
: | >SMALL utilities out there that will list just your mail headers (besides
: | >mail and mailx)? Thanks for any help or information you can provide.
: |
: | /usr/ucb/from
: This is fine provided all of your incoming mail is in your INBOX
: (i.e., still in the mail spool). However, I, like _many_ people, use a
: utility such as procmail (or filter) to pre-sort mail into various
: folders before I ever invoke my mail reader (Pine, in my case). I have
: been wanting a utility (Perl OK) that would list the headers of mail not
: only remaining in the INBOX but also in pre-sorted folders.
It's just five awk-commands, see at the end :-)
NOTES
- This is too slow for big files. A C version would do better.
- Your awk will need "toupper()". This is ok e.g. with AIX and Linux,
but not e.g. with IRIX 4 or SunOS 5.
- Have an eye on the /var/spool/mail path.
- You will have to write the man page yourself ...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!/bin/sh
# @(#) from 0.1 by moritz@math.uni-duesseldorf.de, 1995.11.03
Usage () {
cat <<EOF | more
Usage: ${ThisCmd} [-h] [-s Sender] [[-u] User] [-d Directory] [-f File(s)]
This command displays the message headings on your system mailbox
to show you whom mail is from. Flags modify ${ThisCmd}'s behavior.
-h Display this help. Do nothing else.
-s Sender Display only mails from this sender.
[-u] User Use this users system mailbox instead of yours.
-d Directory Use this directory instead of /var/spool/mail/.
-f File(s) Use this file or these files instead of your system
mailbox. A dash (-) stands for standard input,
directories and non-existent or unreadable files
are ignored silently.
The location of your system mailbox is stored in the MAILBOX or MAIL
environment variable or defaults to /var/spool/mail/\$LOGNAME. The
sender string is matched against the beginning of the 'From:'-field
ignoring case. (This is what the standard from command does, sorry.)
You may omit the -u flag if the user parameter is not equal to any
of the flags. Specifying "User -d Directory" or "-f Directory/User"
is the same. But the -f flag must be teh last flag if it is present.
EOF
}
ThisCmd="`basename $0`"
Sender=""
MailBox="${MAILBOX:-${MAIL:-/var/spool/mail/$LOGNAME}}"
while [ $# -gt 0 ] ; do
case "$1" in
-h)
Usage
exit 0 ;;
-s)
shift
Sender="$1"
if [ $# -gt 0 ] ; then
shift
fi ;;
-u)
shift
MailBox="`dirname ${MailBox}`/$1"
if [ $# -gt 0 ] ; then
shift
fi ;;
-d)
shift
MailBox="$1/`basename ${MailBox}`"
if [ $# -gt 0 ] ; then
shift
fi ;;
-f)
shift
MailBox="$*"
break ;;
*)
MailBox="`dirname ${MailBox}`/$1"
shift ;;
esac
done
Files="/dev/null"
for File in ${MailBox} ; do
if [ "${File}" = "-" -o \( -f "${File}" -a -r "${File}" \) ] ; then
Files="${Files} ${File}"
fi
done
cat -sv ${Files} 2>/dev/null | \
awk '
BEGIN {S="^" toupper(S)}
!B && $1=="From" {H=1; sub(/^From [^ ]* /, " "); D=$0}
H && $1=="From:" && toupper($2)~S {print $0 D}
NF>0 {B=1}
NF==0 {B=0; H=0}
' S="${Sender}" 2>/dev/null
Technical Details
Message-ID:
<47eapi$bna@selene.rz.uni-duesseldorf.de>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<45bj41$71u@nic-nac.CSU.net> <DVANDERR.95Oct17153012@hen3ry.oracle.com> <Pine.SUN.3.91.951018103830.14452D-100000@access2.digex.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f4424,1da94461f21b3512 X-Google-Attributes: gidf4424,public X-Google-Thread: f72b0,1da94461f21b3512 X-Google-Attributes: gidf72b0,public X-Google-Thread: 10650a,d99c990480db6016 X-Google-Attributes: gid10650a,public X-Google-Thread: 115614,1da94461f21b3512 X-Google-Attributes: gid115614,public X-Google-Thread: 106cc5,1da94461f21b3512 X-Google-Attributes: gid106cc5,public X-Google-Thread: fc89c,d99c990480db6016 X-Google-Attributes: gidfc89c,public X-Google-Thread: fd322,1da94461f21b3512 X-Google-Attributes: gidfd322,public X-Google-Thread: 10183f,1da94461f21b3512 X-Google-Attributes: gid10183f,public From: moritz@math.uni-duesseldorf.de (Moritz D. Klingholz) Subject: Re: Getting Mail headers without mail prog??? Date: 1995/11/04 Message-ID: <47eapi$bna@selene.rz.uni-duesseldorf.de> X-Deja-AN: 118613905 references: <45bj41$71u@nic-nac.CSU.net> <DVANDERR.95Oct17153012@hen3ry.oracle.com> <Pine.SUN.3.91.951018103830.14452D-100000@access2.digex.net> followup-to: comp.mail.pine,comp.mail.headers,comp.mail.misc,comp.unix.misc,ca.unix,comp.unix.aix,comp.unix.internals,comp.unix.programmer,comp.unix.questions,comp.unix.shell,comp.unix.user-friendly organization: Mathematisches Institut der Heinrich Heine Universitaet Duesseldorf newsgroups: comp.mail.pine,comp.mail.headers,comp.mail.misc,comp.unix.misc,ca.unix,comp.unix.aix,comp.unix.internals,comp.unix.programmer,comp.unix.questions,comp.unix.shell,comp.unix.user-friendly