#!/bin/zsh ## Copyright (C) 2007 - 2010 Steve Youngs ## Time-stamp: ## Redistribution and use in source and binary forms, with or without ## modification, are permitted provided that the following conditions ## are met: ## ## 1. Redistributions of source code must retain the above copyright ## notice, this list of conditions and the following disclaimer. ## 2. Redistributions in binary form must reproduce the above copyright ## notice, this list of conditions and the following disclaimer in the ## documentation and/or other materials provided with the distribution. ## 3. Neither the name of the University nor the names of its contributors ## may be used to endorse or promote products derived from this software ## without specific prior written permission. ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR ## IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ## DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ## BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ## OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ## IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## Commentary: # # This is a simple wrapper around sendmail that serves as a command # line mailer, along the lines of mailx or nail. ## Code: ourname=${0##*/} # Version info VERSION=0.3 COPYRIGHT="Copyright (C) 2007 - 2010 Steve Youngs " version_str="${ourname}: ${VERSION} ${COPYRIGHT}" _version () { echo $version_str } # Help/Usage usage () { cat<" echo "Date: $(date --rfc-2822)" echo "Subject: ${SUBJECT}" echo "User-Agent: bastard mailer, ${VERSION}" echo cat ${FILE} ) | ${MTA} "${RCPT}" } # Parse the command line args=vh-:F:s:c:f: rv=0 while getopts $args opts; do case $opts in (-) case $OPTARG in (from?*) FROM=${OPTARG/from=/} ;; (subject?*) SUBJECT=${OPTARG/subject=/} ;; (cc?*) CC=${OPTARG/cc=/} ;; (file?*) FILE=${OPTARG/file=/} ;; (version) _version; exit 0 ;; (help|usage) usage; exit 0 ;; (*) print Unrecognised option: --$OPTARG >&2 print See $ourname --help >&2 rv=1 ;; esac ;; (F) FROM=${OPTARG} ;; (s) SUBJECT=${OPTARG} ;; (c) CC=${OPTARG} ;; (f) FILE=${OPTARG} ;; (v) _version; exit 0 ;; (h) usage; exit 0 ;; (*) print Unrecognised option -$OPTARG >&2 print see $ourname --help >&2 rv=1 ;; esac done shift $(( $OPTIND - 1 )) # What's left on the command line _should_ be the recipients RCPT=$argv if [[ $rv -eq 0 ]]; then process_mail exit $? else exit $rv fi