#! /bin/sh
# $Id: rcvxterm,v 1.2.1.2 92/08/02 18:19:27 jerry book2 $
### rcvxterm - HACK script to notify you about new mail
### Usage in .maildelivery: "/bin/cat >/tmp/m$$; /x/y/rcvxterm /tmp/m$$ &"
##
##  THIS SHELL SCRIPT READS A MAIL MESSAGE (OR ANYTHING, ACTUALLY)
##  FROM A FILE NAMED ON ITS COMMAND LINE.  IT POPS OPEN A BRIGHT WINDOW
##  (RED, MAYBE) TO SHOW THE MESSAGE; IT RUNS A PAGER PROGRAM LIKE less
##  THAT DOESN'T EXIT UNTIL YOU SELECT THE WINDOW AND TYPE A QUIT COMMAND.
##
##  NOTE!  AFTER THE WINDOW CLOSES, THE SCRIPT **REMOVES** THE FILE ON
##  THE COMMAND LINE!  THIS FILE SHOULD BE A TEMPORARY FILE!
##  HERE'S A USAGE EXAMPLE FROM A .maildelivery FILE.  IT COPIES THE
##  STANDARD INPUT (THE MESSAGE) TO A TEMP FILE, THEN STARTS rcvxterm
##  IN THE BACKGROUND.  IF YOU DON'T START rcvxterm IN THE BACKGROUND,
##  THE OTHER ACTIONS IN THE .maildelivery WOULDN'T HAPPEN, DELAYING
##  YOUR MAIL... AFTER A WHILE, rcvxterm WOULD BE KILLED ANYWAY.
##  THIS WAY, RUNNING IN THE BACKGROUND, THE WINDOW SHOULD STAY UP
##  UNTIL THE SYSTEM GOES DOWN.
##
##  TYPICAL LINE TO RUN THIS FROM .maildelivery:
##      From,root,|,R,"/bin/cat >/tmp/msg$$; /x/y/rcvxterm /tmp/msg$$ &"
##
##  GOTCHAS:
##      - IF /tmp IS CLEANED OUT PERIODICALLY ON YOUR SYSTEM AND YOU
##        DON'T LOOK AT YOUR WINDOWS BEFORE THAT, THE FILES WILL BE GONE.
##      - IF THIS CAN'T OPEN A DISPLAY, IT JUST FAILS SILENTLY.
##      - IF YOU GET LOTS OF MAIL, YOU MIGHT GET TOO MANY WINDOWS ON
##        YOUR DISPLAY.  SAVE THIS FOR IMPORTANT MAIL; USE rcvtty,
##        xbiff, OR SOMETHING SMARTER THAN THIS FOR EVERYDAY MAIL.
##
##  THIS SCRIPT CAN BE HACKED TO WORK UNDER OTHER WINDOW SYSTEMS THAN X.
##  YOU SHOULD PROBABLY JUST HACK IN THE PARAMETERS YOU WANT INSTEAD OF
##  PUTTING THEM ALL ON THE COMMAND LINE; IT KEEPS .maildelivery NEATER.
##  JUST HACK IT.  THAT'S WHY I DIDN'T DO A NEATER PROGRAMMING JOB. :-)
# 
#                             NO WARRANTY
# 
#   BECAUSE THIS PROGRAM IS AVAILABLE FREE OF CHARGE, THERE IS NO WARRANTY
# FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
# OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
# PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
# OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
# REPAIR OR CORRECTION.
# 
#   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
# REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
# INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
# TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGES.


trap '/bin/rm -f $1' 0 1 2 15   # REMOVE TEMP FILE BEFORE EXITING

# USE less BECAUSE IT DOESN'T QUIT UNTIL YOU TYPE q.  pg WORKS, TOO.
# USE FULL PATHS; REMEMBER THAT .maildelivery ENVIRONMENT IS LIMITED.
/usr/bin/X11/xterm -display hostname:0.0 \
    -geometry 80x24-0+0 -bg red -fg white \
    -title "important mail.  Press q to quit" \
    -ut -e /usr/local/bin/less $1
