Fix uip/whom.c for C89 compatibility
[mmh] / uip / spost.c
index 04479a1..39d8ada 100644 (file)
@@ -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 */
@@ -212,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 */
@@ -220,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",
@@ -243,6 +245,9 @@ main(int argc, char **argv)
                        finish_headers(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;
@@ -264,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 */
@@ -311,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";
@@ -321,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);
@@ -397,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)) {
@@ -428,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;
                                }
                        }
                }
@@ -543,10 +552,10 @@ putadr(char *name, struct mailname *nl)
                }
                if (mp->m_ingrp) {
                        if (mp->m_gname != NULL) {
-                               cp = getcpy(mp->m_gname);
+                               cp = mh_xstrdup(mp->m_gname);
                                cp = add(";", cp);
                                linepos = putone(cp, linepos, namelen);
-                               free(cp);
+                               mh_free0(&cp);
                                cp = NULL;
                        }
                } else {
@@ -642,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);
        }
 }
@@ -658,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");