/*
* 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.
*/
#include <h/mh.h>
#include <fcntl.h>
#include <h/fmt_scan.h>
-#include <zotnet/tws/tws.h>
+#include <h/tws.h>
+#include <h/utils.h>
#define IFORMAT "digest-issue-%s"
#define VERSIONSW 22
{ "version", 0 },
#define HELPSW 23
- { "help", 4 },
+ { "help", 0 },
#define FILESW 24
- { "file file", -4 }, /* interface from msh */
-
-#ifdef MHE
+ { "file file", 4 }, /* interface from msh */
#define BILDSW 25
- { "build", -5 }, /* interface from mhe */
-#endif /* MHE */
+ { "build", 5 }, /* interface from mhe */
{ NULL, 0 }
};
char **argp, **arguments, *msgs[MAXARGS];
struct stat st;
-#ifdef MHE
int buildsw = 0;
-#endif /* MHE */
#ifdef LOCALE
setlocale(LC_ALL, "");
adios (NULL, "missing argument to %s", argp[-2]);
nwhat = 0;
continue;
-#ifdef MHE
case BILDSW:
buildsw++; /* fall... */
-#endif /* MHE */
case NWHATSW:
nwhat++;
continue;
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;
}
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)))
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;
- }
- }
+ } else
+ in = open_form(&form, forwcomps);
if ((out = creat (drft, m_gmprot ())) == NOTOK)
adios (drft, "unable to create");
done (0);
what_now (ed, nedit, NOUSE, drft, NULL, 0, mp,
anot ? "Forwarded" : NULL, inplace, cwd);
- return done (1);
+ done (1);
+ return 1;
}
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;
int fmtsize;
register char *nfs;
char *line, tmpfil[BUFSIZ];
- register FILE *tmp;
+ FILE *tmp;
register struct comp *cptr;
struct format *fmt;
int dat[5];
+ char *cp = NULL;
/* Get new format string */
nfs = new_fs (form, NULL, NULL);
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");
+ cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
+ if (cp == NULL) adios("forw", "unable to create temporary file");
+ strncpy (tmpfil, cp, sizeof(tmpfil));
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");
+ line = mh_xmalloc ((unsigned) fmtsize);
fmt_scan (fmt, line, fmtsize, dat);
fputs (line, tmp);
free (line);