shithub: Nail

Download patch

ref: 8f73c6436a0a0a39f6e1de79b4fd6f21af38d841
parent: 5924afea6a78723f097830797da04579b6aaeb81
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Nov 4 00:52:14 EST 2020

implement Reply All.

--- a/comp.c
+++ b/comp.c
@@ -103,7 +103,7 @@
 		case 'l':
 		case 'L':
 			if((a = matchaddr(&mbox, &ev)) != nil)
-				compose1(a, nil, 0);
+				compose(a, nil, 0, 0);
 			else if(matchmesg(&mbox, ev.text))
 				mesgopen(ev.text, nil);
 			else if(!(ev.flags & 0x2))
@@ -132,13 +132,12 @@
 }
 
 void
-compose(char **to, int nto, char **cc, int ncc, Mesg *r, int quote)
+compose(char *to, Mesg *r, int quote, int all)
 {
 	static int ncompose;
 	char *path, *ln;
 	Biobuf *rfd, *wfd;
 	Comp *c;
-	int i;
 
 	c = emalloc(sizeof(Comp));
 	if(r != nil)
@@ -150,10 +149,16 @@
 
 	wintagwrite(c, "Delmesg Save Post ");
 	wfd = bwinopen(c, "body", OWRITE);
-	for(i = 0; i < nto; i++)
-		Bprint(wfd, "To: %s\n", to[i]);
-	for(i = 0; i < ncc; i++)
-		Bprint(wfd, "Cc: %s\n", cc[i]);
+	if(r == nil || !all)
+		Bprint(wfd, "To: %s", to);
+	else{
+		if(strlen(r->from) > 0)
+			Bprint(wfd, "To: %s\n", r->from);
+		if(strlen(r->to) > 0)
+			Bprint(wfd, "To: %s\n", r->to);
+		if(strlen(r->cc) > 0)
+			Bprint(wfd, "CC: %s\n", r->cc);
+	}
 	if(r == nil){
 		Bprint(wfd, "\n");
 	}else{
@@ -179,10 +184,4 @@
 	}
 	Bterm(wfd);
 	proccreate(compmain, c, Stack);
-}
-
-void
-compose1(char *to, Mesg *resp, int quote)
-{
-	compose(&to, 1, nil, 0, resp, quote);
 }
--- a/mail.h
+++ b/mail.h
@@ -178,8 +178,7 @@
 void	mbredraw(Mesg*, int, int);
 
 /* composition */
-void	compose(char**, int, char**, int, Mesg*, int);
-void	compose1(char*, Mesg*, int);
+void	compose(char*, Mesg*, int, int);
 
 /* utils */
 void	*emalloc(ulong);
--- a/mbox.c
+++ b/mbox.c
@@ -676,7 +676,7 @@
 	case 'l':
 	case 'L':
 		if((a = matchaddr(&mbox, ev)) != nil)
-			compose1(a, nil, 0);
+			compose(a, nil, 0, 0);
 		else if(matchmesg(&mbox, ev->text))
 			mesgopen(ev->text, nil);
 		else
--- a/mesg.c
+++ b/mesg.c
@@ -283,8 +283,7 @@
 		return;
 	}
 
-	/* FIXME: get all recievers of the message */
-	compose1(m->from, m, 0);
+	compose(m->replyto, m, 0, nf >= 1);
 }
 
 static void
@@ -297,9 +296,7 @@
 		fprint(2, "Q: invaid args\n");
 		return;
 	}
-
-	/* FIXME: get all recievers of the message */
-	compose1(m->from, m, 1);
+	compose(m->replyto, m, 1, nf >= 2);
 }
 
 static void
@@ -358,7 +355,7 @@
 		case 'l':
 		case 'L':
 			if((a = matchaddr(m, &ev)) != nil)
-				compose1(a, nil, 0);
+				compose(a, nil, 0, 0);
 			else if(matchmesg(m, ev.text))
 				mesgopen(ev.text, nil);
 			else