Browse Source

Plan 9 from Bell Labs 2009-05-19

David du Colombier 15 years ago
parent
commit
92c7ed8f9d

+ 19 - 0
mail/lib/gone.fishing

@@ -0,0 +1,19 @@
+#!/bin/rc
+# gone.fishing local!$user /mail/box/$user/mbox - vacation responder
+#	as pipeto script
+
+# standard library.  saves the message on standard input in $TMP.msg and
+# parses it into /mail/fs/mbox/1.
+. /mail/lib/pipeto.lib $*
+
+{cat $TMP.msg; echo} >>/mail/box/$USER/gone.mail
+
+message=/mail/box/$USER/gone.msg
+if (! test -e $message)
+	message=/mail/lib/gone.msg
+
+MAILTO=`{cat $D/replyto}
+grep '^'$"MAILTO'$' /mail/box/$USER/gone.addrs >/dev/null >[2=1] || {
+	echo $MAILTO >>/mail/box/$USER/gone.addrs
+	mail $MAILTO <$message
+}

+ 6 - 0
mail/lib/gone.msg

@@ -0,0 +1,6 @@
+subject: away from my computer
+
+This is a recorded message.  I am currently out of contact with my
+computer system.  Your message to me has been saved and will be
+read upon my return.  This is the last time you will receive this
+message during my absence.  Thank you.

+ 15 - 1
mail/lib/pipeto.lib

@@ -26,6 +26,19 @@ fn log {
 		echo `{date} $* >>/mail/box/$USER/_log >[2]/dev/null
 }
 
+fn gonefishing {
+	if (test -e gone.fishing) {
+		MAILTO=`{cat $D/replyto}
+		grep '^'$"MAILTO'$' gone.addrs >/dev/null >[2=1] || {
+			echo $MAILTO >>gone.addrs
+			message=gone.msg
+			if (! test -e $message)
+				message=/mail/lib/gone.msg
+			mail $MAILTO <$message
+		}
+	}
+}
+
 # deliver mail to a local file
 fn spool {
 	if(~ $#* 0)
@@ -33,6 +46,7 @@ fn spool {
 	if not
 		_mbox=$1
 	$BIN/deliver $RECIP $D/from $_mbox < $D/raw || exit $status
+	gonefishing
 }
 
 # spool but change the subject line to note spam
@@ -48,9 +62,9 @@ fn spool-tagged-spam {
 		echo
 		cat $D/rawbody
 	} | $BIN/deliver $RECIP $D/from $_mbox || exit $status
+	gonefishing
 }
 
-
 # forward mail to a list of addresses
 fn forward {
 	upasname=`{awk '{print $2}' $D/unixheader} cat $D/raw | upas/send $* || exit $status

+ 15 - 0
rc/bin/go.fishing

@@ -0,0 +1,15 @@
+#!/bin/rc
+# go.fishing - set up vacation responder
+rfork e
+
+cd /mail/box/$user
+if (test -e gone.fishing) {
+	echo $0: /mail/box/$user/gone.fishing already exists >[1=2]
+	exit 'already fishing'
+}
+
+>gone.addrs
+chmod -a gone.addrs
+>gone.addrs
+chmod +arw gone.addrs
+>>gone.fishing

+ 62 - 5
sys/man/1/mail

@@ -1,11 +1,13 @@
 .TH MAIL 1
 .SH NAME
-mail \-  mail and mailboxes
+mail, go.fishing \- mail and mailboxes
 .SH SYNOPSIS
 .B mail
 [
 .I arg ...
 ]
+.PP
+.B go.fishing
 .SH DESCRIPTION
 .PP
 Mail is a shell script that invokes
@@ -54,13 +56,49 @@ The file is run as user
 .BR none .
 Its two arguments are the 
 with arguments of the destination address
-(e.g.
+(e.g.,
 .BR local!gremlin )
 and the user's mail box path
-(e.g.
+(e.g.,
 .BR /mail/box/gremlin/mbox )
+.SS Auto-answer
+.PP
+To use 
+.I mail
+as an answering machine while you are away,
+run
+.IR go.fishing ,
+which will create
+.B /mail/box/$user/gone.fishing
+as a flag for
+.B pipeto
+processing,
+and truncate
+.BR /mail/box/$user/gone.addrs .
+Any existing
+.B pipeto
+file that uses
+.B /mail/lib/pipeto.lib
+will invoke the
+.I gone.fishing
+machinery when it calls
+.B spool
+or
+.BR spool-tagged-spam .
+.PP
+If
+.B /mail/box/$user/gone.msg
+exists, it
+will be sent (just once) to everyone who
+sends you mail;
+if not,
+.B /mail/lib/gone.msg
+will be sent.
+Upon your return, remove
+.B /mail/box/$user/gone.fishing
+to stop automatic responses.
 .SH FILES
-.TF /mail/box/*/dead.letter
+.TF /mail/box/$user/gone.fishing
 .TP
 .B /sys/log/mail
 mail log file
@@ -86,9 +124,28 @@ mutual exclusion lock for altering mbox
 .B /lib/face/48x48x?
 directories of icons for
 .I seemail
-.SH SOURCE
 .TP
+.B /mail/lib/pipeto.lib
+helper functions for pipeto files
+.TP
+.B /mail/lib/gone.msg
+default vacation message
+.TP
+.B /mail/lib/gone.fishing
+auto-responder as
+.I pipeto
+script
+.TP
+.B /mail/box/$user/gone.fishing
+flag to active gone processing
+.TP
+.B /mail/box/$user/gone.addrs
+list of senders answered by
+.I gone.fishing
+.SH SOURCE
 .B /rc/bin/mail
+.br
+.B /rc/bin/go.fishing
 .SH "SEE ALSO"
 .IR aliasmail (8),
 .IR faces (1),

+ 15 - 0
sys/src/cmd/upas/misc/go.fishing

@@ -0,0 +1,15 @@
+#!/bin/rc
+# go.fishing - set up vacation responder
+rfork e
+
+cd /mail/box/$user
+if (test -e gone.fishing) {
+	echo $0: /mail/box/$user/gone.fishing already exists >[1=2]
+	exit 'already fishing'
+}
+
+>gone.addrs
+chmod -a gone.addrs
+>gone.addrs
+chmod +arw gone.addrs
+>>gone.fishing

+ 18 - 8
sys/src/cmd/upas/misc/gone.fishing

@@ -1,9 +1,19 @@
-#!/bin/sh
-PATH=/bin:/usr/bin
-message=${1-/usr/lib/upas/gone.msg}
-return=`sed '2,$s/^From[ 	]/>&/'|tee -a $HOME/gone.mail|sed -n '1s/^From[ 	]\([^ 	]*\)[ 	].*$/\1/p'`
-echo '' >>$HOME/gone.mail
-grep "^$return" $HOME/gone.addrs >/dev/null 2>/dev/null || {
-	echo $return >>$HOME/gone.addrs
-	mail $return < $message
+#!/bin/rc
+# gone.fishing local!$user /mail/box/$user/mbox - vacation responder
+#	as pipeto script
+
+# standard library.  saves the message on standard input in $TMP.msg and
+# parses it into /mail/fs/mbox/1.
+. /mail/lib/pipeto.lib $*
+
+{cat $TMP.msg; echo} >>/mail/box/$USER/gone.mail
+
+message=/mail/box/$USER/gone.msg
+if (! test -e $message)
+	message=/mail/lib/gone.msg
+
+MAILTO=`{cat $D/replyto}
+grep '^'$"MAILTO'$' /mail/box/$USER/gone.addrs >/dev/null >[2=1] || {
+	echo $MAILTO >>/mail/box/$USER/gone.addrs
+	mail $MAILTO <$message
 }

+ 2 - 0
sys/src/cmd/upas/misc/gone.msg

@@ -1,3 +1,5 @@
+subject: away from my computer
+
 This is a recorded message.  I am currently out of contact with my
 computer system.  Your message to me has been saved and will be
 read upon my return.  This is the last time you will receive this

+ 0 - 0
sys/src/cmd/upas/misc/mail.rc → sys/src/cmd/upas/misc/mail


+ 13 - 17
sys/src/cmd/upas/misc/mkfile

@@ -1,36 +1,32 @@
+RCFILES=mail\
+	go.fishing\
 
-RCFILES=mail.rc\
-
-all:Q:
+all:VQ:
 	;
 
-installall:Q:	install
+installall:VQ:	install
 	;
 
-install:V:
-	cp mail.rc /rc/bin/mail
+install:V: mail go.fishing gone.msg gone.fishing
+	cp mail go.fishing /rc/bin
+	cp gone.msg gone.fishing /mail/lib
 
-safeinstall:V:
-	cp mail.rc /rc/bin/mail
+safeinstall:V: install
 
-safeinstallall:V:
-	cp mail.rc /rc/bin/mail
+safeinstallall:V: install
 
-clean:Q:
+clean:VQ:
 	;
 nuke:V:
-	rm /rc/bin/mail
+	;	# rm /rc/bin/^(mail gone.fishing)
 
 UPDATE=\
+	go.fishing\
 	gone.fishing\
 	gone.msg\
-	mail.c\
-	mail.rc\
-	mail.sh\
-	makefile\
+	mail\
 	mkfile\
 	namefiles\
-	omail.rc\
 	qmail\
 	remotemail\
 	rewrite\

+ 0 - 14
sys/src/cmd/upas/misc/omail.rc

@@ -1,14 +0,0 @@
-#!/bin/rc
-switch($#*){
-case 0
-	exec upas/edmail -m
-}
-
-switch($1){
-case -F* -m* -f* -r* -p* -e* -c* -D*
-	exec upas/edmail -m $*
-case '-#'* -a*
-	exec upas/sendmail $*
-case *
-	exec upas/sendmail $*
-}

+ 9 - 0
sys/src/cmd/upas/misc/unix/gone.fishing.sh

@@ -0,0 +1,9 @@
+#!/bin/sh
+PATH=/bin:/usr/bin
+message=${1-/usr/lib/upas/gone.msg}
+return=`sed '2,$s/^From[ 	]/>&/'|tee -a $HOME/gone.mail|sed -n '1s/^From[ 	]\([^ 	]*\)[ 	].*$/\1/p'`
+echo '' >>$HOME/gone.mail
+grep "^$return" $HOME/gone.addrs >/dev/null 2>/dev/null || {
+	echo $return >>$HOME/gone.addrs
+	mail $return < $message
+}

+ 0 - 0
sys/src/cmd/upas/misc/mail.c → sys/src/cmd/upas/misc/unix/mail.c


+ 0 - 0
sys/src/cmd/upas/misc/mail.sh → sys/src/cmd/upas/misc/unix/mail.sh


+ 0 - 0
sys/src/cmd/upas/misc/makefile → sys/src/cmd/upas/misc/unix/makefile