#!/bin/sh # nextatt - Convert mail to NeXT format and add attachments # Brian Katzung Revision 2.6 3 December 1992 # (based on a simpler, earlier version by the same author) # # This software is provided on a strictly as-is basis. # Use it at your own risk. # # usage: # Filter message (including header lines) through # "nextatt [-courier] [-helv] [-ohlfs] [-tf typeface] # [-ps point_size] [path...]" # # When using /usr/ucb/mail, make sure the "editheaders" option is set. # Then use ~e or ~v after composing your message to enter your editor and # filter the message through nextatt. # # Attachments may also be imbedded in the message body using lines of the form: # \attach path... # (the paths are globbed by sh) # # RTF (Rich Text Format) notes: # Append a blank to lines in the middle of paragraphs, and a \ to the last # line in a paragraph (and blank lines). # Quote backslashes and braces (\ -> \\, { -> \{, and } -> \}). # # You will also have to escape characters that are interpreted by your # Bourne (or equivalent) shell's echo command. attach () { for arg do # Add "-C dir" if file is not in current directory dir=`dirname "$arg"` case $dir in .) ;; *) tar_args=\ "$tar_args -C $dir" esac # Add file name file=`basename "$arg"` tar_args=\ "$tar_args $file" # Reference the attachment in the index.rtf. # Note: NeXT doesn't balance the }'s either. echo "{{\\attachment0 $file }" >&3 done } # Process command line options type="swiss Helvetica" points=10 while true do case $1 in -[Cc]ourier) type="modern Courier" shift ;; -[Hh]elv | -[Hh]elvetica) type="swiss Helvetica" shift ;; -[Oo]hlfs) type="modern Ohlfs" shift ;; -ps) points=$2 shift 2 ;; -tf) type=$2 shift 2 ;; *) break ;; esac done # Convert to half-points points=`expr $points + $points` # Look for the subject line in order to name the attachment. # The "read" built-in destroys \'s, so use "line". :-( subj=no_subject while line=`line` do case $line in [Ss][Uu][Bb][Jj][Ee][Cc][Tt]:*) subj=`echo "$line" | sed -e 's/.......:[ ]*//' \ -e 's/[^A-Za-z0-9][^A-Za-z0-9]*/_/g' \ -e 's/\(.\{40\}\).*/\1/'` ;; "") break ;; esac echo "$line" done tmp=/tmp/na.$$ na=.tar.$$.$subj.attach trap "rm -rf $tmp" 0 mkdir $tmp exec 3> $tmp/index.rtf tar_args="-C $tmp index.rtf" # RTF boilerplate echo \ "{\\rtf0\\ansi{\\fonttbl\\f0\\f${type};} \\margl120 \\margr120 \\fs${points}" >&3 # Any attachments on the command line? case $# in 0) ;; *) echo \ "X-nextatt-note: attachments may be imbedded in the message body using X-nextatt-note: \\attach path" attach "$@" ;; esac # Look for attachments in the message body. while line=`line` do case $line in "\\attach "*) eval set -- "$line" shift attach "$@" ;; *) echo "$line" >&3 ;; esac done echo '}' >&3 # Allow file names with imbedded spaces IFS=" " tar cf - $tar_args | compress -f | uuencode "$na" > "$tmp/$na" len=`wc -c < "$tmp/$na"` # Next-Attachment: file, length, nth/of, ?, offset_in_body echo "Next-Attachment: $na," $len", 1/1, 0, 0 " cat "$tmp/$na"