Plan 9 from Bell Labs’s /usr/web/sources/contrib/maht/rc/pipefrom

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

rfork e

# collect upas/send options
options=()
while (! ~ $#* 0 && ~ $1 -*) {
	options=($options $1);
	shift
}

dests=() # replace destination addresses
while (! ~ $#* 0) {
	a=`{awk '$1=="'^$1^'" { print $2 } ' $home/lib/outgoing_aliases_to}
	if(~ $#a 0)
		dests=($dests $1);
	if not 
		dests=($dests $a)
	shift
}

if(~ $#dests 1)
	cache = /dev/null
if not
	cache = /tmp/cache

fn out {
	while(r=`{read} && ! ~ $#r 0) {
		if(~ $r From:*)
			echo From: $upasname
		if not
			echo $r
	}
	cat 
}

for(d in $dests) {
	upasname=`{awk ' $1=="'^$d^'" { print $2 } ' $home/lib/outgoing_aliases_from}
	if(~ $#upasname 0)
		upasname=$user
	if(test -s $cache) # format our copy
		out < $cache | upas/send $options $d
	if not # copy and format stdin
		tee $cache | out |  upas/send $options $d
}
rm -f $cache


###########
# Example
# % cat $home/lib/outgoing_aliases_to
# 9fans [email protected]
#
# % cat $home/lib/outgoing_aliases_from
# [email protected] [email protected]
#
# echo 'Hi from maht' | mail -s 'Hello 9fans' 9fans
#
# will send [email protected] the email from [email protected]
#
#
#

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].