The mimecat Shell Script

[return-to Explanation of mimecat] [table of contents] [index]
#!/bin/sh
# $Id: mimecat 1.0 1994/12/10 12:47:21 jerry book3 $
### mimecat - send content of an MH MIME message to standard output
### Usage: mimecat [-part nn]
##
##  THIS SCRIPT RUNS mhn -store TO OUTPUT MESSAGE CONTENT TO THE
##  STANDARD OUTPUT.  FOR MULTIPART MESSAGES, GIVE THE -part SWITCH.
##  IF THE SCRIPT STORES PARTS THAT AREN'T LISTED IN ITS $profile
##  VARIABLE (SEE BELOW), IT WARNS YOU.
##
##  BECAUSE mhn -store UN-ENCODES THE MESSAGE, THIS IS AN EASY WAY
##  TO UN-DO quoted-printable AND base64 ENCODING.

mhnout=/tmp/MIMECATm$$
profile=/tmp/MIMECATp$$
stat=1  # DEFAULT EXIT STATUS; RESET TO 0 FOR NORMAL EXITS
trap 'rm -f $mhnout $profile; exit $stat' 0
trap 'echo "$0: interrupted.  Quitting early..." 1>&2; exit' 1 2 15

# THE MH 6.8.3 VERSION OF mhn -store SEEMS TO HAVE A BUG:
# A mhn-store- PROFILE ENTRY OF "-" (DASH) IS SUPPOSED TO WRITE A
# CONTENT TO STANDARD OUTPUT.  BUT IT DOESN'T; IT MAKES A FILE
# NAMED "-".  WORK AROUND THE PROBLEM BY MAKING A PROFILE STRING
# THAT RUNS "| cat".  IF YOUR VERSION OF mhn WORKS RIGHT, REPLACE
# THE LINE BELOW WITH output='-' AND CHANGE THE grep -v COMMAND.
output='| cat'

# CONFIGURE FOR TYPES YOU WANT TO BE ABLE TO OUTPUT.
# TYPES NOT LISTED WILL BE STORED USING RULES IN YOUR OTHER PROFILE(S).
# NOTE: SHELL EXPANDS SOME METACHARACTERS (LIKE ` AND $) IN HERE:
cat > $profile << ENDPROFILE
mhn-store-text/plain: $output
mhn-store-text/enriched: $output
mhn-store-text/richtext: $output
mhn-store-application/octet-stream: $output
mhn-store-application/postscript: $output
ENDPROFILE

# STORE PARTS IN $profile -- AND MAYBE OTHER PLACES TOO.  CAPTURE mhn STDERR:
MHN=$profile mhn -store -noverbose -noauto ${1+"$@"} 2>$mhnout

# CHECK mhn OUTPUT FOR PROBLEMS.  TYPICAL OUTPUT:
#   1. storing msg 105 part 1.1 using command (cd /tmp;  cat)
#   2. storing message 105 part 2 as file /tmp/105.2.basic
#
# IF ANY LINES DON'T MATCH LINE 1 ABOVE, SHOW THEM.
# ELSE SET A ZERO (SUCCESS) EXIT STATUS:
grep -v "^storing m.*using command (cd.*cat)" $mhnout 1>&2 || stat=0

[Table of Contents] [Index] [Return to Explanation of mimecat]


Last change $Date: 1996/06/06 15:13:48 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jerry@ora.com>

Questions or problems regarding this web site should be directed to Steve Gielda.
Copyright 1999 www.cotse.com.  All rights reserved.
Last modified: Friday April 02, 1999.