X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fforw.c;h=e00ae0e1cbd6d2181dc284a4a7ed69646f7b36de;hp=8455431a2a7db2d072a5d78c63e0be1b1012061e;hb=6e9577f324bef90765a5edc02044eb111ec48072;hpb=197f95940cc0860683e6988352f721e6603f9339 diff --git a/uip/forw.c b/uip/forw.c index 8455431..e00ae0e 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -1,697 +1,347 @@ - /* - * forw.c -- forward a message, or group of messages. - * - * $Id$ - */ +** forw.c -- forward a message, or group of messages. +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ #include #include #include -#include - +#include +#include +#include +#include +#include -#define IFORMAT "digest-issue-%s" -#define VFORMAT "digest-volume-%s" +#define IFORMAT "digest-issue-%s" +#define VFORMAT "digest-volume-%s" static struct swit switches[] = { -#define ANNOSW 0 - { "annotate", 0 }, -#define NANNOSW 1 - { "noannotate", 0 }, -#define DFOLDSW 2 - { "draftfolder +folder", 0 }, -#define DMSGSW 3 - { "draftmessage msg", 0 }, -#define NDFLDSW 4 - { "nodraftfolder", 0 }, -#define EDITRSW 5 - { "editor editor", 0 }, -#define NEDITSW 6 - { "noedit", 0 }, -#define FILTSW 7 - { "filter filterfile", 0 }, -#define FORMSW 8 - { "form formfile", 0 }, -#define FRMTSW 9 - { "format", 5 }, -#define NFRMTSW 10 - { "noformat", 7 }, -#define INPLSW 11 - { "inplace", 0 }, -#define NINPLSW 12 - { "noinplace", 0 }, -#define MIMESW 13 - { "mime", 0 }, -#define NMIMESW 14 - { "nomime", 0 }, -#define DGSTSW 15 - { "digest list", 0 }, -#define ISSUESW 16 - { "issue number", 0 }, -#define VOLUMSW 17 - { "volume number", 0 }, -#define WHATSW 18 - { "whatnowproc program", 0 }, -#define NWHATSW 19 - { "nowhatnowproc", 0 }, -#define BITSTUFFSW 20 - { "dashstuffing", 0 }, /* interface to mhl */ -#define NBITSTUFFSW 21 - { "nodashstuffing", 0 }, -#define VERSIONSW 22 - { "version", 0 }, -#define HELPSW 23 - { "help", 4 }, -#define FILESW 24 - { "file file", -4 }, /* interface from msh */ - -#ifdef MHE -#define BILDSW 25 - { "build", -5 }, /* interface from mhe */ -#endif /* MHE */ - - { NULL, 0 } -}; - -static struct swit aqrnl[] = { -#define NOSW 0 - { "quit", 0 }, -#define YESW 1 - { "replace", 0 }, -#define LISTDSW 2 - { "list", 0 }, -#define REFILSW 3 - { "refile +folder", 0 }, -#define NEWSW 4 - { "new", 0 }, - { NULL, 0 } +#define ANNOSW 0 + { "annotate", 0 }, +#define NANNOSW 1 + { "noannotate", 2 }, +#define EDITRSW 2 + { "editor editor", 0 }, +#define FORMSW 3 + { "form formfile", 0 }, +#define DGSTSW 4 + { "digest list", 0 }, +#define ISSUESW 5 + { "issue number", 0 }, +#define VOLUMSW 6 + { "volume number", 0 }, +#define WHATSW 7 + { "whatnowproc program", 0 }, +#define VERSIONSW 8 + { "Version", 0 }, +#define HELPSW 9 + { "help", 0 }, +#define BILDSW 10 + { "build", 5 }, /* interface from mhe */ + { NULL, 0 } }; -static struct swit aqrl[] = { - { "quit", 0 }, - { "replace", 0 }, - { "list", 0 }, - { "refile +folder", 0 }, - { NULL, 0 } -}; +char *version=VERSION; static char drft[BUFSIZ]; - -static char delim3[] = - "\n------------------------------------------------------------\n\n"; -static char delim4[] = "\n------------------------------\n\n"; - - -static struct msgs *mp = NULL; /* used a lot */ +static struct msgs *mp = NULL; /* - * static prototypes - */ -static void mhl_draft (int, char *, int, int, char *, char *, int); -static void copy_draft (int, char *, char *, int, int, int); -static void copy_mime_draft (int); -static int build_form (char *, char *, int, int); +** static prototypes +*/ +static void add_forw_hdr(char *); +static int build_form(char *, char *, int, int); int -main (int argc, char **argv) +main(int argc, char **argv) { - int msgp = 0, anot = 0, inplace = 1, mime = 0; - int issue = 0, volume = 0, dashstuff = 0; - int nedit = 0, nwhat = 0, i, in; - int out, isdf = 0, msgnum; - char *cp, *cwd, *maildir, *dfolder = NULL; - char *dmsg = NULL, *digest = NULL, *ed = NULL; - char *file = NULL, *filter = NULL, *folder = NULL; - char *form = NULL, buf[BUFSIZ], value[10]; - char **argp, **arguments, *msgs[MAXARGS]; - struct stat st; - -#ifdef MHE - int buildsw = 0; -#endif /* MHE */ - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); - - /* read user profile/context */ - context_read(); - - arguments = getarguments (invo_name, argc, argv, 1); - argp = arguments; - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch (++cp, switches)) { - case AMBIGSW: - ambigsw (cp, switches); - done (1); - case UNKWNSW: - adios (NULL, "-%s unknown", cp); - - case HELPSW: - snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", - invo_name); - print_help (buf, switches, 1); - done (1); - case VERSIONSW: - print_version(invo_name); - done (1); - - case ANNOSW: - anot++; - continue; - case NANNOSW: - anot = 0; - continue; - - case EDITRSW: - if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nedit = 0; - continue; - case NEDITSW: - nedit++; - continue; - - case WHATSW: - if (!(whatnowproc = *argp++) || *whatnowproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nwhat = 0; - continue; -#ifdef MHE - case BILDSW: - buildsw++; /* fall... */ -#endif /* MHE */ - case NWHATSW: - nwhat++; - continue; - - case FILESW: - if (file) - adios (NULL, "only one file at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - file = path (cp, TFILE); - continue; - case FILTSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - filter = getcpy (etcpath (cp)); - mime = 0; - continue; - case FORMSW: - if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - - case FRMTSW: - filter = getcpy (etcpath (mhlforward)); - continue; - case NFRMTSW: - filter = NULL; - continue; - - case INPLSW: - inplace++; - continue; - case NINPLSW: - inplace = 0; - continue; - - case MIMESW: - mime++; - filter = NULL; - continue; - case NMIMESW: - mime = 0; - continue; - - case DGSTSW: - if (!(digest = *argp++) || *digest == '-') - adios (NULL, "missing argument to %s", argp[-2]); - mime = 0; - continue; - case ISSUESW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((issue = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - case VOLUMSW: - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - if ((volume = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); - continue; - - case DFOLDSW: - if (dfolder) - adios (NULL, "only one draft folder at a time!"); - if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, - *cp != '@' ? TFOLDER : TSUBCWF); - continue; - case DMSGSW: - if (dmsg) - adios (NULL, "only one draft message at a time!"); - if (!(dmsg = *argp++) || *dmsg == '-') - adios (NULL, "missing argument to %s", argp[-2]); - continue; - case NDFLDSW: - dfolder = NULL; - isdf = NOTOK; - continue; - - case BITSTUFFSW: - dashstuff = 1; /* trinary logic */ - continue; - case NBITSTUFFSW: - dashstuff = -1; /* trinary logic */ - continue; - } - } - if (*cp == '+' || *cp == '@') { - if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); - } else { - msgs[msgp++] = cp; - } - } - - cwd = getcpy (pwd ()); - - if (!context_find ("path")) - free (path ("./", TFOLDER)); - if (file && (msgp || folder)) - adios (NULL, "can't mix files and folders/msgs"); - -try_it_again: - -#ifdef MHE - strncpy (drft, buildsw ? m_maildir ("draft") - : m_draft (dfolder, NULL, NOUSE, &isdf), sizeof(drft)); - - /* Check if a draft already exists */ - if (!buildsw && stat (drft, &st) != NOTOK) { -#else - strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft)); - - /* Check if a draft already exists */ - if (stat (drft, &st) != NOTOK) { -#endif /* MHE */ - printf ("Draft \"%s\" exists (%ld bytes).", drft, (long) st.st_size); - for (i = LISTDSW; i != YESW;) { - if (!(argp = getans ("\nDisposition? ", isdf ? aqrnl : aqrl))) - done (1); - switch (i = smatch (*argp, isdf ? aqrnl : aqrl)) { - case NOSW: - done (0); - case NEWSW: - dmsg = NULL; - goto try_it_again; - case YESW: - break; - case LISTDSW: - showfile (++argp, drft); - break; - case REFILSW: - if (refile (++argp, drft) == 0) - i = YESW; - break; - default: - advise (NULL, "say what?"); - break; - } + int msgp = 0, anot = 0; + int issue = 0, volume = 0; + int in; + int out, msgnum; + char *cp, *cwd, *maildir; + char *digest = NULL, *ed = NULL; + char *folder = NULL; + char *form = NULL, buf[BUFSIZ], value[10]; + char **argp, **arguments, *msgs[MAXARGS]; + char *fmtstr; + int buildsw = 0; + + setlocale(LC_ALL, ""); + invo_name = mhbasename(argv[0]); + + /* read user profile/context */ + context_read(); + + arguments = getarguments(invo_name, argc, argv, 1); + argp = arguments; + + while ((cp = *argp++)) { + if (*cp == '-') { + switch (smatch(++cp, switches)) { + case AMBIGSW: + ambigsw(cp, switches); + exit(EX_USAGE); + case UNKWNSW: + adios(EX_USAGE, NULL, "-%s unknown", cp); + + case HELPSW: + snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name); + print_help(buf, switches, 1); + exit(argc == 2 ? EX_OK : EX_USAGE); + case VERSIONSW: + print_version(invo_name); + exit(argc == 2 ? EX_OK : EX_USAGE); + + case ANNOSW: + anot++; + continue; + case NANNOSW: + anot = 0; + continue; + + case EDITRSW: + if (!(ed = *argp++) || *ed == '-') + adios(EX_USAGE, NULL, "missing argument to %s", + argp[-2]); + continue; + + case WHATSW: + if (!(whatnowproc = *argp++) || + *whatnowproc == '-') + adios(EX_USAGE, NULL, "missing argument to %s", + argp[-2]); + continue; + + case BILDSW: + buildsw++; + continue; + + case FORMSW: + if (!(form = *argp++) || *form == '-') + adios(EX_USAGE, NULL, "missing argument to %s", + argp[-2]); + continue; + + case DGSTSW: + if (!(digest = *argp++) || *digest == '-') + adios(EX_USAGE, NULL, "missing argument to %s", + argp[-2]); + continue; + case ISSUESW: + if (!(cp = *argp++) || *cp == '-') + adios(EX_USAGE, NULL, "missing argument to %s", + argp[-2]); + if ((issue = atoi(cp)) < 1) + adios(EX_USAGE, NULL, "bad argument %s %s", + argp[-2], cp); + continue; + case VOLUMSW: + if (!(cp = *argp++) || *cp == '-') + adios(EX_USAGE, NULL, "missing argument to %s", + argp[-2]); + if ((volume = atoi(cp)) < 1) + adios(EX_USAGE, NULL, "bad argument %s %s", + argp[-2], cp); + continue; + } + } + if (*cp == '+' || *cp == '@') { + if (folder) + adios(EX_USAGE, NULL, "only one folder at a time!"); + else + folder = mh_xstrdup(expandfol(cp)); + } else { + msgs[msgp++] = cp; + } } - } - if (file) { + cwd = mh_xstrdup(pwd()); + strncpy(drft, buildsw ? toabsdir("draft") : m_draft(seq_beyond), + sizeof(drft)); /* - * Forwarding a file. - */ - anot = 0; /* don't want to annotate a file */ - } else { + ** FIXME: (concerning MHE support (buildsw) only) + ** There's no check if the draft already exists. mmh has removed + ** this case by having the draft folder. I won't add code only to + ** handle this legacy issue for MHE. -- meillo@marmaro.de 2012-05 + */ + /* - * Forwarding a message. - */ + ** Forwarding a message. + */ if (!msgp) - msgs[msgp++] = "cur"; + msgs[msgp++] = seq_cur; if (!folder) - folder = getfolder (1); - maildir = m_maildir (folder); + folder = getcurfol(); + maildir = toabsdir(folder); - if (chdir (maildir) == NOTOK) - adios (maildir, "unable to change directory to"); + if (chdir(maildir) == NOTOK) + adios(EX_OSERR, maildir, "unable to change directory to"); /* read folder and create message structure */ - if (!(mp = folder_read (folder))) - adios (NULL, "unable to read folder %s", folder); + if (!(mp = folder_read(folder))) + adios(EX_IOERR, NULL, "unable to read folder %s", folder); /* check for empty folder */ if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); + adios(EX_DATAERR, NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) - done (1); - seq_setprev (mp); /* set the previous sequence */ - } - - if (filter && access (filter, R_OK) == NOTOK) - adios (filter, "unable to read"); - - /* - * Open form (component) file. - */ - if (digest) { - if (issue == 0) { - snprintf (buf, sizeof(buf), IFORMAT, digest); - if (volume == 0 - && (cp = context_find (buf)) - && ((issue = atoi (cp)) < 0)) - issue = 0; - issue++; - } - if (volume == 0) - snprintf (buf, sizeof(buf), VFORMAT, digest); - if ((cp = context_find (buf)) == NULL || (volume = atoi (cp)) <= 0) - volume = 1; - if (!form) - form = digestcomps; - in = build_form (form, digest, volume, issue); - } else { - if (form) { - if ((in = open (etcpath (form), O_RDONLY)) == NOTOK) - adios (form, "unable to open form file"); - } else { - if ((in = open (etcpath (forwcomps), O_RDONLY)) == NOTOK) - adios (forwcomps, "unable to open default components file"); - form = forwcomps; + for (msgnum = 0; msgnum < msgp; msgnum++) { + if (!m_convert(mp, msgs[msgnum])) { + exit(EX_SOFTWARE); + } } - } - - if ((out = creat (drft, m_gmprot ())) == NOTOK) - adios (drft, "unable to create"); - - /* - * copy the components into the draft - */ - cpydata (in, out, form, drft); - close (in); - - if (file) { - /* just copy the file into the draft */ - if ((in = open (file, O_RDONLY)) == NOTOK) - adios (file, "unable to open"); - cpydata (in, out, file, drft); - close (in); - close (out); - } else { - /* - * If filter file is defined, then format the - * messages into the draft using mhlproc. - */ - if (filter) - mhl_draft (out, digest, volume, issue, drft, filter, dashstuff); - else if (mime) - copy_mime_draft (out); - else - copy_draft (out, digest, drft, volume, issue, dashstuff); - close (out); + seq_setprev(mp); /* set the previous sequence */ + if ((out = creat(drft, m_gmprot())) == NOTOK) + adios(EX_CANTCREAT, drft, "unable to create"); + + /* Open form (component) file. */ if (digest) { - snprintf (buf, sizeof(buf), IFORMAT, digest); - snprintf (value, sizeof(value), "%d", issue); - context_replace (buf, getcpy (value)); - snprintf (buf, sizeof(buf), VFORMAT, digest); - snprintf (value, sizeof(value), "%d", volume); - context_replace (buf, getcpy (value)); + if (issue == 0) { + snprintf(buf, sizeof(buf), IFORMAT, digest); + if (volume == 0 && (cp = context_find(buf)) + && ((issue = atoi(cp)) < 0)) + issue = 0; + issue++; + } + if (volume == 0) { + snprintf(buf, sizeof(buf), VFORMAT, digest); + if ((cp = context_find(buf)) == NULL || + (volume = atoi(cp)) <= 0) + volume = 1; + } + if (!form) + form = digestcomps; + in = build_form(form, digest, volume, issue); + cpydata(in, out, form, drft); + close(in); + } else { + fmtstr = new_fs(form, forwcomps); + if (write(out, fmtstr, strlen(fmtstr)) != (int)strlen(fmtstr)) { + adios(EX_IOERR, drft, "error writing"); + } } + close(out); - context_replace (pfolder, folder); /* update current folder */ - seq_setcur (mp, mp->lowsel); /* update current message */ - seq_save (mp); /* synchronize sequences */ - context_save (); /* save the context file */ - } - - if (nwhat) - done (0); - what_now (ed, nedit, NOUSE, drft, NULL, 0, mp, - anot ? "Forwarded" : NULL, inplace, cwd); - return done (1); -} + add_forw_hdr(drft); + if (digest) { + snprintf(buf, sizeof(buf), IFORMAT, digest); + snprintf(value, sizeof(value), "%d", issue); + context_replace(buf, mh_xstrdup(value)); + snprintf(buf, sizeof(buf), VFORMAT, digest); + snprintf(value, sizeof(value), "%d", volume); + context_replace(buf, mh_xstrdup(value)); + } -/* - * Filter the messages you are forwarding, into the - * draft calling the mhlproc, and reading its output - * from a pipe. - */ + context_replace(curfolder, folder); /* update current folder */ + seq_setcur(mp, mp->lowsel); /* update current message */ + seq_save(mp); /* synchronize sequences */ + context_save(); /* save the context file */ -static void -mhl_draft (int out, char *digest, int volume, int issue, - char *file, char *filter, int dashstuff) -{ - pid_t child_id; - int i, msgnum, pd[2]; - char *vec[MAXARGS]; - char buf1[BUFSIZ]; - char buf2[BUFSIZ]; - - if (pipe (pd) == NOTOK) - adios ("pipe", "unable to create"); - - vec[0] = r1bindex (mhlproc, '/'); - - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - switch (child_id) { - case NOTOK: - adios ("fork", "unable to"); - - case OK: - close (pd[0]); - dup2 (pd[1], 1); - close (pd[1]); - - i = 1; - vec[i++] = "-forwall"; - vec[i++] = "-form"; - vec[i++] = filter; - - if (digest) { - vec[i++] = "-digest"; - vec[i++] = digest; - vec[i++] = "-issue"; - snprintf (buf1, sizeof(buf1), "%d", issue); - vec[i++] = buf1; - vec[i++] = "-volume"; - snprintf (buf2, sizeof(buf2), "%d", volume); - vec[i++] = buf2; - } - - /* - * Are we dashstuffing (quoting) the lines that begin - * with `-'. We use the mhl default (don't add any flag) - * unless the user has specified a specific flag. - */ - if (dashstuff > 0) - vec[i++] = "-dashstuffing"; - else if (dashstuff < 0) - vec[i++] = "-nodashstuffing"; - - if (mp->numsel >= MAXARGS - i) - adios (NULL, "more than %d messages for %s exec", - vec[0], MAXARGS - i); - - /* - * Now add the message names to filter. We can only - * handle about 995 messages (because vec is fixed size), - * but that should be plenty. - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel && i < sizeof(vec) - 1; - msgnum++) - if (is_selected (mp, msgnum)) - vec[i++] = getcpy (m_name (msgnum)); - vec[i] = NULL; - - execvp (mhlproc, vec); - fprintf (stderr, "unable to exec "); - perror (mhlproc); - _exit (-1); - - default: - close (pd[1]); - cpydata (pd[0], out, vec[0], file); - close (pd[0]); - pidXwait(child_id, mhlproc); - break; - } + if (buildsw) + exit(EX_OK); + what_now(ed, NOUSE, drft, NULL, 0, mp, + anot ? "Forwarded" : NULL, cwd); + return EX_OSERR; } /* - * Copy the messages into the draft. The messages are - * not filtered through the mhlproc. Do dashstuffing if - * necessary. - */ - +** Create an attachment header for the to be forward messages. +*/ static void -copy_draft (int out, char *digest, char *file, int volume, int issue, int dashstuff) +add_forw_hdr(char *draft) { - int fd,i, msgcnt, msgnum; - int len, buflen; - register char *bp, *msgnam; - char buffer[BUFSIZ]; - - msgcnt = 1; - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - if (digest) { - strncpy (buffer, msgnum == mp->lowsel ? delim3 : delim4, - sizeof(buffer)); - } else { - /* Get buffer ready to go */ - bp = buffer; - buflen = sizeof(buffer); - - strncpy (bp, "\n-------", buflen); - len = strlen (bp); - bp += len; - buflen -= len; - - if (msgnum == mp->lowsel) { - snprintf (bp, buflen, " Forwarded Message%s", - mp->numsel > 1 ? "s" : ""); - } else { - snprintf (bp, buflen, " Message %d", msgcnt); + int msgnum; + char buf[BUFSIZ]; + char *vec[MAXARGS]; + int vecp = 0; + + vec[vecp++] = "anno"; + vec[vecp++] = "-append"; + vec[vecp++] = "-nodate"; + vec[vecp++] = draft; + vec[vecp++] = "-comp"; + vec[vecp++] = attach_hdr; + vec[vecp++] = "-text"; + snprintf(buf, sizeof buf, "+%s", mp->foldpath); + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { + if (!is_selected(mp, msgnum)) { + continue; + } + if (strlen(buf) + 1 + strlen(m_name(msgnum)) + 1 + > sizeof buf) { + adios(EX_DATAERR, NULL, "Attachment header line too long. " + "Forward less messages."); } - len = strlen (bp); - bp += len; - buflen -= len; - - strncpy (bp, "\n\n", buflen); - } - write (out, buffer, strlen (buffer)); - - if ((fd = open (msgnam = m_name (msgnum), O_RDONLY)) == NOTOK) { - admonish (msgnam, "unable to read message"); - continue; - } - - /* - * Copy the message. Add RFC934 quoting (dashstuffing) - * unless given the -nodashstuffing flag. - */ - if (dashstuff >= 0) - cpydgst (fd, out, msgnam, file); - else - cpydata (fd, out, msgnam, file); - - close (fd); - msgcnt++; + strcat(buf, " "); + strcat(buf, m_name(msgnum)); } - } - - if (digest) { - strncpy (buffer, delim4, sizeof(buffer)); - } else { - snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n\n", - mp->numsel > 1 ? "s" : ""); - } - write (out, buffer, strlen (buffer)); - - if (digest) { - snprintf (buffer, sizeof(buffer), "End of %s Digest [Volume %d Issue %d]\n", - digest, volume, issue); - i = strlen (buffer); - for (bp = buffer + i; i > 1; i--) - *bp++ = '*'; - *bp++ = '\n'; - *bp = 0; - write (out, buffer, strlen (buffer)); - } -} - - -/* - * Create a mhn composition file for forwarding message. - */ - -static void -copy_mime_draft (int out) -{ - int msgnum; - char buffer[BUFSIZ]; - - snprintf (buffer, sizeof(buffer), "#forw [forwarded message%s] +%s", - mp->numsel == 1 ? "" : "s", mp->foldpath); - write (out, buffer, strlen (buffer)); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) - if (is_selected (mp, msgnum)) { - snprintf (buffer, sizeof(buffer), " %s", m_name (msgnum)); - write (out, buffer, strlen (buffer)); + vec[vecp++] = buf; + vec[vecp] = NULL; + if (execprog(*vec, vec) != 0) { + advise(NULL, "unable to add attachment header"); } - write (out, "\n", 1); } static int -build_form (char *form, char *digest, int volume, int issue) +build_form(char *form, char *digest, int volume, int issue) { - int in; - int fmtsize; - register char *nfs; - char *line, tmpfil[BUFSIZ]; - register FILE *tmp; - register struct comp *cptr; - struct format *fmt; - int dat[5]; - - /* Get new format string */ - nfs = new_fs (form, NULL, NULL); - fmtsize = strlen (nfs) + 256; - - /* Compile format string */ - fmt_compile (nfs, &fmt); - - FINDCOMP (cptr, "digest"); - if (cptr) - cptr->c_text = digest; - FINDCOMP (cptr, "date"); - if (cptr) - cptr->c_text = getcpy(dtimenow (0)); - - dat[0] = issue; - dat[1] = volume; - dat[2] = 0; - dat[3] = fmtsize; - dat[4] = 0; - - strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil)); - if ((tmp = fopen (tmpfil, "w+")) == NULL) - adios (tmpfil, "unable to create"); - unlink (tmpfil); - if ((in = dup (fileno (tmp))) == NOTOK) - adios ("dup", "unable to"); - - if ((line = malloc ((unsigned) fmtsize)) == NULL) - adios (NULL, "unable to allocate format line storage"); - fmt_scan (fmt, line, fmtsize, dat); - fputs (line, tmp); - free (line); - if (fclose (tmp)) - adios (tmpfil, "error writing"); - - lseek (in, (off_t) 0, SEEK_SET); - return in; + int in; + int fmtsize; + char *fmtstr; + char *line, tmpfil[BUFSIZ]; + FILE *tmp; + struct comp *cptr; + struct format *fmt; + int dat[5]; + char *cp = NULL; + + /* Get new format string */ + fmtstr = new_fs(form, NULL); + fmtsize = strlen(fmtstr) + 256; + + /* Compile format string */ + fmt_compile(fmtstr, &fmt); + + FINDCOMP(cptr, "digest"); + if (cptr) + cptr->c_text = digest; + FINDCOMP(cptr, "date"); + if (cptr) + cptr->c_text = mh_xstrdup(dtimenow()); + + dat[0] = issue; + dat[1] = volume; + dat[2] = 0; + dat[3] = fmtsize; + dat[4] = 0; + + cp = m_mktemp2(NULL, invo_name, NULL, &tmp); + if (cp == NULL) { + adios(EX_CANTCREAT, "forw", "unable to create temporary file"); + } + strncpy(tmpfil, cp, sizeof(tmpfil)); + unlink(tmpfil); + if ((in = dup(fileno(tmp))) == NOTOK) + adios(EX_OSERR, "dup", "unable to"); + + line = mh_xcalloc(fmtsize, sizeof(char)); + fmt_scan(fmt, line, fmtsize, dat); + fputs(line, tmp); + mh_free0(&line); + if (fclose(tmp)) + adios(EX_IOERR, tmpfil, "error writing"); + + lseek(in, (off_t) 0, SEEK_SET); + return in; }