-/*
- * show.c -- show/list messages
+/* show.c -- show/list 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/mime.h>
-#include <h/utils.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/path.h"
+#include "sbr/print_version.h"
+#include "sbr/print_help.h"
+#include "sbr/arglist.h"
+#include "sbr/error.h"
+#include "h/mime.h"
+#include "h/done.h"
+#include "h/utils.h"
+#include "sbr/m_maildir.h"
#define SHOW_SWITCHES \
X("checkmime", 0, CHECKMIMESW) \
int
main (int argc, char **argv)
{
- int draftsw = 0, headersw = 1;
- int nshow = 0, checkmime = 1, mime = 0;
+ bool draftsw = false;
+ bool headersw = true;
+ bool nshow = false;
+ bool checkmime = true;
+ bool mime = false;
int isdf = 0, mode = SHOW, msgnum;
char *cp, *maildir, *file = NULL, *folder = NULL, *proc, *program;
char buf[BUFSIZ], **argp, **arguments;
struct msgs_array msgs = { 0, 0, NULL };
struct msgs_array vec = { 0, 0, NULL }, non_mhl_vec = { 0, 0, NULL };
- if (nmh_init(argv[0], 1)) { return 1; }
+ if (nmh_init(argv[0], true, true)) { return 1; }
if (!strcasecmp (invo_name, "next")) {
mode = NEXT;
done (1);
case HEADSW:
- headersw = 1;
+ headersw = true;
goto non_mhl_switches;
case NHEADSW:
- headersw = 0;
+ headersw = false;
+ /* FALLTHRU */
case CONCATSW:
case NCONCATSW:
non_mhl_switches:
case DRFTSW:
if (file)
- adios (NULL, "only one file at a time!");
- draftsw++;
+ die("only one file at a time!");
+ draftsw = true;
if (mode == SHOW)
continue;
usage:
- adios (NULL,
- "usage: %s [+folder] [switches] [switches for showproc]",
+ die( "usage: %s [+folder] [switches] [switches for showproc]",
invo_name);
case FILESW:
if (mode != SHOW)
goto usage;
if (draftsw || 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 FORMSW:
app_msgarg(&vec, --cp);
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- app_msgarg(&vec, getcpy (etcpath(cp)));
+ die("missing argument to %s", argp[-2]);
+ app_msgarg(&vec, mh_xstrdup(etcpath(cp)));
continue;
case PROGSW:
case WCACHESW:
app_msgarg(&vec, --cp);
if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
+ die("missing argument to %s", argp[-2]);
app_msgarg(&vec, cp);
continue;
case SHOWSW:
if (!(showproc = *argp++) || *showproc == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- nshow = 0;
+ die("missing argument to %s", argp[-2]);
+ nshow = false;
continue;
case NSHOWSW:
- nshow++;
+ nshow = true;
continue;
case SHOWMIMESW:
if (!(showmimeproc = *argp++) || *showmimeproc == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- nshow = 0;
+ die("missing argument to %s", argp[-2]);
+ nshow = false;
continue;
case CHECKMIMESW:
- checkmime++;
+ checkmime = true;
continue;
case NOCHECKMIMESW:
- checkmime = 0;
+ checkmime = false;
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 {
if (mode != SHOW)
goto usage;
if (draftsw || file) {
if (msgs.size)
- adios (NULL, "only one file at a time!");
+ die("only one file at a time!");
if (draftsw)
- app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf)));
+ app_msgarg(&vec, mh_xstrdup(m_draft(folder, NULL, 1, &isdf)));
else
app_msgarg(&vec, file);
- headersw = 0;
+ headersw = false;
goto go_to_it;
}
/* 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++)
/* loop through selected messages and check for MIME */
for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
if (is_selected (mp, msgnum) && is_nontext (m_name (msgnum))) {
- mime = 1;
+ mime = true;
break;
}
} else {
/* check the file or draft for MIME */
if (is_nontext (vec.msgs[vec.size - 1]))
- mime = 1;
+ mime = true;
}
}
}
if (folder && !draftsw && !file)
- m_putenv ("mhfolder", folder);
+ setenv("mhfolder", folder, 1);
if (strcmp (r1bindex (proc, '/'), "cat") == 0) {
{
int result, state;
char *bp, *dp, *cp;
- char buf[BUFSIZ], name[NAMESZ];
+ char buf[NMH_BUFSIZ], name[NAMESZ];
FILE *fp;
- m_getfld_state_t gstate = 0;
+ m_getfld_state_t gstate;
if ((fp = fopen (msgnam, "r")) == NULL)
return 0;
-
+ gstate = m_getfld_state_init(fp);
for (;;) {
int bufsz = sizeof buf;
- switch (state = m_getfld (&gstate, name, buf, &bufsz, fp)) {
+ switch (state = m_getfld2(&gstate, name, buf, &bufsz)) {
case FLD:
case FLDPLUS:
/*
int passno;
char c;
- cp = add (buf, NULL);
+ cp = mh_xstrdup(buf);
while (state == FLDPLUS) {
bufsz = sizeof buf;
- state = m_getfld (&gstate, name, buf, &bufsz, fp);
+ state = m_getfld2(&gstate, name, buf, &bufsz);
cp = add (buf, cp);
}
bp = cp;
continue;
case '(':
i++;
- /* and fall... */
+ continue;
default:
continue;
case ')':
* Check Content-Transfer-Encoding field
*/
if (!strcasecmp (name, ENCODING_FIELD)) {
- cp = add (buf, NULL);
+ cp = mh_xstrdup(buf);
while (state == FLDPLUS) {
bufsz = sizeof buf;
- state = m_getfld (&gstate, name, buf, &bufsz, fp);
+ state = m_getfld2(&gstate, name, buf, &bufsz);
cp = add (buf, cp);
}
for (bp = cp; isspace ((unsigned char) *bp); bp++)
*/
while (state == FLDPLUS) {
bufsz = sizeof buf;
- state = m_getfld (&gstate, name, buf, &bufsz, fp);
+ state = m_getfld2(&gstate, name, buf, &bufsz);
}
break;