[comp.mail.mush] Saving just mail headers

a20@nikhefh.hep.nl (Marten Terpstra) (08/10/89)

Hi,

Can anyone tell me if it is possible to just save mail headers without
the message body ?

Thanks,


-- 
            Marten Terpstra   email : terpstra@nikhef.nl
NIKHEF-H (National Institute for Nuclear and High Energy Physics)   Amsterdam
-----------------------------------------------------------------------------
-- Workers of the world arise, you have nothing to loose but your chairs ! --

argv%eureka@Sun.COM (Dan Heller) (08/11/89)

In article <236@nikhefh.hep.nl> a20@nikhefh.hep.nl (Marten Terpstra) writes:
> Can anyone tell me if it is possible to just save mail headers without
> the message body ?

no, but you can save outgoing mail headers only using "set logfile = ..."

dan <island!argv@sun.com>
-----
My postings reflect my opinion only -- not the opinion of any company.

dan <island!argv@sun.com>
-----
My postings reflect my opinion only -- not the opinion of any company.

schaefer@ogccse.ogc.edu (Barton E. Schaefer) (08/11/89)

In article <120719@sun.Eng.Sun.COM> argv@sun.UUCP (Dan Heller) writes:
} In article <236@nikhefh.hep.nl> a20@nikhefh.hep.nl (Marten Terpstra) writes:
} > Can anyone tell me if it is possible to just save mail headers without
} > the message body ?
} 
} no, but you can save outgoing mail headers only using "set logfile = ..."

"NO?"  Not feeling terribly helpful today, Dan? :-)	[%]

Of course you can save just the headers, you just can't do it with the
"save" command.

Try

    mush> pipe sed -n 1,/\^\$/p >> file

If you want a message list rather than the current message, the list goes
between the "pipe" and the "sed".  Note that the Bourne shell, which is
run by the "pipe" command, is performing the >> redirection; mush doesn't
do that itself. [%%]

"pipe" does not write the ignored headers ("ignore" command or "show_hdrs"
variable).  If you want to save ALL the headers, you have to do a little
more work:

    mush> set print_cmd='sed -n 1,/\^\$/p >> file'
    mush> lpr
    printing message 11...(219 lines)
    1 message printed through "sed -n 1,/\^\$/p >> file".
    mush> unset print_cmd

You can of course bundle all this up into a "cmd" alias (the quoting is a
bit nasty, escaped newlines for readability):

    cmd sv_hdrs "\
	    set sv_list ;\
	    set print_cmd='"'sed -n 1,/\^\$/p >> \!:$'"'"' ;\
	    lpr $sv_list \!* ;\
	    unset sv_list print_cmd'

Some non-obvious things going on here.  I'll explain the mush ones, sed
is up to you:

    set sv_list	
		This exploits a special feature of the "set" command
		to allow you to pipe to sv_hdrs.  For example,
		    pick mush-users | sv_hdrs mu-hdrs
		expands to
		    pick mush-users | set sv_list ; set print_cmd=...
		and $sv_list gets set to the messages found by pick.

    set print_cmd='sed -n 1,/\^\$/p >> \!:$'
		The \!:$ sets the file name to the last argument on the
		sv_hdrs command line, for compatibility with "save".
		YOU MUST GIVE A FILE NAME!  Otherwise you will either
		get an error or the message list will be used as a file
		name, which probably is not what you want.

    lpr $sv_list \!*
		The \!:* picks up any message list that was given before
		the file name.  It also picks up the file name, but the
		"lpr" command conveniently ignores that.  The $sv_list
		spits out whatever messages were piped to sv_hdrs.  So
		all messages listed and piped get their headers saved.

I think that about covers it. :-)  Hope it helps.	[+]
____________

%  This newsgroup is "comp.mail.mush" not "comp.mush.ask.dan.and.bart".
   Anybody else who wants to jump in with a clever suggestion is always
   welcome to do so.  In fact, I'm going to start waiting a day or two
   for other answers to show up, unless somebody jumps in with something
   completely wrong.

%% The characters < and > are used in E-mail addresses, so mush avoids
   using them as redirection metachars.

+  If you don't want long answers, don't ask leading questions. :-)
____________
-- 
Bart Schaefer           "And if you believe that, you'll believe anything."
                                                            -- DangerMouse
CSNET / Internet                schaefer@cse.ogc.edu
UUCP                            ...{sequent,tektronix,verdix}!ogccse!schaefer

loverso@Xylogics.COM (John Robert LoVerso) (08/12/89)

In article <4177@ogccse.ogc.edu> schaefer@ogccse.UUCP (Barton E. Schaefer) writes:
>     mush> pipe sed -n 1,/\^\$/p >> file
...
> "pipe" does not write the ignored headers ("ignore" command or "show_hdrs"
> variable).  If you want to save ALL the headers, you have to do a little
> more work:
>     mush> set print_cmd='sed -n 1,/\^\$/p >> file'
>     mush> lpr
>     printing message 11...(219 lines)
>     1 message printed through "sed -n 1,/\^\$/p >> file".
>     mush> unset print_cmd

Not to be picky, but this sounds more like the "lpr" command is unneeded,
and that "pipe" needs additional work.  I.e., perhaps there should be an
option to pipe, "-a"(?), which says "even send all headers".  Then
"lpr" just becomes an alias using "pipe -a", and the mechanism pipe out
complete messages becomes much cleaner.

John
-- 
John Robert LoVerso			Xylogics, Inc.  617/272-8140
loverso@Xylogics.COM			Annex Terminal Server Development Group
encore!xylogics!loverso			[formerly of Encore Computer Corp]

schaefer@ogccse.ogc.edu (Barton E. Schaefer) (08/12/89)

In article <6883@xenna.Xylogics.COM> loverso@Xylogics.COM (John Robert LoVerso) writes:
} In article <4177@ogccse.ogc.edu> schaefer@ogccse.UUCP (Barton E. Schaefer) writes:
} >     mush> pipe sed -n 1,/\^\$/p >> file
} ...
} > "pipe" does not write the ignored headers ("ignore" command or "show_hdrs"
} > variable).  If you want to save ALL the headers, you have to do a little
} > more work:
} >     mush> set print_cmd='sed -n 1,/\^\$/p >> file'
} >     mush> lpr
} 
} Not to be picky, but this sounds more like the "lpr" command is unneeded,
} and that "pipe" needs additional work.  I.e., perhaps there should be an
} option to pipe, "-a"(?), which says "even send all headers".  Then
} "lpr" just becomes an alias using "pipe -a", and the mechanism pipe out
} complete messages becomes much cleaner.

This has already been under discussion for some days, originally for
other reasons, but nobody has time to work it out at the moment.

I should mention that there is an error in the "sv_hdrs" cmd that I
included in the original article.  If given a list of several messages,
it will save the headers only of the first, because "lpr" starts only
one "print_cmd" process and sends all the messages to it separated by
form feeds.  (A difference from "pipe" that presently does make the
"lpr" command needed.)

To make sv_hdrs work correctly for a list of messages, substitute the
variable "pager" for "print_cmd" and substitute the command "print"
for "lpr".  You probably want to save the original value of $pager in
another variable and restore it afterwards.
-- 
Bart Schaefer           "And if you believe that, you'll believe anything."
                                                            -- DangerMouse
CSNET / Internet                schaefer@cse.ogc.edu
UUCP                            ...{sequent,tektronix,verdix}!ogccse!schaefer