3 # This is a script to mimic sendmail(1) interface, but
4 # forward mail to local MTA via sendEmail(1).
6 .
/usr
/lib
/tool
/bash-utils ||
exit -1
11 get_recipients_from_headers
=no
12 single_dot_terminates_input
=yes
22 -t) get_recipients_from_headers
=yes;;
24 get_recipients_from_headers
=yes
25 single_dot_terminates_input
=no
28 single_dot_terminates_input
=no
;;
31 warnx
"Ignoring option: -o $1";;
33 errx
22 "Option not supported: $1";;
34 -*) errx
22 "Unknown option: $1";;
35 *) recipient
+=("$1");;
40 if [ $get_recipients_from_headers = yes -a ${#recipient[@]} != 0 ]
42 errx
22 "Option -t and specifying recipients are mutually exclusive."
46 maildomain
=`cat /etc/domain || cat /etc/mailname`
50 # add local domain name if there is no domain part in the address
54 addr
=$addr@
$maildomain
59 if [ -z "$envelope_sender" ]
61 envelope_sender
=$USER@
$maildomain
63 envelope_sender
=`qualify_address "$envelope_sender"`
66 for idx
in ${!recipient[@]}
68 recipient
[$idx]=`qualify_address "${recipient[$idx]}"`
72 auto_qualify_recipients
()
74 local line hname hcontent
76 while IFS
=$
'\n' read -r line
78 if [[ $line =~ ^
(To|Cc|Bcc
):([^$
'\r']+) ]]
80 hname
=${BASH_REMATCH[1]}
81 hcontent
=${BASH_REMATCH[2]}
82 hcontent
=`qualify_address "$hcontent"`
83 line
="$hname:$hcontent"$
'\r'
91 sendEmail
-f "$envelope_sender" -t "${recipient[@]}" \
92 -o message-format
=raw
-o message-file
=- \
93 -s "${SMTP_SERVER:-localhost:25}" \
97 if [ $get_recipients_from_headers = yes ]
102 recipient
+=(`echo "$raw_email" | auto_qualify_recipients | mail-extract-raw-headers To Cc Bcc | mail-extract-addresses`)
104 if [ -n "$SENDMAIL_DEBUG" ]
106 warnx
"detected recipients: ${recipient[@]}"
108 echo "$raw_email" | call_sendEmail