Subject: Re: Getting Mail headers without mail prog???

From: [email-masked] (Stephen R. van den Berg)
Date: 1 Nov 1995 02:25:55 GMT

Anders Waller  <[email-masked]> wrote:
>On 23 Oct 1995, Sven Guckes wrote:
>> Well, this looks at *all* lines which contain "From".
>> It should be "^From: ", though.
>> And even this does not skip "included non-quoted mails".

>Correct...Been playing some with egrep, seems the following works, havent 
>tested it much yet though...Im sure theres some case whereas it doesnt 
>work.

>alias from	'more $MAILPATH | egrep "^From: | ^From "

If you have procmail/formail installed, try:

alias from	'formail -x From: -s <$MAILPATH'

This *does* skip "included non-quoted mails".
--
Sincerely,                                                          [email-masked]
           Stephen R. van den Berg (AKA BuGless).

In this signature, the concluding three words `were left out'.

---

From: [email-masked] (Moritz D. Klingholz)
Date: 4 Nov 1995 00:06:10 GMT

Paul O Bartlett ([email-masked]) wrote:
: On 17 Oct 1995, Danny van der Rijn wrote:

: | In article <[email-masked]> [email-masked] (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 [email-masked], 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

---

From: Sven Guckes <[email-masked]>
Date: 5 Nov 95 22:41:20 GMT

[email-masked] (Bill Davis) writes:
>|>> And even this does not skip "included non-quoted mails".
>If you are on a system with egrep, then perhaps you can use sed as well.
>You could include the sed command '/^$/,$d' to keep just the header
>based on RFC 822 paragraph 3.1 "The body is ... It is separated from
>the headers by a null line (i.e.,  a line with nothing preceding the CRLF)."
>There are complications with trying to get all this on an alias line, but
>the alias could just call a script or it could be a script called "from".

''And even this does not skip "included non-quoted mails".''
Anyone have a script which takes care of "included" mails?

Sven
--
http://www.math.fu-berlin.de/~guckes/.signature

---

From: [email-masked] (Bill Davis)
Date: 3 Nov 1995 20:39:09 GMT

Anders Waller <[email-masked]> writes:
|>
|>On 23 Oct 1995, Sven Guckes wrote:
|>
|>> Well, this looks at *all* lines which contain "From".
|>> It should be "^From: ", though.
|>> And even this does not skip "included non-quoted mails".
|>
|>Correct...Been playing some with egrep, seems the following works, havent 
|>tested it much yet though...Im sure theres some case whereas it doesnt 
|>work.
|>
|>alias from	'more $MAILPATH | egrep "^From: | ^From "

Bill Davis
[email-masked]