X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fspost.c;h=39d8ada53dfb99f8b35888ac62d290e53d7ed978;hp=780b5f449c8e7ccb022b0e7338d977b88daeb424;hb=6e9577f324bef90765a5edc02044eb111ec48072;hpb=054c8779d6660afe45f38fa04510c2061aa6a605 diff --git a/uip/spost.c b/uip/spost.c index 780b5f4..39d8ada 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -39,6 +39,7 @@ static struct swit switches[] = { { NULL, 0 } }; +char *version=VERSION; /* flags for headers->flags */ #define HNOP 0x0000 /* just used to keep .set around */ @@ -117,6 +118,7 @@ static enum { static char *tmpfil; static char *subject = NULL; /* the subject field for BCC'ing */ +static struct mailname *from = NULL; /* the from field for BCC'ing */ static char fccs[BUFSIZ] = ""; struct mailname *bccs = NULL; /* list of the bcc recipients */ struct mailname *recipients = NULL; /* list of the recipients */ @@ -143,9 +145,11 @@ static size_t do_aliasing(struct mailname *, struct mailname **); int main(int argc, char **argv) { - int state, compnum; + enum state state; + struct field f = {{0}}; + int compnum; char *cp, *msg = NULL, **argp, **arguments; - char **sargv, buf[BUFSIZ], name[NAMESZ]; + char **sargv, buf[BUFSIZ]; FILE *in; setlocale(LC_ALL, ""); @@ -210,7 +214,7 @@ main(int argc, char **argv) verbose++; out = stdout; } else { - tmpfil = getcpy(m_mktemp2("/tmp/", invo_name, NULL, &out)); + tmpfil = mh_xstrdup(m_mktemp2("/tmp/", invo_name, NULL, &out)); } /* check for "Aliasfile:" profile entry */ @@ -218,7 +222,7 @@ main(int argc, char **argv) char *dp, **ap; aliasflg = 1; - for (ap=brkstring(dp=getcpy(cp), " ", "\n"); ap && *ap; + for (ap=brkstring(dp=mh_xstrdup(cp), " ", "\n"); ap && *ap; ap++) { if ((state = alias(etcpath(*ap))) != AK_OK) { adios(EX_IOERR, NULL, "aliasing error in file %s: %s", @@ -230,37 +234,31 @@ main(int argc, char **argv) hdrtab = (msgstate == normal) ? NHeaders : RHeaders; - for (compnum = 1, state = FLD;;) { - switch (state = m_getfld(state, name, buf, sizeof(buf), in)) { - case FLD: - case FLDPLUS: + for (compnum = 1, state = FLD2;;) { + switch (state = m_getfld2(state, &f, in)) { + case FLD2: compnum++; - cp = getcpy(buf); - while (state == FLDPLUS) { - state = m_getfld(state, name, buf, - sizeof(buf), in); - cp = add(buf, cp); - } - putfmt(name, cp, out); - free(cp); + putfmt(f.name, f.value, out); continue; - case BODY: + case BODY2: finish_headers(out); - fprintf(out, "\n%s", buf); - while (state == BODY) { - state = m_getfld(state, name, buf, - sizeof(buf), in); - fputs(buf, out); + fprintf(out, "\n%s", f.value); + while ((state = m_getfld2(state, &f, in)) == BODY2) { + if (f.valuelen >= NAMESZ) { + adios(EX_DATAERR, NULL, "Body contains a to long line"); + } + fputs(f.value, out); } break; - case FILEEOF: + case FILEEOF2: finish_headers(out); break; - case LENERR: - case FMTERR: + case LENERR2: + case FMTERR2: + case IOERR2: adios(EX_DATAERR, NULL, "message format error in component #%d", compnum); @@ -271,6 +269,10 @@ main(int argc, char **argv) } fclose(in); + if (state != FILEEOF2) { + adios(EX_IOERR, "m_getfld2", "Error while reading body"); + } + if (debug) { struct mailname *i = recipients; /* stop here */ @@ -318,7 +320,7 @@ main(int argc, char **argv) adios(EX_DATAERR, NULL, "message has no recipients"); } - sargv = mh_xmalloc(sizeof(char **) * (recipientsc + 4)); + sargv = mh_xcalloc(recipientsc + 4, sizeof(char **)); argp = sargv; *argp++ = "send-mail"; @@ -328,7 +330,7 @@ main(int argc, char **argv) } while (recipients != NULL) { - cp = getcpy(recipients->m_mbox); + cp = mh_xstrdup(recipients->m_mbox); if (recipients->m_host) { cp = add("@", cp); cp = add(recipients->m_host, cp); @@ -404,7 +406,7 @@ putfmt(char *name, char *str, FILE *out) } if (hdr->flags & HSUB) { - subject = getcpy(str); + subject = mh_xstrdup(str); } if (!(hdr->flags & HADR)) { @@ -435,11 +437,11 @@ putfmt(char *name, char *str, FILE *out) /* needed because the address parser holds global state */ ismymbox(NULL); - for ( mp = addr_start.m_next; mp; mp = mp->m_next) { + for (mp = addr_start.m_next; mp; mp = mp->m_next) { if (ismymbox(mp)) { msgflags |= MFMM; if (my == NULL) { - my = mp; + from = my = mp; } } } @@ -535,6 +537,7 @@ static void putadr(char *name, struct mailname *nl) { struct mailname *mp; + char *cp; int linepos; int namelen; @@ -547,7 +550,17 @@ putadr(char *name, struct mailname *nl) fprintf(out, "\n%s: ", name); linepos = namelen; } - linepos = putone(mp->m_text, linepos, namelen); + if (mp->m_ingrp) { + if (mp->m_gname != NULL) { + cp = mh_xstrdup(mp->m_gname); + cp = add(";", cp); + linepos = putone(cp, linepos, namelen); + mh_free0(&cp); + cp = NULL; + } + } else { + linepos = putone(mp->m_text, linepos, namelen); + } mp = mp->m_next; } putc('\n', out); @@ -638,7 +651,7 @@ fcc(char *file, char *folders) fprintf(stderr, "Skipped %sFcc %s: unable to system().\n", msgstate == resent ? "Resent-" : "", folders); } else if (status != 0) { - fprintf(stderr, "%sFcc %s: Problems occured.\n", + fprintf(stderr, "%sFcc %s: Problems occurred.\n", msgstate == resent ? "Resent-" : "", folders); } } @@ -654,8 +667,11 @@ process_bccs(char *origmsg) FILE *out = NULL; for (mp=bccs; mp; mp=mp->m_next) { - bccdraft = getcpy(m_mktemp2("/tmp/", invo_name, NULL, &out)); + bccdraft = mh_xstrdup(m_mktemp2("/tmp/", invo_name, NULL, &out)); fprintf(out, "To: %s\n", mp->m_text); + if (from) { + fprintf(out, "From: %s\n", from->m_text); + } fprintf(out, "Subject: [BCC] %s", subject ? subject : ""); fprintf(out, "%s: %s\n", attach_hdr, origmsg); fprintf(out, "------------\n");