From 8aeebaf757a1588ae2836965f5443ca7dc3a0257 Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Sun, 31 May 2015 00:53:11 +0200 Subject: [PATCH] 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. --- uip/spost.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/uip/spost.c b/uip/spost.c index ac2843f..163c1e6 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); } } -- 1.7.10.4