Commit Diff


commit - e4d832222ba5519db94c7512c1fb82bd32491120
commit + b5f65921f346e6b4335f77e457ac5bcae0ab9d67
blob - f50c348ab07a49e6da41b215e2de6f7ba1d44315
blob + 626be975595ac37d53597a75a827c99d7ca62a1e
--- src/cmd/upas/alias/aliasmail.c
+++ src/cmd/upas/alias/aliasmail.c
@@ -39,11 +39,10 @@ main(int argc, char *argv[])
 		namefiles = ARGF();
 		break;
 	} ARGEND
-	if (chdir(unsharp(UPASLIB)) < 0) {
-		perror("translate(chdir):");
-		exit9(1);
-	}
 
+	if (chdir(UPASLIB) < 0)
+		sysfatal("aliasmail chdir %s: %r", UPASLIB);
+
 	/* get environmental info */
 	names = sysnames_read();
 	files = getdbfiles();
blob - 46695efd8e5193db3a23d16f4a5142e9a0aa5081
blob + 80142deea50ad98ee6ff45a6dcad7e7444976128
--- src/cmd/upas/bayes/dfa.c
+++ src/cmd/upas/bayes/dfa.c
@@ -3,7 +3,7 @@
 #include <bin.h>
 #include <bio.h>
 #include <regexp.h>
-#include "/sys/src/libregexp/regcomp.h"
+#include "../../../libregexp/regcomp.h"
 #include "dfa.h"
 
 void rdump(Reprog*);
@@ -140,19 +140,19 @@ followempty(Deter *d, uchar *bits, int bol, int eol)
 			switch(i->type){
 			case RBRA:
 			case LBRA:
-				again |= add(i->next - d->p->firstinst, bits, k);
+				again |= add(i->u2.next - d->p->firstinst, bits, k);
 				break;
 			case OR:
-				again |= add(i->left - d->p->firstinst, bits, k);
-				again |= add(i->right - d->p->firstinst, bits, k);
+				again |= add(i->u2.left - d->p->firstinst, bits, k);
+				again |= add(i->u1.right - d->p->firstinst, bits, k);
 				break;
 			case BOL:
 				if(bol)
-					again |= add(i->next - d->p->firstinst, bits, k);
+					again |= add(i->u2.next - d->p->firstinst, bits, k);
 				break;
 			case EOL:
 				if(eol)
-					again |= add(i->next - d->p->firstinst, bits, k);
+					again |= add(i->u2.next - d->p->firstinst, bits, k);
 				break;
 			}
 		}
@@ -209,27 +209,27 @@ transition(Deter *d, Reiset *s, Rune r, uint eol)
 			longjmp(d->kaboom, 1);
 
 		case RUNE:
-			if(r == i->r)
-				bits[i->next - inst0] = 1;
+			if(r == i->u1.r)
+				bits[i->u2.next - inst0] = 1;
 			break;
 		case ANY:
 			if(r != L'\n')
-				bits[i->next - inst0] = 1;
+				bits[i->u2.next - inst0] = 1;
 			break;
 		case ANYNL:
-			bits[i->next - inst0] = 1;
+			bits[i->u2.next - inst0] = 1;
 			break;
 		case NCCLASS:
 			if(r == L'\n')
 				break;
 			/* fall through */
 		case CCLASS:
-			ep = i->cp->end;
-			for(rp = i->cp->spans; rp < ep; rp += 2)
+			ep = i->u1.cp->end;
+			for(rp = i->u1.cp->spans; rp < ep; rp += 2)
 				if(rp[0] <= r && r <= rp[1])
 					break;
 			if((rp < ep) ^! (i->type == CCLASS))
-				bits[i->next - inst0] = 1;
+				bits[i->u2.next - inst0] = 1;
 			break;
 		case END:
 			break;
@@ -290,9 +290,9 @@ findchars(Deter *d, Reprog *p)
 			set(d, tab, L'\n'+1);
 			break;
 		case RUNE:
-			set(d, tab, i->r-1);
-			set(d, tab, i->r);
-			set(d, tab, i->r+1);
+			set(d, tab, i->u1.r-1);
+			set(d, tab, i->u1.r);
+			set(d, tab, i->u1.r+1);
 			break;
 		case NCCLASS:
 			set(d, tab, L'\n'-1);
@@ -300,8 +300,8 @@ findchars(Deter *d, Reprog *p)
 			set(d, tab, L'\n'+1);
 			/* fall through */
 		case CCLASS:
-			ep = i->cp->end;
-			for(rp = i->cp->spans; rp < ep; rp += 2){
+			ep = i->u1.cp->end;
+			for(rp = i->u1.cp->spans; rp < ep; rp += 2){
 				set(d, tab, rp[0]-1);
 				set(d, tab, rp[0]);
 				set(d, tab, rp[1]);
blob - c0c546e73a8405ffe5fe595818764a55458e655c
blob + 1479995b1476c926faee580529e9ab5fe2c1bb27
--- src/cmd/upas/bayes/mkfile
+++ src/cmd/upas/bayes/mkfile
@@ -1,18 +1,18 @@
-</$objtype/mkfile
+<$PLAN9/src/mkhdr
 
 TARG=addhash bayes msgtok
 HFILES=
 OFILES=
 LIB=
 
-BIN=/$objtype/bin/upas
-</sys/src/cmd/mkmany
+BIN=$BIN/upas
+<$PLAN9/src/mkmany
 
 # msg tokenizer
 $O.regen: regcomp.$O dfa.$O
 dfa.$O regcomp.$O regen.$O: dfa.h
 
-/mail/lib/classify.re: $O.regen
+$PLAN9/mail/lib/classify.re: $O.regen
 	if(~ $cputype $objtype)
 		$O.regen >x && cp x $target
 
blob - 7c450546983f3c004c43edf9fd7eae6563fa2728
blob + 122e0c64606aa22a1e02bca5c3c83d8abbba46d0
--- src/cmd/upas/bayes/msgtok.c
+++ src/cmd/upas/bayes/msgtok.c
@@ -13,7 +13,7 @@
 
 void buildre(Dreprog*[3]);
 int debug;
-char *refile = "/mail/lib/classify.re";
+char *refile = "#9/mail/lib/classify.re";
 int maxtoklen = 20;
 int trim(char*);
 
@@ -35,6 +35,7 @@ main(int argc, char **argv)
 	char msg[1024+1];
 	char buf[1024];
 
+	refile = unsharp(refile);
 	buildre(re);
 	ARGBEGIN{
 	case 'D':
blob - 1b5aa4569be8d2af6d9ff8aff90721ea6052fefe (mode 644)
blob + /dev/null
--- src/cmd/upas/common/become.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "common.h"
-#include <auth.h>
-#include <ndb.h>
-
-/*
- *  become powerless user
- */
-int
-become(char **cmd, char *who)
-{
-	int fd;
-
-	USED(cmd);
-	if(strcmp(who, "none") == 0) {
-		fd = open("#c/user", OWRITE);
-		if(fd < 0 || write(fd, "none", strlen("none")) < 0) {
-			werrstr("can't become none");
-			return -1;
-		}
-		close(fd);
-		// jpc if(newns("none", 0)) {
-		// jpc 	werrstr("can't set new namespace");
-		// jpc	return -1;
-		// jpc }
-	}
-	return 0;
-}
-
blob - a9d4f0f811341c6312607af5bf9465778440a267
blob + cf56c8693fb4e850f3dda1ffcbf78a5fea1f8fb1
--- src/cmd/upas/common/libsys.c
+++ src/cmd/upas/common/libsys.c
@@ -454,6 +454,7 @@ sysnames_read(void)
 	if(namev)
 		return namev;
 
+/* XXX */
 	/* free(csgetvalue(0, "sys", alt_sysname_read(), "dom", &t));  jpc */
 	db = ndbopen(unsharp("#9/ndb/local"));
 	free(ndbgetvalue(db, &s, "sys", sysname(),"dom", &t));
blob - 33903708a4f6d40e97464c6cce657ef590de8c46
blob + 3b129317f0743d44b1df140c53ef68ab55f11084
--- src/cmd/upas/filterkit/deliver.c
+++ src/cmd/upas/filterkit/deliver.c
@@ -1,11 +1,12 @@
 #include "dat.h"
+#include <thread.h>
 #include "common.h"
 
 void
 usage(void)
 {
 	fprint(2, "usage: %s recipient fromaddr-file mbox\n", argv0);
-	exits("usage");
+	threadexitsall("usage");
 }
 
 void
blob - 6c23dcc19c19a6f1a427af2a9e345506e4f93c2d
blob + 1913c6ded4dc8ef2c19043a4bb0fbcc4598e317f
--- src/cmd/upas/filterkit/list.c
+++ src/cmd/upas/filterkit/list.c
@@ -2,7 +2,7 @@
 #include <libc.h>
 #include <regexp.h>
 #include <libsec.h>
-#include <String.h>
+#include <libString.h>
 #include <bio.h>
 #include "dat.h"
 
@@ -188,8 +188,9 @@ readpatterns(char *path)
 }
 
 /* fuck, shit, bugger, damn */
-void regerror(char*)
+void regerror(char *err)
 {
+	USED(err);
 }
 
 /*
blob - c077d56411bd1392db7b4aee235e33aea2b9cd61
blob + 880ede1e2c8a2ecdb230960240b51827a39dc952
--- src/cmd/upas/filterkit/mkfile
+++ src/cmd/upas/filterkit/mkfile
@@ -1,21 +1,14 @@
-</$objtype/mkfile
+<$PLAN9/src/mkhdr
 
 TARG=\
 	token\
 	list\
 	deliver\
 
-LIB=../common/libcommon.a$O\
-
-BIN=/$objtype/bin/upas
+LIB=../common/libcommon.a
 OFILES=readaddrs.$O
-UPDATE=\
-	mkfile\
-	${TARG:%=%.c}\
-	pipeto.sample\
-	pipefrom.sample\
-	pipeto.sample-hold\
 
-</sys/src/cmd/mkmany
-CFLAGS=$CFLAGS -I../common
+BIN=$BIN/upas
+<$PLAN9/src/mkmany
 
+CFLAGS=$CFLAGS -I../common
blob - 8fbcda668d5b6a865c5b7d870b1a9d19e4cde22a
blob + 4e91e261a9159cbc4ad6c6eb1ead6835afb61042
--- src/cmd/upas/filterkit/token.c
+++ src/cmd/upas/filterkit/token.c
@@ -1,7 +1,7 @@
 #include <u.h>
 #include <libc.h>
 #include <libsec.h>
-#include <String.h>
+#include <libString.h>
 #include "dat.h"
 
 void
blob - cfc186c0a8dabd89c7a5a2f399fb4b470414d93b
blob + e5c75f7fd40d52186ee7840d41fab876e5ab33d5
--- src/cmd/upas/marshal/marshal.c
+++ src/cmd/upas/marshal/marshal.c
@@ -1,6 +1,8 @@
 #include "common.h"
 #include <ctype.h>
 
+#define inline _inline
+
 typedef struct Attach Attach;
 typedef struct Alias Alias;
 typedef struct Addr Addr;
@@ -10,7 +12,7 @@ struct Attach {
 	Attach	*next;
 	char	*path;
 	char	*type;
-	int	tinline;
+	int	inline;
 	Ctype	*ctype;
 };
 
@@ -684,7 +686,7 @@ attachment(Attach *a, Biobuf *out)
 	if(strcmp(a->type, "text/plain") != 0)
 		Bprint(out, "Content-Type: %s\n", a->type);
 
-	if(a->tinline){
+	if(a->inline){
 		Bprint(out, "Content-Disposition: inline\n");
 	} else {
 		p = strrchr(a->path, '/');
@@ -811,7 +813,7 @@ printinreplyto(Biobuf *out, char *dir)
 }
 
 Attach*
-mkattach(char *file, char *type, int tinline)
+mkattach(char *file, char *type, int inline)
 {
 	Ctype *c;
 	Attach *a;
@@ -829,7 +831,7 @@ mkattach(char *file, char *type, int tinline)
 	a->path = file;
 	a->next = nil;
 	a->type = type;
-	a->tinline = tinline;
+	a->inline = inline;
 	a->ctype = nil;
 	if(type != nil){
 		for(c = ctype; ; c++)
@@ -1067,7 +1069,7 @@ sendmail(Addr *to, Addr *cc, int *pid, char *rcvr)
 
 	if(pipe(pfd) < 0)
 		fatal("%r");
-	switch(*pid = rfork(RFFDG|RFPROC)){   // jpc - removed |RFENVG|RFREND|
+	switch(*pid = fork()){
 	case -1:
 		fatal("%r");
 		break;
@@ -1105,7 +1107,7 @@ sendmail(Addr *to, Addr *cc, int *pid, char *rcvr)
 
 		cmd = mboxpath("pipefrom", login, s_new(), 0);
 		exec(s_to_c(cmd), av);
-		exec(unsharp("#9/bin/myupassend"), av);
+		exec("myupassend", av);
 		exec(unsharp("#9/bin/upas/send"), av);
 		fatal("execing: %r");
 		break;
@@ -1130,6 +1132,7 @@ pgpfilter(int *pid, int fd, int pgpflag)
 	v = av = emalloc(sizeof(char*)*8);
 	ac = 0;
 	v[ac++] = "pgp";
+	v[ac++] = "-fat";		/* operate as a filter, generate text */
 	if(pgpflag & PGPsign)
 		v[ac++] = "-s";
 	if(pgpflag & PGPencrypt)
@@ -1148,8 +1151,10 @@ pgpfilter(int *pid, int fd, int pgpflag)
 		close(pfd[0]);
 		dup(fd, 1);
 		close(fd);
+		/* add newline to avoid confusing pgp output with 822 headers */
+		write(1, "\n", 1);
 
-		exec("/bin/upas/pgp", av);
+		exec("pgp", av);
 		fatal("execing: %r");
 		break;
 	default:
@@ -1314,7 +1319,6 @@ readaliases(void)
 	Alias *a, **l, *first;
 	Addr *addr, **al;
 	String *file, *line, *token;
-	// jpc - static int already;
 	Sinstack *sp;
 
 	first = nil;
@@ -1747,7 +1751,7 @@ readmimetypes(void)
 		mimetypes[0].ext = "";
 	}
 
-	b = Bopen(unsharp("#9/sys/lib/mimetype"), OREAD);
+	b = Bopen(unsharp("#9/lib/mimetype"), OREAD);
 	if(b == nil)
 		return;
 	for(;;){
blob - 6913d743e1a9b52044800494e6d15e8d8518240f
blob + b079e2d816242f77cec6f1ee33bcba2bafab05a0
--- src/cmd/upas/misc/mail.rc
+++ src/cmd/upas/misc/mail.rc
@@ -1,4 +1,4 @@
-#!/bin/rc
+#!/usr/local/plan9/bin/rc
 switch($#*){
 case 0
 	exec upas/nedmail
blob - 0bbd8a5ab355647dab620b7060a3834d95b782b9
blob + eeb76965b5fe849dd24680031495db743218f9db
--- src/cmd/upas/misc/mkfile
+++ src/cmd/upas/misc/mkfile
@@ -2,24 +2,19 @@
 RCFILES=mail.rc\
 
 all:Q:
-	;
+	#
 
 installall:Q:	install
-	;
+	#
 
-install:V:
-	cp mail.rc /rc/bin/mail
+install safeinstall safeinstallall:V:
+	cp mail.rc $PLAN9/bin/mail
 
-safeinstall:V:
-	cp mail.rc /rc/bin/mail
-
-safeinstallall:V:
-	cp mail.rc /rc/bin/mail
-
 clean:Q:
-	;
+	#
+
 nuke:V:
-	rm /rc/bin/mail
+	rm $PLAN9/bin/mail
 
 UPDATE=\
 	gone.fishing\
blob - ed64f38c439ca03cbf5773d05b430a46c3d288bf (mode 755)
blob + /dev/null
--- src/cmd/upas/misc/omail.rc
+++ /dev/null
@@ -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 $*
-}
blob - 77a3d228ad1413f28264fb31486354360ab7c1b1
blob + de2f03617e432340db27ad2be6eb66e3d35c800f
--- src/cmd/upas/misc/qmail
+++ src/cmd/upas/misc/qmail
@@ -1,6 +1,6 @@
-#!/bin/rc
+#!/usr/local/plan9/bin/rc
 sender=$1
 shift
 addr=$1
 shift
-qer /mail/queue mail $sender $addr $* && runq /mail/queue /mail/lib/remotemail
+qer $PLAN9/mail/queue mail $sender $addr $* && runq $PLAN9/mail/queue $PLAN9/mail/lib/remotemail
blob - 312ee58748d80bde6e815aab91935cdf4417ee03
blob + 9059d3f4aabc1a25b0c2f7cab76d17f7f30b0c00
--- src/cmd/upas/misc/remotemail
+++ src/cmd/upas/misc/remotemail
@@ -1,7 +1,7 @@
-#!/bin/rc
+#!/usr/local/plan9/bin/rc
 shift
 sender=$1
 shift
 addr=$1
 shift
-/bin/upas/smtp -g research.research.bell-labs.com $addr $sender $*
+upas/smtp -g yourgateway $addr $sender $*
blob - fd724eb1e76497bba88f7f448d4c5b7da379e864
blob + a4d1719d767a15c5f17db37b00cb061e70901024
--- src/cmd/upas/misc/rewrite
+++ src/cmd/upas/misc/rewrite
@@ -2,8 +2,8 @@
 pOsTmAsTeR	alias		postmaster
 
 # local mail
-[^!@]+		translate	"/bin/upas/aliasmail '&'"
-local!(.*)	>>		/mail/box/\1/mbox
+[^!@]+		translate	"upas/aliasmail '&'"
+local!(.*)	>>		$PLAN9/mail/box/\1/mbox
 \l!(.*)		alias		\1
 (helix|helix.bell-labs.com)!(.*)	alias		\2
 
@@ -17,4 +17,4 @@ local!(.*)	>>		/mail/box/\1/mbox
 ([^@]+)@([^@]+)		alias	\2!\1
 
 # /mail/lib/remotemail will take care of gating to systems we don't know
-([^!]*)!(.*) 		| 		"/mail/lib/qmail '\s' 'net!\1'" "'\2'"
+([^!]*)!(.*) 		| 		"$PLAN9/mail/lib/qmail '\s' 'net!\1'" "'\2'"
blob - 5142e56f45d3dd97bee0646cc3992839f0596585
blob + 1a3841087d18b1b34eb2ec9588ab8dff6f711540
--- src/cmd/upas/ml/mkfile
+++ src/cmd/upas/ml/mkfile
@@ -1,4 +1,4 @@
-</$objtype/mkfile
+<$PLAN9/src/mkhdr
 
 TARG=ml\
 	mlowner\
@@ -16,25 +16,17 @@ UHFILES= ../common/common.h\
 HFILES=$UHFILES\
 	../smtp/y.tab.h\
 
-LIB=../common/libcommon.a$O\
+LIB=../common/libcommon.a
 
-BIN=/$objtype/bin/upas
-
-UPDATE=\
-	mkfile\
-	$UHFILES\
-	${TARG:%=%.c}\
-	${OFILES:%.$O=%.c}\
-	../smtp/rfc822.y\
-
-</sys/src/cmd/mkmany
+BIN=$BIN/upas
+<$PLAN9/src/mkmany
 CFLAGS=$CFLAGS -I../common
 
 $O.ml: ../smtp/rfc822.tab.$O
 $O.mlowner: ../smtp/rfc822.tab.$O
 
 ../smtp/y.tab.h ../smtp/rfc822.tab.$O:
-	@{
+	(
 		cd ../smtp
 		mk rfc822.tab.$O
-	}
+	)
blob - 8372dc9d26410f16eeeee619c7f8fc3096f4f873
blob + 8dad05179af33e80574992f324d28b0613dd6d51
--- src/cmd/upas/ml/ml.c
+++ src/cmd/upas/ml/ml.c
@@ -35,7 +35,7 @@ main(int argc, char **argv)
 		break;
 	}ARGEND;
 
-	rfork(RFENVG|RFREND);
+	rfork(RFENVG);
 
 	if(argc < 2)
 		usage();
blob - a1d1b907e9d4233fe36355327fa3fabfe16fa936
blob + 758fc0a15aede4c7b2874cc53eb44e13170ba36f
--- src/cmd/upas/ml/mlmgr.c
+++ src/cmd/upas/ml/mlmgr.c
@@ -21,7 +21,7 @@ main(int argc, char **argv)
 	char *listname, *addr;
 	String *owner, *alfile;
 
-	rfork(RFENVG|RFREND);
+	rfork(RFENVG);
 
 	ARGBEGIN{
 	case 'c':
blob - 5bb98a298fdc03cc921558cace2fb1fd456f8b36
blob + 4ac46b868ef51d22530ca0478990d3865c302a59
--- src/cmd/upas/ml/mlowner.c
+++ src/cmd/upas/ml/mlowner.c
@@ -24,7 +24,7 @@ main(int argc, char **argv)
 	ARGBEGIN{
 	}ARGEND;
 
-	rfork(RFENVG|RFREND);
+	rfork(RFENVG);
 
 	if(argc < 2)
 		usage();
blob - b6ea720d1fccfce7245cf1d2560388a3c9d26d62
blob + eab9e2fcc943b026150e8bfa9985667d1f6d1e8b
--- src/cmd/upas/scanmail/common.c
+++ src/cmd/upas/scanmail/common.c
@@ -585,15 +585,15 @@ matchpat(Pattern *p, char *message, Resub *m)
 				if(c1 == spat->c1)
 				if(memcmp(s, spat->string, spat->len) == 0)
 				if(!isalt(message, spat->alt)){
-					m->sp = s;
-					m->ep = s + spat->len;
+					m->s.sp = s;
+					m->e.ep = s + spat->len;
 					return 1;
 				}
 			}
 		}
 		return 0;
 	}
-	m->sp = m->ep = 0;
+	m->s.sp = m->e.ep = 0;
 	if(regexec(p->pat, message, m, 1) == 0)
 		return 0;
 	if(isalt(message, p->alt))
@@ -608,23 +608,23 @@ xprint(int fd, char *type, Resub *m)
 	char *p, *q;
 	int i;
 
-	if(m->sp == 0 || m->ep == 0)
+	if(m->s.sp == 0 || m->e.ep == 0)
 		return;
 
 		/* back up approx 30 characters to whitespace */
-	for(p = m->sp, i = 0; *p && i < 30; i++, p--)
+	for(p = m->s.sp, i = 0; *p && i < 30; i++, p--)
 			;
 	while(*p && *p != ' ')
 		p--;
 	p++;
 
 		/* grab about 30 more chars beyond the end of the match */
-	for(q = m->ep, i = 0; *q && i < 30; i++, q++)
+	for(q = m->e.ep, i = 0; *q && i < 30; i++, q++)
 			;
 	while(*q && *q != ' ')
 		q++;
 
-	fprint(fd, "%s %.*s~%.*s~%.*s\n", type, (int)(m->sp-p), p, (int)(m->ep-m->sp), m->sp, (int)(q-m->ep), m->ep);
+	fprint(fd, "%s %.*s~%.*s~%.*s\n", type, (int)(m->s.sp-p), p, (int)(m->e.ep-m->s.sp), m->s.sp, (int)(q-m->e.ep), m->e.ep);
 }
 
 enum {
blob - 5f0db8556d50d27e5ac57aebab2a7dae82927b3a
blob + 630150e65e29115cab96885d67d548d890bd6551
--- src/cmd/upas/scanmail/mkfile
+++ src/cmd/upas/scanmail/mkfile
@@ -1,4 +1,4 @@
-</$objtype/mkfile
+<$PLAN9/src/mkhdr
 
 TARG=scanmail\
 	testscan
@@ -8,17 +8,11 @@ OFILES=	common.$O
 HFILES=	spam.h\
 	../common/sys.h\
 
-LIB=	../common/libcommon.a$O\
+LIB=	../common/libcommon.a
 
-BIN=/$objtype/bin/upas
-UPDATE=\
-	mkfile\
-	$HFILES\
-	${OFILES:%.$O=%.c}\
-	${TARG:%=%.c}\
-
-</sys/src/cmd/mkmany
+BIN=$BIN/upas
+<$PLAN9/src/mkmany
 CFLAGS=$CFLAGS -I../common
 
 scanmail.$O:	scanmail.c
-	$CC $CFLAGS -D'SPOOL="/mail"' scanmail.c
+	$CC $CFLAGS -D'SPOOL="'$PLAN9'/mail"' scanmail.c
blob - 444bbcdd20065d1b2eb19bd2b114b345b34f05a8
blob + b99d9485f26a7d1f0c59d61a9b26ad6f40028806
--- src/cmd/upas/scanmail/scanmail.c
+++ src/cmd/upas/scanmail/scanmail.c
@@ -313,7 +313,7 @@ matcher(char *action, Pattern *p, char *message, Resub
 	char *cp;
 	String *s;
 
-	for(cp = message; matchpat(p, cp, m); cp = m->ep){
+	for(cp = message; matchpat(p, cp, m); cp = m->e.ep){
 		switch(p->action){
 		case SaveLine:
 			if(vflag)
@@ -340,12 +340,12 @@ matcher(char *action, Pattern *p, char *message, Resub
 		case Dump:
 			if(vflag)
 				xprint(2, action, m);
-			*(m->ep) = 0;
+			*m->e.ep = 0;
 			if(!tflag){
 				s = s_new();
 				s_append(s, sender);
 				s = unescapespecial(s);
-				syslog(0, "smtpd", "Dumped %s [%s] to %s", s_to_c(s), m->sp,
+				syslog(0, "smtpd", "Dumped %s [%s] to %s", s_to_c(s), m->s.sp,
 					s_to_c(s_restart(recips)));
 				s_free(s);
 			}
@@ -367,17 +367,17 @@ saveline(char *file, char *sender, Resub *rp)
 	int i, c;
 	Biobuf *bp;
 
-	if(rp->sp == 0 || rp->ep == 0)
+	if(rp->s.sp == 0 || rp->e.ep == 0)
 		return;
 		/* back up approx 20 characters to whitespace */
-	for(p = rp->sp, i = 0; *p && i < 20; i++, p--)
+	for(p = rp->s.sp, i = 0; *p && i < 20; i++, p--)
 			;
 	while(*p && *p != ' ')
 		p--;
 	p++;
 
 		/* grab about 20 more chars beyond the end of the match */
-	for(q = rp->ep, i = 0; *q && i < 20; i++, q++)
+	for(q = rp->e.ep, i = 0; *q && i < 20; i++, q++)
 			;
 	while(*q && *q != ' ')
 		q++;
blob - e5ea59ad5788f5bdcf96c0d9d316f5b1d14abe38
blob + 48cd4bbfe4649c5ab0078413ba37b4262d5e4587
--- src/cmd/upas/scanmail/testscan.c
+++ src/cmd/upas/scanmail/testscan.c
@@ -191,11 +191,11 @@ matchaction(Patterns *pp, char *message)
 	p = pp->strings;
 	ret = 0;
 	if(p)
-		for(cp = message; matcher(name, p, cp, m); cp = m[0].ep)
+		for(cp = message; matcher(name, p, cp, m); cp = m[0].e.ep)
 				ret++;
 
 	for(p = pp->regexps; p; p = p->next)
-		for(cp = message; matcher(name, p, cp, m); cp = m[0].ep)
+		for(cp = message; matcher(name, p, cp, m); cp = m[0].e.ep)
 				ret++;
 	return ret;
 }
blob - eab6160ca3a00cd874065781e3492c0905860bac
blob + 8cee34a0ef2a3a9a5ea6695b9a5d90c2b4022a5a
--- src/cmd/upas/send/message.c
+++ src/cmd/upas/send/message.c
@@ -143,7 +143,7 @@ getstring(Node *p)
 	return s;
 }
 
-#if 0 /* jpc */
+#if 0
 static char *fieldname[] =
 {
 [WORD-WORD]	"WORD",
@@ -172,7 +172,7 @@ static char *fieldname[] =
 [MAILER-WORD]	"MAILER",
 [BADTOKEN-WORD]	"BADTOKEN",
 };
-#endif /* jpc */
+#endif
 
 /* fix 822 addresses */
 static void
blob - a49fde1762c2aaf323fcda25732192a4f92e7247
blob + 937b318d662f148adcbf9133e7231d2f1197de31
--- src/cmd/upas/send/mkfile
+++ src/cmd/upas/send/mkfile
@@ -21,22 +21,13 @@ SMOBJ=main.$O\
 	gateway.$O\
 	cat_mail.$O\
 
-LIB=../common/libcommon.av\
-
 HFILES=send.h\
 	../common/common.h\
 	../common/sys.h\
 
-LIB=../common/libcommon.a\
+LIB=../common/libcommon.a
 
-BIN=$PLAN9/bin/upas
-UPDATE=\
-	mkfile\
-	$HFILES\
-	${UOFILES:%.$O=%.c}\
-	${SMOBJ:%.$O=%.c}\
-	${TARG:%=%.c}\
-
+BIN=$BIN/upas
 <$PLAN9/src/mkmany
 CFLAGS=$CFLAGS -I../common
 
@@ -46,7 +37,6 @@ $O.send: $SMOBJ $OFILES
 message.$O:	../smtp/y.tab.h
 
 ../smtp/y.tab.h ../smtp/rfc822.tab.$O: ../smtp/rfc822.y
-#	@{
-		cd ../smtp
-		mk rfc822.tab.$O
-#	}
+	cd ../smtp
+	mk rfc822.tab.$O
+
blob - 4f40b29338b9003991ee364bc2704feff8d202da
blob + 2feacbf21d6c0aa180fb16c59f26a8b37e6da002
--- src/cmd/upas/send/rewrite.c
+++ src/cmd/upas/send/rewrite.c
@@ -131,7 +131,7 @@ getrules(void)
 	String	*type;
 	String	*file;
 
-	file = abspath("rewrite", unsharp(UPASLIB), (String *)0);
+	file = abspath("rewrite", UPASLIB, (String *)0);
 	rfp = sysopen(s_to_c(file), "r", 0);
 	if(rfp == 0) {
 		rulep = 0;
@@ -168,7 +168,7 @@ findrule(String *addrp, int authorized)
 			continue;
 		memset(rp->subexp, 0, sizeof(rp->subexp));
 		if(debug)
-			print("matching %s aginst %s\n", s_to_c(addrp), rp->matchre->base);
+			fprint(2, "matching %s aginst %s\n", s_to_c(addrp), rp->matchre->base);
 		if(regexec(rp->program, s_to_c(addrp), rp->subexp, NSUBEXP))
 		if(s_to_c(addrp) == rp->subexp[0].s.sp)
 		if((s_to_c(addrp) + strlen(s_to_c(addrp))) == rp->subexp[0].e.ep)
@@ -203,15 +203,43 @@ rewrite(dest *dp, message *mp)
 	dp->repl2 = substitute(rp->repl2, rp->subexp, mp);
 	dp->status = rp->type;
 	if(debug){
-		print("\t->");
+		fprint(2, "\t->");
 		if(dp->repl1)
-			print("%s", s_to_c(dp->repl1));
+			fprint(2, "%s", s_to_c(dp->repl1));
 		if(dp->repl2)
-			print("%s", s_to_c(dp->repl2));
-		print("\n");
+			fprint(2, "%s", s_to_c(dp->repl2));
+		fprint(2, "\n");
 	}
 	s_free(lower);
 	return 0;
+}
+
+/* stolen from rc/lex.c */
+static int
+idchr(int c)
+{
+	return c>' ' && !strchr("!\"#$%&'()+,-./:;<=>?@[\\]^`{|}~", c);
+}
+
+static char*
+getrcvar(char* p, char** rv)
+{
+	char* p0;
+	char buf[128];
+	char* bufe;
+
+	*rv = 0;
+	p0=p;
+	bufe=buf+sizeof buf-1;
+	while(p<bufe && idchr(*p))
+		p++;
+
+	memcpy(buf, p0, p-p0);
+	buf[p-p0]=0;
+	*rv = getenv(buf);
+	if (debug)
+		fprint(2, "varsubst: %s → %s\n", buf, *rv);
+	return p;
 }
 
 static String *
@@ -264,11 +292,15 @@ substitute(String *source, Resub *subexp, message *mp)
 				s_putc(stp, *sp);
 				break;
 			}
-		} else if(*sp == '&') {				
+		} else if(*sp == '&') {			
 			if(subexp[0].s.sp != 0)
 				for (s = subexp[0].s.sp;
 				     s < subexp[0].e.ep; s++)
 					s_putc(stp, *s);
+		} else if(*sp == '$') {
+			sp = getrcvar(sp+1, &s);
+			s_append(stp, s);
+			free(s);
 		} else
 			s_putc(stp, *sp);
 		sp++;
blob - 915e688e3c5deb94b40dbc346901d743bee9cdb3
blob + a3a3f4d46f8f82c7ed3e7fbb185204abef6f1431
--- src/cmd/upas/smtp/greylist.c
+++ src/cmd/upas/smtp/greylist.c
@@ -23,7 +23,7 @@ typedef struct {
 enum {
 	Nonspammax = 14*60*60,  /* must call back within this time if real */
 };
-static char whitelist[] = "/mail/lib/whitelist";
+static char *whitelist = "#9/mail/lib/whitelist";
 
 /*
  * matches ip addresses or subnets in whitelist against nci->rsys.
@@ -40,11 +40,11 @@ onwhitelist(void)
 	uchar mask[IPaddrlen], addr[IPaddrlen], addrmasked[IPaddrlen];
 	Biobuf *wl;
 	static int beenhere;
-	static allzero[IPaddrlen];
 
 	if (!beenhere) {
 		beenhere = 1;
 		fmtinstall('I', eipfmt);
+		whitelist = unsharp(whitelist);
 	}
 
 	parseip(ip, nci->rsys);
@@ -219,8 +219,8 @@ isrcptrecent(char *rcpt)
 		user++;
 
 	/* check & try to update the grey list entry */
-	snprint(file, sizeof file, "/mail/grey/%s/%s/%s",
-		nci->lsys, nci->rsys, user);
+	snprint(file, sizeof file, "%s/mail/grey/%s/%s/%s",
+		get9root(), nci->lsys, nci->rsys, user);
 	memset(gsp, 0, sizeof *gsp);
 	addgreylist(file, gsp);
 
@@ -258,10 +258,7 @@ vfysenderhostok(void)
 
 		if (fd >= 0) {
 			seek(fd, 0, 2);			/* paranoia */
-			if ((fqdn = csgetvalue(nil, "ip", nci->rsys, "dom", nil)) != nil)
-				fprint(fd, "# %s\n%s\n\n", fqdn, nci->rsys);
-			else
-				fprint(fd, "# unknown\n%s\n\n", nci->rsys);
+			fprint(fd, "# %s\n%s\n\n", fqdn, nci->rsys);
 			close(fd);
 		}
 	} else {
blob - 722f1357b364678cf8dd2920c1e2a1ec7f52a53b
blob + c4c7e05332923c615743ef0c6e7d2da381621991
--- src/cmd/upas/smtp/mkfile
+++ src/cmd/upas/smtp/mkfile
@@ -1,12 +1,12 @@
 <$PLAN9/src/mkhdr
 
-TARG = # smtpd\
+TARG=\
 	smtp\
+	smtpd\
 
 OFILES=
 
-LIB=../common/libcommon.a\
-	$PLAN9/lib/libthread.a   # why do i have to explicitly put this?
+LIB=../common/libcommon.a
 
 HFILES=../common/common.h\
 	../common/sys.h\
@@ -27,7 +27,7 @@ UPDATE=\
 	${TARG:%=%.c}\
 
 <$PLAN9/src/mkmany
-CFLAGS=$CFLAGS -I../common -D'SPOOL="/mail"'
+CFLAGS=$CFLAGS -I../common -D'SPOOL="'$PLAN9'/mail"'
 
 $O.smtpd:	smtpd.tab.$O rmtdns.$O spam.$O rfc822.tab.$O greylist.$O
 $O.smtp:	rfc822.tab.$O mxdial.$O
@@ -37,7 +37,7 @@ smtpd.$O: 	smtpd.h
 smtp.$O to.$O: 	smtp.h
 
 smtpd.tab.c: smtpd.y smtpd.h
-	yacc -o xxx smtpd.y
+	9 yacc -o xxx smtpd.y
 	sed 's/yy/zz/g' < xxx > $target
 	rm xxx
 
@@ -47,8 +47,6 @@ rfc822.tab.c: rfc822.y smtp.h
 clean:V:
 	rm -f *.[$OS] [$OS].$TARG smtpd.tab.c rfc822.tab.c y.tab.? y.debug $TARG
 
-../common/libcommon.a$O:
-	@{ 	
-		cd ../common
-		mk
-	}
+../common/libcommon.a
+	cd ../common; mk
+
blob - aea5f2566f6e6992bec36461dc60fe655cf7c7d9
blob + 13f40ab540778efe7a33f481a7442fb2493880dd
--- src/cmd/upas/smtp/mxdial.c
+++ src/cmd/upas/smtp/mxdial.c
@@ -1,6 +1,7 @@
 #include "common.h"
 #include <ndb.h>
 #include "smtp.h"	/* to publish dial_string_parse */
+#include <ip.h>
 
 enum
 {
@@ -42,12 +43,18 @@ mxdial(char *addr, char *ddomain, char *gdomain)
 
 	/* try our mail gateway */
 	rerrstr(err, sizeof(err));
-	if(fd < 0 && gdomain && strstr(err, "can't translate") != 0) {
-		fprint(2,"dialing %s\n",gdomain);
+	if(fd < 0 && gdomain && strstr(err, "can't translate") != 0)
 		fd = dial(netmkaddr(gdomain, 0, "smtp"), 0, 0, 0);
-	}
 
 	return fd;
+}
+
+static int
+timeout(void*, char *msg)
+{
+	if(strstr(msg, "alarm"))
+		return 1;
+	return 0;
 }
 
 /*
@@ -92,7 +99,11 @@ callmx(DS *ds, char *dest, char *domain)
 			mx[i].host, ds->service);
 		if(debug)
 			fprint(2, "mxdial trying %s\n", addr);
+		atnotify(timeout, 1);
+		alarm(10*1000);
 		fd = dial(addr, 0, 0, 0);
+		alarm(0);
+		atnotify(timeout, 0);
 		if(fd >= 0)
 			return fd;
 	}
@@ -316,6 +327,7 @@ expand_meta(DS *ds)
 }
 #endif /* jpc */
 
+/* XXX */
 static void
 expand_meta(DS *ds)
 {
blob - e88154f78a2ae2ec215a72aeb575949cafb1f7da
blob + fb00cd5f5f99014d5fb2acb596609c4c0eee9077
--- src/cmd/upas/smtp/smtp.c
+++ src/cmd/upas/smtp/smtp.c
@@ -171,7 +171,7 @@ threadmain(int argc, char **argv)
 	if(*argv == 0)
 		usage();
 	addr = *argv++; argc--;
-	// expand $smtp if necessary
+	// expand $smtp if necessary XXX
 	addr = expand_addr(addr);
 	farend = addr;
 
@@ -202,12 +202,12 @@ threadmain(int argc, char **argv)
 		exits(0);
 	}
 
-	/* 10 minutes to get through the initial handshake */
-	atnotify(timeout, 1);
-
-	alarm(10*alarmscale);
+	/* mxdial uses its own timeout handler */
 	if((rv = connect(addr)) != 0)
 		exits(rv);
+
+	/* 10 minutes to get through the initial handshake */
+	atnotify(timeout, 1);
 	alarm(10*alarmscale);
 	if((rv = hello(hellodomain, 0)) != 0)
 		goto error;
@@ -1097,6 +1097,7 @@ dBputc(int x)
 	return Bputc(&bout, x);
 }
 
+/* XXX */
 char* 
 expand_addr(char* a)
 {
blob - 7042c37c3bf3b21105adf9408a1c05bb8b198b4c
blob + 8bd4511d28d80934fd206200143df8b7ac59e530
--- src/cmd/upas/smtp/smtpd.c
+++ src/cmd/upas/smtp/smtpd.c
@@ -157,7 +157,7 @@ main(int argc, char **argv)
 
 	if(debug){
 		close(2);
-		snprint(buf, sizeof(buf), "%s/smtpd", UPASLOG);
+		snprint(buf, sizeof(buf), "%s/smtpd.db", UPASLOG);
 		if (open(buf, OWRITE) >= 0) {
 			seek(2, 0, 2);
 			fprint(2, "%d smtpd %s\n", getpid(), thedate());
@@ -1221,6 +1221,16 @@ data(void)
 		}
 		reply("%d mail process terminated abnormally\r\n", code);
 	} else {
+		/*
+		 * if a message appeared on stderr, despite good status,
+		 * log it.  this can happen if rewrite.in contains a bad
+		 * r.e., for example.
+		 */
+		if(*s_to_c(err))
+			syslog(0, "smtpd",
+				"%s returned good status, but said: %s",
+				s_to_c(mailer), s_to_c(err));
+
 		if(filterstate == BLOCKED)
 			reply("554 we believe this is spam.  we don't accept it.\r\n");
 		else
blob - 84a8fccc32ac95965ed12ebba544556ca5097d96
blob + a4d49485e654e60445a8fda3d904da30923fe5ed
--- src/cmd/upas/smtp/spam.c
+++ src/cmd/upas/smtp/spam.c
@@ -62,7 +62,7 @@ findkey(char *val, Keyword *p)
 char*
 actstr(int a)
 {
-	char buf[32];
+	static char buf[32];
 	Keyword *p;
 
 	for(p=actions; p->name; p++)
@@ -84,7 +84,8 @@ getaction(char *s, char *type)
 		return ACCEPT;
 
 	for(k = actions; k->name != 0; k++){
-		snprint(buf, sizeof buf, "/mail/ratify/%s/%s/%s", k->name, type, s);
+		snprint(buf, sizeof buf, "%s/mail/ratify/%s/%s/%s", 
+			get9root(), k->name, type, s);
 		if(access(buf,0) >= 0)
 			return k->code;
 	}
@@ -99,7 +100,7 @@ istrusted(char *s)
 	if(s == nil || *s == 0)
 		return 0;
 
-	snprint(buf, sizeof buf, "/mail/ratify/trusted/%s", s);
+	snprint(buf, sizeof buf, "%s/mail/ratify/trusted/%s", get9root(), s);
 	return access(buf,0) >= 0;
 }
 
@@ -167,6 +168,7 @@ getconf(void)
 	sysclose(bp);
 }
 
+#if 0
 /*
  *	match a user name.  the only meta-char is '*' which matches all
  *	characters.  we only allow it as "*", which matches anything or
@@ -186,6 +188,7 @@ usermatch(char *pathuser, char *specuser)
 	}
 	return strcmp(pathuser, specuser);
 }
+#endif
 
 static int
 dommatch(char *pathdom, char *specdom)
@@ -493,7 +496,7 @@ dumpfile(char *sender)
 	return "/dev/null";
 }
 
-char *validator = "/mail/lib/validateaddress";
+char *validator = "#9/mail/lib/validateaddress";
 
 int
 recipok(char *user)
@@ -504,7 +507,12 @@ recipok(char *user)
 	Biobuf *bp;
 	int pid;
 	Waitmsg *w;
-
+	static int beenhere;
+	
+	if(!beenhere){
+		beenhere++;
+		validator = unsharp(validator);
+	}
 	if(shellchars(user)){
 		syslog(0, "smtpd", "shellchars in user name");
 		return 0;
@@ -522,9 +530,7 @@ recipok(char *user)
 			if(w->pid != pid)
 				continue;
 			if(w->msg[0] != 0){
-				/*
 				syslog(0, "smtpd", "validateaddress %s: %s", user, w->msg);
-				*/
 				return 0;
 			}
 			break;
@@ -581,7 +587,7 @@ optoutofspamfilter(char *addr)
 
 
 	rv = 0;
-	f = smprint("/mail/box/%s/nospamfiltering", p);
+	f = smprint("%s/mail/box/%s/nospamfiltering", get9root(), p);
 	if(f != nil){
 		rv = access(f, 0)==0;
 		free(f);
blob - 612a5965f05976d52a2c8ce6d2b634a8c1091d93
blob + 0574e93fd0c6fb823bd128888d290915e8706fab
--- src/cmd/upas/unesc/mkfile
+++ src/cmd/upas/unesc/mkfile
@@ -1,17 +1,7 @@
-</$objtype/mkfile
+<$PLAN9/src/mkhdr
 
 TARG=unesc
+OFILES=unesc.$O
 
-OFILES=unesc.$O\
-
-BIN=/$objtype/bin/upas
-
-CC=pcc -c
-CFLAGS=-B
-
-UPDATE=\
-	mkfile\
-	$HFILES\
-	${OFILES:%.$O=%.c}\
-
-</sys/src/cmd/mkone
+BIN=$BIN/upas
+<$PLAN9/src/mkone
blob - f3b4d652d2ac3e6a28ce99d723090a337652423a
blob + faf5e9486d761219968941862d8c79b4cc844ec4
--- src/cmd/upas/unesc/unesc.c
+++ src/cmd/upas/unesc/unesc.c
@@ -17,7 +17,7 @@ hex(int c)
 	return 0;
 }
 
-void
+int
 main(int argc, char **argv)
 {
 	int c;
blob - db4f5ce8b539eb157655c14b89d103084f16bc51
blob + 9d9081500b03b694d8fdef69efb5b88930726b27
--- src/cmd/upas/vf/vf.c
+++ src/cmd/upas/vf/vf.c
@@ -117,6 +117,13 @@ int justreject;
 char *savefile;
 
 void
+usage(void)
+{
+	fprint(2, "usage: upas/vf [-r] [-s savefile]\n");
+	exits("usage");
+}
+
+void
 main(int argc, char **argv)
 {
 	ARGBEGIN{
@@ -124,11 +131,14 @@ main(int argc, char **argv)
 		justreject = 1;
 		break;
 	case 's':
-		savefile = ARGF();
-		if(savefile == nil)
-			exits("usage");
+		savefile = EARGF(usage());
 		break;
+	default:
+		usage();
 	}ARGEND;
+
+	if(argc)
+		usage();
 
 	Binit(&in, 0, OREAD);
 	Binit(&out, 1, OWRITE);
@@ -415,8 +425,7 @@ savetmp(Part *p)
 }
 
 /*
- * XXX save the decoded file, run 9 unzip -tf on it, and then
- * look at the file list.
+ * Run the external checker to do content-based checks.
  */
 static int
 runchecker(Part *p)
@@ -483,19 +492,18 @@ problemchild(Part *p)
 	if(runchecker(p) > 0)
 		return p;
 
-fprint(2, "x\n");
+	if(justreject)
+		return p;
+		
 	syslog(0, "mail", "vf wrapped %s %s", p->type?s_to_c(p->type):"?",
 		p->filename?s_to_c(p->filename):"?");
-fprint(2, "x\n");
 
 	boundary = mkboundary();
-fprint(2, "x\n");
 	/* print out non-mime headers */
 	for(hl = p->hl; hl != nil; hl = hl->next)
 		if(cistrncmp(s_to_c(hl->s), "content-", 8) != 0)
 			Bprint(&out, "%s", s_to_c(hl->s));
 
-fprint(2, "x\n");
 	/* add in our own multipart headers and message */
 	Bprint(&out, "Content-Type: multipart/mixed;\n");
 	Bprint(&out, "\tboundary=\"%s\"\n", s_to_c(boundary));
@@ -539,11 +547,9 @@ fprint(2, "x\n");
 		break;
 	}
 
-fprint(2, "z\n");
 	/* pass the body */
 	np = passbody(p, 0);
 
-fprint(2, "w\n");
 	/* add the new boundary and the original terminator */
 	Bprint(&out, "--%s--\n", s_to_c(boundary));
 	if(np && np->boundary){
@@ -551,7 +557,6 @@ fprint(2, "w\n");
 		Bwrite(&out, cp, Blinelen(&in));
 	}
 
-fprint(2, "a %p\n", np);
 	return np;
 }
 
@@ -871,8 +876,6 @@ badfile(char *name)
 				return 2;
 			}
 		}
-	if(justreject)
-		return 0;
 	return 1;
 }
 
@@ -887,9 +890,6 @@ badtype(char *type)
 	char *s, *fix;
 	int rv = 1;
 
-	if(justreject)
-		return 0;
-
 	fix = s = strchr(type, '/');
 	if(s != nil)
 		*s++ = 0;