shithub: riscv

Download patch

ref: 4257a5292af5a9a3ff8fbbc76a00fdeffc75bfd2
parent: 6f15a730f351b75f24286cb937a96db1ee9e5b82
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Nov 6 13:15:15 EST 2020

upas/marshal: add -S saveto to save outgoing mail, fix -F

Upas/marshal -F was broken with the '-8' command, and silly
without it: It used aliases passed on the command line, so
the destination address was ignored with -8 was passed.

In addition, it would create a new mailbox for any aliases
being sent to, instead of putting them all in one location.

The new -S option is similar to -F, but specifies where the
message should go.

--- a/sys/man/1/marshal
+++ b/sys/man/1/marshal
@@ -15,6 +15,9 @@
 ] [
 .B -Fr#xn
 ] [
+.B -S
+.I saveto
+] [
 .B -p[es]
 ] [
 .B -R
@@ -103,6 +106,11 @@
 .TP
 .BI -F
 file the message
+.TP
+.BI -S saveto
+file the message into the
+.I saveto
+mailbox.
 .TP
 .BI -n
 intentionally no standard input
--- a/sys/src/cmd/upas/marshal/marshal.c
+++ b/sys/src/cmd/upas/marshal/marshal.c
@@ -193,7 +193,7 @@
 main(int argc, char **argv)
 {
 	int ccargc, bccargc, flags, fd, noinput, headersrv;
-	char *subject, *type, *boundary;
+	char *subject, *type, *boundary, *saveto;
 	char *ccargv[32], *bccargv[32];
 	Addr *to, *cc, *bcc;
 	Attach *first, **l, *a;
@@ -207,6 +207,7 @@
 	l = &first;
 	type = nil;
 	hdrstring = nil;
+	saveto = nil;
 	ccargc = bccargc = 0;
 
 	tmfmtinstall();
@@ -244,6 +245,9 @@
 	case 'F':
 		Fflag = 1;		/* file message */
 		break;
+	case 'S':
+		saveto = EARGF(usage());
+		break;
 	case 'n':			/* no standard input */
 		nflag = 1;
 		break;
@@ -336,7 +340,9 @@
 		}
 	}
 
-	fd = sendmail(to, cc, bcc, &pid, Fflag ? argv[0] : nil);
+	if(Fflag)
+		saveto=argc>0?argv[0]:to->v;
+	fd = sendmail(to, cc, bcc, &pid, saveto);
 	if(fd < 0)
 		sysfatal("execing sendmail: %r\n:");
 	if(xflag || lbflag || dflag){
@@ -1079,10 +1085,8 @@
 				break;
 			case 0:
 				close(pfd[0]);
-				b = 0;
 				/* BOTCH; "From " time gets changed */
-				if(rcvr)
-					b = openfolder(foldername(nil, user, rcvr), time(0));
+				b = openfolder(foldername(nil, user, rcvr), time(0));
 				fd = b? Bfildes(b): -1;
 				printunixfrom(fd);
 				tee(0, pfd[1], fd);