X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fforw.c;h=a04ebd6f9b9a4713f1c46aa81035f976541361f7;hb=a6f717992d5588898c37711aa1895dbb11016e1c;hp=93870b1af0c5c91e9cf1bc9738adb7536de5ccf4;hpb=b439ec143c4d2e2daf4b0a9c332123f24500cd9a;p=mmh diff --git a/uip/forw.c b/uip/forw.c index 93870b1..a04ebd6 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -2,8 +2,6 @@ /* * forw.c -- forward a message, or group of messages. * - * $Id$ - * * 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. @@ -11,7 +9,6 @@ #include #include -#include #include #include @@ -70,12 +67,20 @@ static struct swit switches[] = { { "help", 0 }, #define FILESW 24 { "file file", 4 }, /* interface from msh */ - -#ifdef MHE #define BILDSW 25 { "build", 5 }, /* interface from mhe */ -#endif /* MHE */ - +#define FROMSW 26 + { "from address", 0 }, +#define TOSW 27 + { "to address", 0 }, +#define CCSW 28 + { "cc address", 0 }, +#define SUBJECTSW 29 + { "subject text", 0 }, +#define FCCSW 30 + { "fcc mailbox", 0 }, +#define WIDTHSW 31 + { "width columns", 0 }, { NULL, 0 } }; @@ -117,7 +122,6 @@ static struct msgs *mp = NULL; /* used a lot */ 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); int @@ -126,17 +130,18 @@ 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; + int out, isdf = 0, msgnum = 0; + int outputlinelen = OUTPUTLINELEN; + int dat[5]; char *cp, *cwd, *maildir, *dfolder = NULL; char *dmsg = NULL, *digest = NULL, *ed = NULL; - char *file = NULL, *filter = NULL, *folder = NULL; + char *file = NULL, *filter = NULL, *folder = NULL, *fwdmsg = NULL; + char *from = NULL, *to = NULL, *cc = NULL, *subject = NULL, *fcc = 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, ""); @@ -162,10 +167,10 @@ main (int argc, char **argv) snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name); print_help (buf, switches, 1); - done (1); + done (0); case VERSIONSW: print_version(invo_name); - done (1); + done (0); case ANNOSW: anot++; @@ -188,10 +193,8 @@ main (int argc, char **argv) adios (NULL, "missing argument to %s", argp[-2]); nwhat = 0; continue; -#ifdef MHE case BILDSW: buildsw++; /* fall... */ -#endif /* MHE */ case NWHATSW: nwhat++; continue; @@ -237,8 +240,9 @@ main (int argc, char **argv) continue; case DGSTSW: - if (!(digest = *argp++) || *digest == '-') + if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); + digest = getcpy(cp); mime = 0; continue; case ISSUESW: @@ -279,13 +283,46 @@ main (int argc, char **argv) case NBITSTUFFSW: dashstuff = -1; /* trinary logic */ continue; + + case FROMSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + from = addlist(from, cp); + continue; + case TOSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + to = addlist(to, cp); + continue; + case CCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + cc = addlist(cc, cp); + continue; + case FCCSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + fcc = addlist(fcc, cp); + continue; + case SUBJECTSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + subject = getcpy(cp); + continue; + + case WIDTHSW: + if (!(cp = *argp++) || *cp == '-') + adios (NULL, "missing argument to %s", argp[-2]); + if ((outputlinelen = atoi(cp)) < 10) + adios (NULL, "impossible width %d", outputlinelen); + continue; } } if (*cp == '+' || *cp == '@') { if (folder) adios (NULL, "only one folder at a time!"); else - folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF); + folder = pluspath (cp); } else { msgs[msgp++] = cp; } @@ -300,18 +337,11 @@ main (int argc, char **argv) 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))) @@ -369,6 +399,20 @@ try_it_again: if (!m_convert (mp, msgs[msgnum])) done (1); seq_setprev (mp); /* set the previous sequence */ + + /* + * Find the first message in our set and use it as the input + * for the component scanner + */ + + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) + if (is_selected (mp, msgnum)) { + fwdmsg = strdup(m_name(msgnum)); + break; + } + + if (! fwdmsg) + adios (NULL, "Unable to find input message"); } if (filter && access (filter, R_OK) == NOTOK) @@ -386,15 +430,27 @@ try_it_again: issue = 0; issue++; } - if (volume == 0) + if (volume == 0) { snprintf (buf, sizeof(buf), VFORMAT, digest); - if ((cp = context_find (buf)) == NULL || (volume = atoi (cp)) <= 0) - volume = 1; + if ((cp = context_find (buf)) == NULL || (volume = atoi (cp)) <= 0) + volume = 1; + } if (!form) form = digestcomps; - in = build_form (form, digest, volume, issue); - } else - in = open_form(&form, forwcomps); + } else { + if (!form) + form = forwcomps; + } + + dat[0] = digest ? issue : msgnum; + dat[1] = volume; + dat[2] = 0; + dat[3] = outputlinelen; + dat[4] = 0; + + + in = build_form (form, digest, dat, from, to, cc, fcc, subject, + file ? file : fwdmsg); if ((out = creat (drft, m_gmprot ())) == NOTOK) adios (drft, "unable to create"); @@ -443,8 +499,9 @@ try_it_again: if (nwhat) done (0); what_now (ed, nedit, NOUSE, drft, NULL, 0, mp, - anot ? "Forwarded" : NULL, inplace, cwd); - return done (1); + anot ? "Forwarded" : NULL, inplace, cwd, 0); + done (1); + return 1; } @@ -508,15 +565,16 @@ mhl_draft (int out, char *digest, int volume, int issue, if (mp->numsel >= MAXARGS - i) adios (NULL, "more than %d messages for %s exec", - vec[0], MAXARGS - i); + MAXARGS - i, vec[0]); /* * 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++) + for (msgnum = mp->lowsel; + msgnum <= mp->hghsel && i < (int) sizeof(vec) - 1; + msgnum++) if (is_selected (mp, msgnum)) vec[i++] = getcpy (m_name (msgnum)); vec[i] = NULL; @@ -602,7 +660,7 @@ copy_draft (int out, char *digest, char *file, int volume, int issue, int dashst if (digest) { strncpy (buffer, delim4, sizeof(buffer)); } else { - snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n\n", + snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n", mp->numsel > 1 ? "s" : ""); } write (out, buffer, strlen (buffer)); @@ -640,54 +698,3 @@ copy_mime_draft (int out) } write (out, "\n", 1); } - - -static int -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"); - - line = mh_xmalloc ((unsigned) fmtsize); - 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; -}