-
-/*
- * forw.c -- forward a message, or group of messages.
+/* 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 <h/mh.h>
+#include "h/mh.h"
+#include "sbr/folder_read.h"
+#include "sbr/context_save.h"
+#include "sbr/context_replace.h"
+#include "sbr/context_find.h"
+#include "sbr/ambigsw.h"
+#include "sbr/pidstatus.h"
+#include "sbr/path.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/arglist.h"
+#include "sbr/error.h"
#include <fcntl.h>
-#include <h/tws.h>
-#include <h/utils.h>
+#include "h/tws.h"
+#include "h/done.h"
+#include "h/utils.h"
+#include "sbr/m_maildir.h"
+#include "forwsbr.h"
#define IFORMAT "digest-issue-%s"
X("nodashstuffing", 0, NBITSTUFFSW) \
X("version", 0, VERSIONSW) \
X("help", 0, HELPSW) \
- X("file file", 4, FILESW) /* interface from msh */ \
+ X("file file", 4, FILESW) \
X("build", 5, BILDSW) /* interface from mhe */ \
X("from address", 0, FROMSW) \
X("to address", 0, TOSW) \
int
main (int argc, char **argv)
{
- int anot = 0, inplace = 1, mime = 0;
+ bool anot = false;
+ bool inplace = true;
+ bool mime = false;
int issue = 0, volume = 0, dashstuff = 0;
- int nedit = 0, nwhat = 0, i, in;
+ bool nedit = false;
+ bool nwhat = false;
+ int i, in;
int out, isdf = 0, msgnum = 0;
int outputlinelen = OUTPUTLINELEN;
int dat[5];
char *dmsg = NULL, *digest = NULL, *ed = 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 *form = NULL, buf[BUFSIZ];
char **argp, **arguments;
struct stat st;
struct msgs_array msgs = { 0, 0, NULL };
- int buildsw = 0;
+ bool buildsw = false;
- if (nmh_init(argv[0], 1)) { return 1; }
+ if (nmh_init(argv[0], true, true)) { return 1; }
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
ambigsw (cp, switches);
done (1);
case UNKWNSW:
- adios (NULL, "-%s unknown", cp);
+ die("-%s unknown", cp);
case HELPSW:
snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
done (0);
case ANNOSW:
- anot++;
+ anot = true;
continue;
case NANNOSW:
- anot = 0;
+ anot = false;
continue;
case EDITRSW:
if (!(ed = *argp++) || *ed == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- nedit = 0;
+ die("missing argument to %s", argp[-2]);
+ nedit = false;
continue;
case NEDITSW:
- nedit++;
+ nedit = true;
continue;
case WHATSW:
if (!(whatnowproc = *argp++) || *whatnowproc == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- nwhat = 0;
+ die("missing argument to %s", argp[-2]);
+ nwhat = false;
continue;
case BILDSW:
- buildsw++;
+ buildsw = true;
/* FALLTHRU */
case NWHATSW:
- nwhat++;
+ nwhat = true;
continue;
case FILESW:
if (file)
- adios (NULL, "only one file at a time!");
+ die("only one file at a time!");
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("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;
+ die("missing argument to %s", argp[-2]);
+ filter = mh_xstrdup(etcpath(cp));
+ mime = false;
continue;
case FORMSW:
if (!(form = *argp++) || *form == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("missing argument to %s", argp[-2]);
continue;
case FRMTSW:
- filter = getcpy (etcpath (mhlforward));
+ filter = mh_xstrdup(etcpath(mhlforward));
continue;
case NFRMTSW:
filter = NULL;
continue;
case INPLSW:
- inplace++;
+ inplace = true;
continue;
case NINPLSW:
- inplace = 0;
+ inplace = false;
continue;
case MIMESW:
- mime++;
+ mime = true;
filter = NULL;
continue;
case NMIMESW:
- mime = 0;
+ mime = false;
continue;
case DGSTSW:
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("missing argument to %s", argp[-2]);
digest = mh_xstrdup(cp);
- mime = 0;
+ mime = false;
continue;
case ISSUESW:
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("missing argument to %s", argp[-2]);
if ((issue = atoi (cp)) < 1)
- adios (NULL, "bad argument %s %s", argp[-2], cp);
+ die("bad argument %s %s", argp[-2], cp);
continue;
case VOLUMSW:
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("missing argument to %s", argp[-2]);
if ((volume = atoi (cp)) < 1)
- adios (NULL, "bad argument %s %s", argp[-2], cp);
+ die("bad argument %s %s", argp[-2], cp);
continue;
case DFOLDSW:
if (dfolder)
- adios (NULL, "only one draft folder at a time!");
+ die("only one draft folder at a time!");
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("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!");
+ die("only one draft message at a time!");
if (!(dmsg = *argp++) || *dmsg == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("missing argument to %s", argp[-2]);
continue;
case NDFLDSW:
dfolder = NULL;
continue;
case BITSTUFFSW:
- dashstuff = 1; /* trinary logic */
+ dashstuff = 1; /* ternary logic */
continue;
case NBITSTUFFSW:
- dashstuff = -1; /* trinary logic */
+ dashstuff = -1; /* ternary logic */
continue;
case FROMSW:
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("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]);
+ die("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]);
+ die("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]);
+ die("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]);
+ die("missing argument to %s", argp[-2]);
subject = mh_xstrdup(cp);
continue;
case WIDTHSW:
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("missing argument to %s", argp[-2]);
if ((outputlinelen = atoi(cp)) < 10)
- adios (NULL, "impossible width %d", outputlinelen);
+ die("impossible width %d", outputlinelen);
continue;
}
}
if (*cp == '+' || *cp == '@') {
if (folder)
- adios (NULL, "only one folder at a time!");
- else
- folder = pluspath (cp);
+ die("only one folder at a time!");
+ folder = pluspath (cp);
} else {
app_msgarg(&msgs, cp);
}
if (!context_find ("path"))
free (path ("./", TFOLDER));
if (file && (msgs.size || folder))
- adios (NULL, "can't mix files and folders/msgs");
+ die("can't mix files and folders/msgs");
try_it_again:
i = YESW;
break;
default:
- advise (NULL, "say what?");
+ inform("say what?");
break;
}
}
/*
* Forwarding a file.
*/
- anot = 0; /* don't want to annotate a file */
+ anot = false; /* don't want to annotate a file */
} else {
/*
* Forwarding a message.
/* read folder and create message structure */
if (!(mp = folder_read (folder, 1)))
- adios (NULL, "unable to read folder %s", folder);
+ die("unable to read folder %s", folder);
/* check for empty folder */
if (mp->nummsg == 0)
- adios (NULL, "no messages in %s", folder);
+ die("no messages in %s", folder);
/* parse all the message ranges/sequences and set SELECTED */
for (msgnum = 0; msgnum < msgs.size; msgnum++)
}
if (! fwdmsg)
- adios (NULL, "Unable to find input message");
+ die("Unable to find input message");
}
if (filter && access (filter, R_OK) == NOTOK)
if (digest) {
snprintf (buf, sizeof(buf), IFORMAT, digest);
- snprintf (value, sizeof(value), "%d", issue);
- context_replace (buf, mh_xstrdup(value));
+ context_replace (buf, mh_xstrdup(m_str(issue)));
snprintf (buf, sizeof(buf), VFORMAT, digest);
- snprintf (value, sizeof(value), "%d", volume);
- context_replace (buf, mh_xstrdup(value));
+ context_replace (buf, mh_xstrdup(m_str(volume)));
}
context_replace (pfolder, folder); /* update current folder */
char *file, char *filter, int dashstuff)
{
pid_t child_id;
- int i, msgnum, pd[2];
+ int msgnum, pd[2];
char buf1[BUFSIZ];
char buf2[BUFSIZ];
char *program;
argsplit_msgarg(&vec, mhlproc, &program);
- for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
- sleep (5);
-
+ child_id = fork();
switch (child_id) {
case NOTOK:
adios ("fork", "unable to");
execvp (program, vec.msgs);
fprintf (stderr, "unable to exec ");
perror (mhlproc);
- _exit (-1);
+ _exit(1);
default:
close (pd[1]);
if (msgnum == mp->lowsel) {
snprintf (bp, buflen, " Forwarded Message%s",
- mp->numsel > 1 ? "s" : "");
+ PLURALS(mp->numsel));
} else {
snprintf (bp, buflen, " Message %d", msgcnt);
}
strncpy (buffer, delim4, sizeof(buffer));
} else {
snprintf (buffer, sizeof(buffer), "\n------- End of Forwarded Message%s\n",
- mp->numsel > 1 ? "s" : "");
+ PLURALS(mp->numsel));
}
if (write (out, buffer, strlen (buffer)) < 0) {
advise (drft, "write");
char buffer[BUFSIZ];
snprintf (buffer, sizeof(buffer), "#forw [forwarded message%s] +%s",
- mp->numsel == 1 ? "" : "s", mp->foldpath);
+ PLURALS(mp->numsel), mp->foldpath);
if (write (out, buffer, strlen (buffer)) < 0) {
advise (drft, "write");
}