]> diplodocus.org Git - nmh/blobdiff - uip/show.c
lock_file.c: close(2) file descriptor on failure, avoiding leak.
[nmh] / uip / show.c
index f89107855c0214bc766f1cc4c64312c9fc055c54..86e8e5b5ae8946a266a774b4e75e9752dca2e6b3 100644 (file)
@@ -1,5 +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
@@ -9,6 +8,7 @@
 #include <h/mh.h>
 #include <h/mime.h>
 #include <h/utils.h>
+#include "sbr/m_maildir.h"
 
 #define SHOW_SWITCHES \
     X("checkmime", 0, CHECKMIMESW) \
     /*                         \
      * 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);
@@ -87,6 +96,7 @@ main (int argc, char **argv)
                    goto non_mhl_switches;
                case NHEADSW:
                    headersw = 0;
+                   /* FALLTHRU */
                case CONCATSW:
                case NCONCATSW:
 non_mhl_switches:
@@ -141,6 +151,12 @@ 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]);
@@ -172,13 +188,11 @@ usage:
        if (*cp == '+' || *cp == '@') {
            if (folder)
                adios (NULL, "only one folder at a time!");
-           else
-               folder = pluspath (cp);
+            folder = pluspath (cp);
        } else {
            if (mode != SHOW)
                goto usage;
-           else
-               app_msgarg(&msgs, cp);
+            app_msgarg(&msgs, cp);
        }
     }
 
@@ -244,7 +258,7 @@ 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   */
@@ -283,7 +297,7 @@ go_to_it: ;
     }
 
     if (folder && !draftsw && !file)
-       m_putenv ("mhfolder", folder);
+       setenv("mhfolder", folder, 1);
 
     if (strcmp (r1bindex (proc, '/'), "cat") == 0) {
 
@@ -353,16 +367,16 @@ 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;
+    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:
            /*
@@ -372,10 +386,10 @@ 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);
+                   state = m_getfld2(&gstate, name, buf, &bufsz);
                    cp = add (buf, cp);
                }
                bp = cp;
@@ -399,7 +413,7 @@ invalid:
                            continue;
                        case '(':
                            i++;
-                           /* and fall... */
+                           continue;
                        default:
                            continue;
                        case ')':
@@ -432,7 +446,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++ != '=')
@@ -477,10 +491,10 @@ 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);
+                   state = m_getfld2(&gstate, name, buf, &bufsz);
                    cp = add (buf, cp);
                }
                for (bp = cp; isspace ((unsigned char) *bp); bp++)
@@ -507,7 +521,7 @@ out:
             */
            while (state == FLDPLUS) {
                bufsz = sizeof buf;
-               state = m_getfld (&gstate, name, buf, &bufsz, fp);
+               state = m_getfld2(&gstate, name, buf, &bufsz);
            }
            break;