X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/df77ac6ade9b551076b33f2addafbb7ae7f06bd3..d711510305:/uip/show.c?ds=inline diff --git a/uip/show.c b/uip/show.c index e5b71eff..ac012927 100644 --- a/uip/show.c +++ b/uip/show.c @@ -1,6 +1,4 @@ - -/* - * 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 @@ -10,6 +8,7 @@ #include #include #include +#include "../sbr/m_maildir.h" #define SHOW_SWITCHES \ X("checkmime", 0, CHECKMIMESW) \ @@ -33,8 +32,17 @@ /* \ * switches for mhlproc \ */ \ - X("concat", -6, CONCATSW) \ - X("noconcat", -8, NCONCATSW) \ + 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); @@ -79,23 +87,30 @@ main (int argc, char **argv) while ((cp = *argp++)) { if (*cp == '-') { switch (smatch (++cp, switches)) { - case AMBIGSW: + case AMBIGSW: ambigsw (cp, switches); done (1); + case HEADSW: + headersw = 1; + goto non_mhl_switches; + case NHEADSW: + headersw = 0; + /* FALLTHRU */ 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 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] ": ""); @@ -105,7 +120,7 @@ main (int argc, char **argv) print_version(invo_name); done (0); - case DRFTSW: + case DRFTSW: if (file) adios (NULL, "only one file at a time!"); draftsw++; @@ -115,7 +130,7 @@ usage: adios (NULL, "usage: %s [+folder] [switches] [switches for showproc]", invo_name); - case FILESW: + case FILESW: if (mode != SHOW) goto usage; if (draftsw || file) @@ -125,13 +140,6 @@ usage: file = path (cp, TFILE); continue; - case HEADSW: - headersw++; - continue; - case NHEADSW: - headersw = 0; - continue; - case FORMSW: app_msgarg(&vec, --cp); if (!(cp = *argp++) || *cp == '-') @@ -143,18 +151,24 @@ usage: 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; @@ -179,8 +193,7 @@ usage: } else { if (mode != SHOW) goto usage; - else - app_msgarg(&msgs, cp); + app_msgarg(&msgs, cp); } } @@ -194,6 +207,7 @@ usage: app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf))); else app_msgarg(&vec, file); + headersw = 0; goto go_to_it; } @@ -245,18 +259,14 @@ usage: 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 == 1) - printf ("(Message %s:%s)\n", folder, vec.msgs[0]); - go_to_it: ; - fflush (stdout); /* * Decide which "proc" to use @@ -288,14 +298,24 @@ go_to_it: ; } if (folder && !draftsw && !file) - m_putenv ("mhfolder", folder); + setenv("mhfolder", folder, 1); + + 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 (strcmp (r1bindex (proc, '/'), "mhl") == 0) { /* If "mhl", then run it internally */ argsplit_insert(&vec, "mhl", &program); app_msgarg(&vec, NULL); mhl (vec.size, vec.msgs); done (0); + } else { int i; char **mp; @@ -324,9 +344,14 @@ go_to_it: ; 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]); } } + fflush (stdout); + argsplit_insert(&vec, proc, &program); app_msgarg(&vec, NULL); execvp (program, vec.msgs); @@ -343,7 +368,7 @@ is_nontext (char *msgnam) { 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; @@ -362,7 +387,7 @@ is_nontext (char *msgnam) 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); @@ -389,7 +414,7 @@ invalid: continue; case '(': i++; - /* and fall... */ + continue; default: continue; case ')': @@ -422,7 +447,7 @@ invalid: if (*dp) { if ((result = !uprf (dp, "charset"))) goto out; - dp += sizeof("charset") - 1; + dp += LEN("charset"); while (isspace ((unsigned char) *dp)) dp++; if (*dp++ != '=') @@ -467,7 +492,7 @@ out: * 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);