Article View: news.software.readers
Article #1428Re: How to save specific header line with 'rn' ?
From: Paul Close
Date: Tue, 07 Apr 1992 18:22
Date: Tue, 07 Apr 1992 18:22
80 lines
4469 bytes
4469 bytes
jik@athena.mit.edu (Jonathan I. Kamens) writes:
>jlim@silver.cs.umanitoba.ca (Tung Tseung Johnny Lim) writes:
>
> I am new to the 'rn' program and find it very interesting. I have checked
> the manual for 'rn' (man rn) and could not solve my problem.
> I would like to be able to save some news without including all the
> header lines (i.e. just to include: Date, From and Subject).
>
>Rn uses the %X/norm.saver and %X/mbox.saver shell scripts to save
>[...]
>
>See the rn man page to find out how to use different mbox.saver and
>norm.saver scripts.
Specifically, see the entries for MBOXSAVER and NORMSAVER. These default to
calling %X/mbox.saver and %X/norm.saver with arguments. I've included an
example below that deals with %X, so don't worry.
>Rn saves articles with the same header lines it displays on-screen.
This is is not true. Rn just saves the article as it appears in the spool
file. Look at either saver program (they're just shell scripts).
The best way to do this is to write a shell script to strip the headers you
don't want. I whipped up an expample (even tested it! :-)
In RNINIT (or the file RNINIT points to):
-EMBOXSAVER='$HOME/bin/mysaver %X/mbox.saver %A %P %c %a %B %C "%b" "From %T %`date`"'
-ENORMSAVER='$HOME/bin/mysaver %X/norm.saver %A %P %c %a %B %C "%b"'
In $HOME/bin/mysaver:
-----------------------cut here-------------------------
#!/bin/sh
saver=$1
file=$2
shift; shift
cat $file |
sed -e '/^Path: /d' -e '/^Message-ID: /d' -e '/^Path: /d' |
$saver "" "$@"
-----------------------cut here-------------------------
Now let me explain what these do. First of all, note that there is a bug in
the mbox.saver man page. The From: should be just From. The rn code gets
it right, it's the man page that's wrong.
The two -Exxx lines tell rn to substitute the following lines for the MBOX
saver and NORM saver. Since "mysaver" is just a filter, you can use it for
both programs. Next, the name of the real saver program is next. That way
rn expands the %X for you, and you don't have to worry. After that is just
the arguments the rn saver programs expect (from the man page).
The shell script does the following. First it parses out the name of the
saver program and the saver program's first arg, which is the file to get
input from. The two shifts move the argument list to make it convenient
to pass the rest of the args to the saver program. Then we pipe the news
article into sed, which removes the lines you don't want, and pipe the
output of sed into the rn saver program.
Two notes here: the "" after saver pass a null first argument to the saver
prog. If you look at the source for the two shell scripts, you'll see they
both use "tail" on their first arg, expecting a filename. By making this
null, both programs will read from stdin, which we want. Second note: "$@"
expands the args like this: "arg1" "arg2" and so on (which we also want, to
preserve the "From xxx" last arg's spaces).
There you have it! One note: the sed line will remove *any* lines that
begin with Path:, etc. There's no way for sed to know if the Path: line
is part of the header or message body. In practice this shouldn't be a
problem. The '^' in the sed lines tells sed to only match that pattern
if it is at the beginning of the line. You can add quite a number of -e
patterns to sed before it'll complain. All seds are different in this
respect, so see what works on your system.
Enjoy!
--
Paul Close pdc@sgi.com ...!{ames, decwrl, uunet}!sgi!pdc
Oh, no! You walked into the slavering fangs of a lurking grue.
Technical Details
Message-ID:
<j8lrq04@fido.asd.sgi.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!sparky!uunet!decwrl!sgi!shinobu!fido!lunch.wpd.sgi.com!pdcReferences:
<1992Apr6.213356.7296@ccu.umanitoba.ca> <JIK.92Apr7104517@pit-manager.mit.edu>Show Full Headers
Complete Article Headers
Message-ID: <j8lrq04@fido.asd.sgi.com> Subject: Re: How to save specific header line with 'rn' ? Date: Tue, 7 Apr 1992 18:22:44 GMT From: pdc@lunch.wpd.sgi.com (Paul Close) References: <1992Apr6.213356.7296@ccu.umanitoba.ca> <JIK.92Apr7104517@pit-manager.mit.edu> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!sparky!uunet!decwrl!sgi!shinobu!fido!lunch.wpd.sgi.com!pdc Newsgroups: news.software.readers Originator: pdc@lunch.wpd.sgi.com Sender: news@fido.asd.sgi.com (Usenet News Admin) Reply-To: pdc@sgi.com (Paul Close) Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 80