shithub: riscv

Download patch

ref: 55a34e1131567f0c36e0d9362043b57dded7f5e1
parent: 5697e93e654d04b1f872a3af3418ea3c293b5883
author: stanley lieber <[email protected]>
date: Mon Dec 31 14:53:59 EST 2012

upas/marshal: interpret attach: and inline: lines in body of message

--- a/sys/src/cmd/upas/marshal/marshal.c
+++ b/sys/src/cmd/upas/marshal/marshal.c
@@ -46,6 +46,8 @@
 	Hcontent,
 	Hx,
 	Hprecedence,
+	Hattach,
+	Hinline,
 	Nhdr,
 };
 
@@ -70,6 +72,8 @@
 [Hcontent]	"content-",
 [Hx]		"x-",
 [Hprecedence]	"precedence",
+[Hattach]		"attach",
+[Hinline]		"inline",
 };
 
 struct Ctype {
@@ -122,7 +126,7 @@
 int	printsubject(Biobuf*, char*);
 int	printto(Biobuf*, Addr*);
 Alias*	readaliases(void);
-int	readheaders(Biobuf*, int*, String**, Addr**, Addr**, Addr**, int);
+int	readheaders(Biobuf*, int*, String**, Addr**, Addr**, Addr**, Attach**, int);
 void	readmimetypes(void);
 int	rfc2047fmt(Fmt*);
 int	sendmail(Addr*, Addr*, Addr*, int*, char*);
@@ -304,7 +308,7 @@
 		 */
 		holding = holdon();
 		headersrv = readheaders(&in, &flags, &hdrstring,
-			eightflag? &to: nil, eightflag? &cc: nil, eightflag? &bcc: nil, 1);
+			eightflag? &to: nil, eightflag? &cc: nil, eightflag? &bcc: nil, l, 1);
 		if(rfc822syntaxerror){
 			Bdrain(&in);
 			fatal("rfc822 syntax error, message not sent");
@@ -345,7 +349,7 @@
 	mboxpath("headers", user, file, 0);
 	b = Bopen(s_to_c(file), OREAD);
 	if(b != nil){
-		if (readheaders(b, &flags, &hdrstring, nil, nil, nil, 0) == Error)
+		if (readheaders(b, &flags, &hdrstring, nil, nil, nil, l, 0) == Error)
 			fatal("reading");
 		Bterm(b);
 		bwritesfree(&out, &hdrstring);
@@ -445,15 +449,16 @@
  * remove Bcc: line.
  */
 int
-readheaders(Biobuf *in, int *fp, String **sp, Addr **top, Addr **ccp, Addr **bccp, int strict)
+readheaders(Biobuf *in, int *fp, String **sp, Addr **top, Addr **ccp, Addr **bccp, Attach **l, int strict)
 {
-	int i, seen, hdrtype;
+	int i, seen, hdrtype, flags;
 	char *p;
-	Addr *to, *cc, *bcc;
+	Addr *to, *cc, *bcc, *attachment;
+	Attach *a;
 	String *s, *sline;
 
 	s = s_new();
-	to = cc = bcc = nil;
+	to = cc = bcc = attachment = nil;
 	sline = nil;
 	hdrtype = -1;
 	seen = 0;
@@ -494,6 +499,19 @@
 			case Hsubject:
 				s_append(s, mksubject(s_to_c(sline)));
 				s_append(s, "\n");
+				break;
+			case Hattach:
+				flags = 0;
+				goto afile;
+			case Hinline:
+				flags = 1;
+			afile:
+				attachment = expandline(&sline, attachment);
+				a = mkattach(attachment->v, nil, flags);
+				if(a == nil)
+					exits("bad args");
+				*l = a;
+				l = &a->next;
 				break;
 			}
 			s_free(sline);