From: Philipp Takacs <philipp@bureaucracy.de>
Date: Sat, 30 May 2015 22:53:11 +0000 (+0200)
Subject: fix bug if multible mbox in From-field
X-Git-Tag: mmh-0.2-RC1~32^2~4
X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=8aeebaf757a1588ae2836965f5443ca7dc3a0257;p=mmh

fix bug if multible mbox in From-field

Now the first address of the user is used, if multible addresses
are in the From-field. If non of the addresses is an address
of the user, the the behaviour has not changed.
---

diff --git a/uip/spost.c b/uip/spost.c
index ac2843fd..163c1e6d 100644
--- a/uip/spost.c
+++ b/uip/spost.c
@@ -115,6 +115,7 @@ static char *tmpfil;
 static char *subject = NULL;  /* the subject field for BCC'ing */
 static char fccs[BUFSIZ] = "";
 struct mailname *bccs = NULL;  /* list of the bcc recipients */
+struct mailname *sender = NULL;
 
 static struct headers *hdrtab;  /* table for the message we're doing */
 static FILE *out;  /* output (temp) file */
@@ -415,16 +416,38 @@ putfmt(char *name, char *str, FILE *out)
 	if (hdr->set & MFRM) {
 
 		struct mailname *mp = NULL;
+		struct mailname *my = NULL;
+		unsigned int fromcnt = 0;
 
 		/* This is need because the addresse parser hold global state */
 		ismymbox(NULL);
 
 		while ((cp = getname(str)) != NULL) {
+			fromcnt++;
 			mp = getm(cp, NULL, 0, AD_NAME, NULL);
 			if (ismymbox(mp)) {
 				msgflags |= MFMM;
+				if (my == NULL) {
+					my = mp;
+				} else {
+					mnfree(mp);
+					mp = NULL;
+				}
+			} else {
+				mnfree(mp);
+				mp = NULL;
 			}
 		}
+
+		if (fromcnt > 1) {
+			sender = my;
+		} else {
+			mnfree(my);
+		}
+
+		free(cp);
+		cp = NULL;
+
 	}
 
 	if (hdr->flags & HSUB) {
@@ -449,7 +472,9 @@ finish_headers(FILE *out)
 		fprintf(out, "%sDate: %s\n", resentstr, dtimenow());
 	}
 
-	if ((cp = context_find("Default-From")) != NULL) {
+	if (sender != NULL) {
+		snprintf(signature, sizeof(signature), "%s", sender->m_text);
+	} else if ((cp = context_find("Default-From")) != NULL) {
 		snprintf(signature, sizeof(signature), "%s", cp);
 	} else {
 		snprintf(from, sizeof(from), "%s@%s", getusername(), LocalName());
@@ -466,7 +491,7 @@ finish_headers(FILE *out)
 		** Add a Sender: header because the From: header could
 		** be fake or contain multiple addresses.
 		*/
-		if (!(msgflags & MFMM)) {
+		if (!(msgflags & MFMM) || sender != NULL) {
 			fprintf(out, "%sSender: %s\n", resentstr, signature);
 		}
 	}