9front: Setting up sending mail using multiple source e-mail (alias) addresses

Mail(1) was recently rewritten, and provides thread view and different presentation formats for mailboxes. One thing that I have tried to setup up before, but was done a bit circuitously, was sending e-mail using aliases. I have different e-mail addresses, and most go through one smtp server. With a few tweaks, mail can be sent from the address that received the message, and if not fall back to a default.

upasname= and marshal override

Using upasname when calling marshal(1) specifies the sender, setting up theenvelope and 'From:' name. Since I'm using a remote SMTP server and not running one locally, this is then used by /mail/lib/remotemail to determine which SMTP server to connect to. We're going to use that to our advantage, and also use binding to do some jiggering before upas/marshal really gets ahold of the message:

#!/bin/rc
# This is a drop-in replacement for marshal to support multiple
# reply addresses.  Start it before starting acme.

if (! test -x /env/marshal) {
	>[1=2] {
		echo no /env/marshal found, creating
		touch /env/marshal
		bind /bin/upas/marshal /env/marshal
		bind $0 /bin/upas/marshal
	}
	exit 'no /env/marshal found'
}
if (~ $2 -R)
	cd $3
if (~ $4 -R)
	cd $5
if (test -e rawheader){
fornames=`{awk '/\tfor <(.*)>/{ gsub("[<>;]", "", $2); print $2 }' <rawheader}
aliasnames=`{cat $home/lib/upas/fromfile | awk '{print $1}'}
for(forn in $fornames)
	for(aliasn in $aliasnames)
		if(~ $forn $aliasn)
			upasname=$aliasn