The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers > Answers to Frequently Asked Questions > How do I send email?
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 12-20-2002
Perderabo's Avatar
Perderabo Perderabo is offline
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,352
mimesender -- part two

Code:
		if ((nattach)) ; then
			DESC[nattach-1]=$OPTARG
		else
			scribe_err -D $optarg must follow a -A argument
			((error=error+1))
		fi
		;;
	s)
		SUBJECT=$OPTARG
		;;
	\?)
		scribe_err what is -${OPTARG}?
		((error=error+1))
		;;
	:)
		scribe_err $OPTARG need an argument
		((error=error+1))
		;;
	esac
done

#
#  Parameter error checking: an address is required

if ((!naddr)) ; then
	scribe_err "-t ADDRESS is required"
	((error=error+1))
fi


#
#  Parameter error checking: If BODY  was specified, it
#  must exist and be readable

if [[ ! -z $BODY ]] ; then
	if [[ $BODY != - ]] ; then
		if [[ ! -f $BODY ||  ! -r $BODY ]] ; then
			scribe_err  "-b $BODY is not a readable file"
			((error=error+1))
		fi
	else
		stdin_inuse=1
	fi
fi

#
#  Parameter error checking: If ATTACH was specified, it
#  must exist and be readable.  
#  Also we can use stdin only once

i=0
while ((i"
	else
		scribe_out "From: $myname <${FADDR}>"
	fi
	scribe_out  "Sender: $myname <${myaddr}>"
elif [[ -n $FNAME ]] ; then
	scribe_out "From: $FNAME <${myaddr}>"
else
	scribe_out  "From: $myname <${myaddr}>"
fi

#
#  Next we will do the "To:" Addresses

((i=0))
Line=""
while ((i1)) ; then
	scribe_out  'Content-Type: multipart/mixed; '
	scribe_out  '    boundary='\"$BOUNDARY\"
	scribe_out 
	scribe_out  "$PREAMBLE"
	scribe_out 
fi

#
#  Output message body if we have one.

if [[ -n $BODY ]] ; then
	if ((npart>1)) ; then
		scribe_out  "--${BOUNDARY}"
	fi
	scribe_out  'Content-Type: text/plain; charset=US-ASCII'
	scribe_out 
	if [[ $BODY = - ]] ; then
		cat
	else
		cat $BODY
	fi
else
	scribe_out
fi

#############################################################
#                                                           #
#    Section 3 ---  Attachments                             #
#                                                           #
#############################################################
#

#
#  Loop on our attachments... 

i=0
while ((i1)) ; then
		scribe_out  "--${BOUNDARY}"
	fi

#
#  Build attachment header

	if [[ ${FORMAT[i]} = B ]] ; then
		TYPE=$BType
	else
		TYPE=$AType
	fi
	scribe_out  'Content-Type: '${TYPE}'; name="'${ATTACH[i]}\"

	if [[ ${FORMAT[i]} != A ]] ; then
		scribe_out "Content-Transfer-Encoding: x-uue"
	fi

	scribe_out  'Content-Disposition: attachment; filename="'${DESC[i]}\"
	scribe_out 

#
#  Build a pipeline to process the attachment

	if [[ ${ATTACH[i]} = - ]] ; then
		PIPELINE="cat"
	else
		PIPELINE="cat ${ATTACH[i]}"
	fi
	[[ ${FORMAT[i]} = X ]] && PIPELINE=${PIPELINE}"| sed \"s/$/\${CR}/\""
	[[ ${FORMAT[i]} != A ]] && PIPELINE=${PIPELINE}"|uuencode ${DESC[i]}"
	scribe_debug PIPELINE = "$PIPELINE"
	eval $PIPELINE

	scribe_out 
	((i=i+1))
done

#############################################################
#                                                           #
#    Section 4 ---  Send Mail                               #
#                                                           #
#############################################################
#

#
#  If in multipart mode, do final boundary

if ((npart>1)) ; then
	scribe_out  "--${BOUNDARY}--"
fi

#
#  Here is where we send the mail

} | eval $MTA ${TADDR[@]}

if ((DEBUG)) ; then
	while read l ; do scribe_debug "$l" ; done < $DEBUGFILE
	rm $DEBUGFILE
fi

exit 0