-
/*
* show.c -- show/list messages
*
X("nofmtproc", 0, NFMTPROCSW) \
X("version", 0, VERSIONSW) \
X("help", 0, HELPSW) \
+ /* \
+ * switches for mhlproc \
+ */ \
+ X("concat", 0, CONCATSW) \
+ X("noconcat", 0, NCONCATSW) \
+ /* \
+ * switches for mhshow \
+ */ \
+ X("part number", 0, PARTSW) \
+ X("type content", 0, TYPESW) \
+ X("prefer content", 0, PREFERSW) \
+ X("markform file", 0, MARKFORMSW) \
+ X("rcache policy", 0, RCACHESW) \
+ X("wcache policy", 0, WCACHESW) \
#define X(sw, minchars, id) id,
DEFINE_SWITCH_ENUM(SHOW);
main (int argc, char **argv)
{
int draftsw = 0, headersw = 1;
- int nshow = 0, checkmime = 1, mime;
+ int nshow = 0, checkmime = 1, mime = 0;
int isdf = 0, mode = SHOW, msgnum;
- char *cp, *maildir, *file = NULL, *folder = NULL, *proc;
+ char *cp, *maildir, *file = NULL, *folder = NULL, *proc, *program;
char buf[BUFSIZ], **argp, **arguments;
struct msgs *mp = NULL;
struct msgs_array msgs = { 0, 0, NULL };
- struct msgs_array vec = { 0, 0, NULL };
-
-#ifdef LOCALE
- setlocale(LC_ALL, "");
-#endif
- invo_name = r1bindex (argv[0], '/');
-
- app_msgarg(&vec, NULL); /* placeholder, filled later with proc name */
+ struct msgs_array vec = { 0, 0, NULL }, non_mhl_vec = { 0, 0, NULL };
- /* read user profile/context */
- context_read();
+ if (nmh_init(argv[0], 1)) { return 1; }
- if (!mh_strcasecmp (invo_name, "next")) {
+ if (!strcasecmp (invo_name, "next")) {
mode = NEXT;
- } else if (!mh_strcasecmp (invo_name, "prev")) {
+ } else if (!strcasecmp (invo_name, "prev")) {
mode = PREV;
}
arguments = getarguments (invo_name, argc, argv, 1);
while ((cp = *argp++)) {
if (*cp == '-') {
switch (smatch (++cp, switches)) {
- case AMBIGSW:
+ case AMBIGSW:
ambigsw (cp, switches);
done (1);
- case UNKWNSW:
+
+ case HEADSW:
+ headersw = 1;
+ goto non_mhl_switches;
+ case NHEADSW:
+ headersw = 0;
+ case CONCATSW:
+ case NCONCATSW:
+non_mhl_switches:
+ /* mhl can't handle these, so keep them separate. */
+ app_msgarg(&non_mhl_vec, --cp);
+ continue;
+
+ case UNKWNSW:
case NPROGSW:
case NFMTPROCSW:
app_msgarg(&vec, --cp);
continue;
- case HELPSW:
+ case HELPSW:
snprintf (buf, sizeof(buf),
"%s [+folder] %s[switches] [switches for showproc]",
invo_name, mode == SHOW ? "[msgs] ": "");
print_version(invo_name);
done (0);
- case DRFTSW:
+ case DRFTSW:
if (file)
adios (NULL, "only one file at a time!");
draftsw++;
adios (NULL,
"usage: %s [+folder] [switches] [switches for showproc]",
invo_name);
- case FILESW:
+ case FILESW:
if (mode != SHOW)
goto usage;
if (draftsw || file)
file = path (cp, TFILE);
continue;
- case HEADSW:
- headersw++;
- continue;
- case NHEADSW:
- headersw = 0;
- continue;
-
case FORMSW:
app_msgarg(&vec, --cp);
if (!(cp = *argp++) || *cp == '-')
case LENSW:
case WIDTHSW:
case FMTPROCSW:
+ case PARTSW:
+ case TYPESW:
+ case PREFERSW:
+ case MARKFORMSW:
+ case RCACHESW:
+ case WCACHESW:
app_msgarg(&vec, --cp);
if (!(cp = *argp++) || *cp == '-')
adios (NULL, "missing argument to %s", argp[-2]);
app_msgarg(&vec, cp);
continue;
- case SHOWSW:
+ case SHOWSW:
if (!(showproc = *argp++) || *showproc == '-')
adios (NULL, "missing argument to %s", argp[-2]);
nshow = 0;
continue;
- case NSHOWSW:
+ case NSHOWSW:
nshow++;
continue;
} else {
if (mode != SHOW)
goto usage;
- else
- app_msgarg(&msgs, cp);
+ app_msgarg(&msgs, cp);
}
}
app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf)));
else
app_msgarg(&vec, file);
+ headersw = 0;
goto go_to_it;
}
-#ifdef WHATNOW
- if (!msgs.size && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) {
- draftsw++;
- app_msgarg(&vec, cp);
- goto go_to_it;
- }
-#endif /* WHATNOW */
-
if (!msgs.size) {
switch (mode) {
case NEXT:
adios (maildir, "unable to change directory to");
/* read folder and create message structure */
- if (!(mp = folder_read (folder)))
+ if (!(mp = folder_read (folder, 1)))
adios (NULL, "unable to read folder %s", folder);
/* check for empty folder */
for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
if (is_selected(mp, msgnum))
- app_msgarg(&vec, getcpy (m_name (msgnum)));
+ app_msgarg(&vec, mh_xstrdup(m_name (msgnum)));
seq_setcur (mp, mp->hghsel); /* update current message */
seq_save (mp); /* synchronize sequences */
context_replace (pfolder, folder); /* update current folder */
context_save (); /* save the context file */
- if (headersw && vec.size == 2)
- printf ("(Message %s:%s)\n", folder, vec.msgs[1]);
-
go_to_it: ;
- fflush (stdout);
/*
* Decide which "proc" to use
*/
- mime = 0;
if (nshow) {
proc = catproc;
} else {
/* check if any messages are non-text MIME messages */
- if (checkmime) {
+ if (! mime && checkmime) {
if (!draftsw && !file) {
/* loop through selected messages and check for MIME */
for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
if (folder && !draftsw && !file)
m_putenv ("mhfolder", folder);
- if (strcmp (r1bindex (proc, '/'), "mhn") == 0) {
- /* Add "-file" if showing file or draft, */
- if (draftsw || file) {
- app_msgarg(&vec, vec.msgs[vec.size - 1]);
- vec.msgs[vec.size - 2] = "-file";
- }
- /* and add -show for backward compatibility */
- app_msgarg(&vec, "-show");
- } else if (strcmp (r1bindex (proc, '/'), "mhshow") == 0) {
- /* If "mhshow", add "-file" if showing file or draft. */
- if (draftsw || file) {
- app_msgarg(&vec, vec.msgs[vec.size - 1]);
- vec.msgs[vec.size - 2] = "-file";
- }
+ if (strcmp (r1bindex (proc, '/'), "cat") == 0) {
+
+ if (headersw && vec.size == 1)
+ printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
+
} else if (strcmp (r1bindex (proc, '/'), "mhl") == 0) {
+
+ if (headersw && vec.size == 1)
+ printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
+
/* If "mhl", then run it internally */
- vec.msgs[0] = "mhl";
+ argsplit_insert(&vec, "mhl", &program);
app_msgarg(&vec, NULL);
mhl (vec.size, vec.msgs);
done (0);
+
+ } else {
+ int i;
+ char **mp;
+
+ for (i = 0, mp = non_mhl_vec.msgs; i < non_mhl_vec.size; ++i, ++mp) {
+ if (draftsw || file) {
+ /* Insert the switch before the filename. */
+ app_msgarg(&vec, vec.msgs[vec.size - 1]);
+ vec.msgs[vec.size - 2] = *mp;
+ } else {
+ app_msgarg(&vec, *mp);
+ }
+ }
+
+ if (strcmp (r1bindex (proc, '/'), "mhn") == 0) {
+ /* Add "-file" if showing file or draft, */
+ if (draftsw || file) {
+ app_msgarg(&vec, vec.msgs[vec.size - 1]);
+ vec.msgs[vec.size - 2] = "-file";
+ }
+ /* and add -show for backward compatibility */
+ app_msgarg(&vec, "-show");
+ } else if (strcmp (r1bindex (proc, '/'), "mhshow") == 0) {
+ /* If "mhshow", add "-file" if showing file or draft. */
+ if (draftsw || file) {
+ app_msgarg(&vec, vec.msgs[vec.size - 1]);
+ vec.msgs[vec.size - 2] = "-file";
+ }
+ } else {
+ if (headersw && vec.size == 1)
+ printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
+ }
}
- vec.msgs[0] = r1bindex (proc, '/');
+ fflush (stdout);
+
+ argsplit_insert(&vec, proc, &program);
app_msgarg(&vec, NULL);
- execvp (proc, vec.msgs);
+ execvp (program, vec.msgs);
adios (proc, "unable to exec");
return 0; /* dead code to satisfy the compiler */
}
is_nontext (char *msgnam)
{
int result, state;
- unsigned char *bp, *dp;
- char *cp;
+ char *bp, *dp, *cp;
char buf[BUFSIZ], name[NAMESZ];
FILE *fp;
m_getfld_state_t gstate = 0;
/*
* Check Content-Type field
*/
- if (!mh_strcasecmp (name, TYPE_FIELD)) {
+ if (!strcasecmp (name, TYPE_FIELD)) {
int passno;
char c;
passno = 1;
again:
- for (; isspace (*bp); bp++)
+ for (; isspace ((unsigned char) *bp); bp++)
continue;
if (*bp == '(') {
int i;
if (!*bp)
goto invalid;
if (passno > 1) {
- if ((result = (mh_strcasecmp (bp, "plain") != 0)))
+ if ((result = (strcasecmp (bp, "plain") != 0)))
goto out;
*dp = c;
- for (dp++; isspace (*dp); dp++)
+ for (dp++; isspace ((unsigned char) *dp); dp++)
continue;
if (*dp) {
if ((result = !uprf (dp, "charset")))
goto out;
- dp += sizeof("charset") - 1;
- while (isspace (*dp))
+ dp += LEN("charset");
+ while (isspace ((unsigned char) *dp))
dp++;
if (*dp++ != '=')
goto invalid;
- while (isspace (*dp))
+ while (isspace ((unsigned char) *dp))
dp++;
if (*dp == '"') {
if ((bp = strchr(++dp, '"')))
/* Check the character set */
result = !check_charset (dp, strlen (dp));
} else {
- if (!(result = (mh_strcasecmp (bp, "text") != 0))) {
+ if (!(result = (strcasecmp (bp, "text") != 0))) {
*dp = c;
bp = dp;
passno = 2;
free (cp);
if (result) {
fclose (fp);
+ m_getfld_state_destroy (&gstate);
return result;
}
break;
/*
* Check Content-Transfer-Encoding field
*/
- if (!mh_strcasecmp (name, ENCODING_FIELD)) {
+ if (!strcasecmp (name, ENCODING_FIELD)) {
cp = add (buf, NULL);
while (state == FLDPLUS) {
bufsz = sizeof buf;
state = m_getfld (&gstate, name, buf, &bufsz, fp);
cp = add (buf, cp);
}
- for (bp = cp; isspace (*bp); bp++)
+ for (bp = cp; isspace ((unsigned char) *bp); bp++)
continue;
- for (dp = bp; istoken (*dp); dp++)
+ for (dp = bp; istoken ((unsigned char) *dp); dp++)
continue;
*dp = '\0';
- result = (mh_strcasecmp (bp, "7bit")
- && mh_strcasecmp (bp, "8bit")
- && mh_strcasecmp (bp, "binary"));
+ result = (strcasecmp (bp, "7bit")
+ && strcasecmp (bp, "8bit")
+ && strcasecmp (bp, "binary"));
free (cp);
if (result) {
fclose (fp);
+ m_getfld_state_destroy (&gstate);
return result;
}
break;
*/
default:
fclose (fp);
+ m_getfld_state_destroy (&gstate);
return 0;
}
}
- m_getfld_state_destroy (&gstate);
}