]> diplodocus.org Git - nmh/blobdiff - uip/mhlistsbr.c
Added tests of MMDF mailbox format to test-eom-align.
[nmh] / uip / mhlistsbr.c
index 42e0b05ad9b8fd7f8cca5f83775c98380f3711b8..d58d43f9caedc36b1e2b69b8996d10012ad4aa5d 100644 (file)
@@ -1,59 +1,45 @@
-
-/*
- * mhlistsbr.c -- routines to list information about the
+/* mhlistsbr.c -- routines to list information about the
  *             -- contents of MIME messages
  *
  *             -- contents of MIME messages
  *
- * $Id$
+ * 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 <fcntl.h>
  */
 
 #include <h/mh.h>
 #include <fcntl.h>
-#include <h/signals.h>
-#include <errno.h>
-#include <signal.h>
-#include <mts/generic/mts.h>
+#include <h/mts.h>
 #include <h/tws.h>
 #include <h/mime.h>
 #include <h/mhparse.h>
 #include <h/tws.h>
 #include <h/mime.h>
 #include <h/mhparse.h>
-
-extern int errno;
-
-/* mhmisc.c */
-int part_ok (CT, int);
-int type_ok (CT, int);
-void flush_errors (void);
-
-/*
- * prototypes
- */
-void list_all_messages (CT *, int, int, int, int);
-int list_switch (CT, int, int, int, int);
-int list_content (CT, int, int, int, int);
+#include <h/utils.h>
+#include "mhmisc.h"
 
 /*
  * static prototypes
  */
 
 /*
  * static prototypes
  */
-static void list_single_message (CT, int, int, int);
+static void list_single_message (CT, int, int, int, int);
 static int list_debug (CT);
 static int list_debug (CT);
-static int list_multi (CT, int, int, int, int);
-static int list_partial (CT, int, int, int, int);
-static int list_external (CT, int, int, int, int);
-static int list_application (CT, int, int, int, int);
+static int list_multi (CT, int, int, int, int, int);
+static int list_partial (CT, int, int, int, int, int);
+static int list_external (CT, int, int, int, int, int);
 static int list_encoding (CT);
 
 
 /*
  * various formats for -list option
  */
 static int list_encoding (CT);
 
 
 /*
  * various formats for -list option
  */
-#define        LSTFMT1         "%4s %-5s %-24s %5s %-36s\n"
+#define        LSTFMT1         "%4s %-5s %-24s %5s %s\n"
 #define        LSTFMT2a        "%4d "
 #define        LSTFMT2b        "%-5s %-24.24s "
 #define        LSTFMT2a        "%4d "
 #define        LSTFMT2b        "%-5s %-24.24s "
+#define        LSTFMT2bv       "%-5s %-24s "
 #define        LSTFMT2c1       "%5lu"
 #define        LSTFMT2c2       "%4lu%c"
 #define        LSTFMT2c3       "huge "
 #define        LSTFMT2c4       "     "
 #define        LSTFMT2c1       "%5lu"
 #define        LSTFMT2c2       "%4lu%c"
 #define        LSTFMT2c3       "huge "
 #define        LSTFMT2c4       "     "
-#define        LSTFMT2d1       " %-36.36s"
-#define        LSTFMT2d2       "\t     %-65.65s\n"
+#define        LSTFMT2d1       " %.36s"
+#define        LSTFMT2d1v      " %s"
+#define        LSTFMT2d2       "\t     %-65s\n"
 
 
 /*
 
 
 /*
@@ -61,7 +47,8 @@ static int list_encoding (CT);
  */
 
 void
  */
 
 void
-list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
+list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug,
+                  int dispo)
 {
     CT ct, *ctp;
 
 {
     CT ct, *ctp;
 
@@ -70,7 +57,7 @@ list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
 
     for (ctp = cts; *ctp; ctp++) {
        ct = *ctp;
 
     for (ctp = cts; *ctp; ctp++) {
        ct = *ctp;
-       list_single_message (ct, realsize, verbose, debug);
+       list_single_message (ct, realsize, verbose, debug, dispo);
     }
 
     flush_errors ();
     }
 
     flush_errors ();
@@ -82,11 +69,11 @@ list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
  */
 
 static void
  */
 
 static void
-list_single_message (CT ct, int realsize, int verbose, int debug)
+list_single_message (CT ct, int realsize, int verbose, int debug, int dispo)
 {
     if (type_ok (ct, 1)) {
        umask (ct->c_umask);
 {
     if (type_ok (ct, 1)) {
        umask (ct->c_umask);
-       list_switch (ct, 1, realsize, verbose, debug);
+       list_switch (ct, 1, realsize, verbose, debug, dispo);
        if (ct->c_fp) {
            fclose (ct->c_fp);
            ct->c_fp = NULL;
        if (ct->c_fp) {
            fclose (ct->c_fp);
            ct->c_fp = NULL;
@@ -102,69 +89,66 @@ list_single_message (CT ct, int realsize, int verbose, int debug)
  */
 
 int
  */
 
 int
-list_switch (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_switch (CT ct, int toplevel, int realsize, int verbose, int debug,
+            int dispo)
 {
     switch (ct->c_type) {
        case CT_MULTIPART:
 {
     switch (ct->c_type) {
        case CT_MULTIPART:
-           return list_multi (ct, toplevel, realsize, verbose, debug);
-           break;
+           return list_multi (ct, toplevel, realsize, verbose, debug, dispo);
 
        case CT_MESSAGE:
            switch (ct->c_subtype) {
                case MESSAGE_PARTIAL:
 
        case CT_MESSAGE:
            switch (ct->c_subtype) {
                case MESSAGE_PARTIAL:
-                   return list_partial (ct, toplevel, realsize, verbose, debug);
-                   break;
+                   return list_partial (ct, toplevel, realsize, verbose,
+                                        debug, dispo);
 
                case MESSAGE_EXTERNAL:
 
                case MESSAGE_EXTERNAL:
-                   return list_external (ct, toplevel, realsize, verbose, debug);
-                   break;
+                   return list_external (ct, toplevel, realsize, verbose,
+                                         debug, dispo);
 
                case MESSAGE_RFC822:
                default:
 
                case MESSAGE_RFC822:
                default:
-                   return list_content (ct, toplevel, realsize, verbose, debug);
-                   break;
+                   return list_content (ct, toplevel, realsize, verbose,
+                                        debug, dispo);
            }
            }
-           break;
 
        case CT_TEXT:
        case CT_AUDIO:
        case CT_IMAGE:
        case CT_VIDEO:
 
        case CT_TEXT:
        case CT_AUDIO:
        case CT_IMAGE:
        case CT_VIDEO:
-           return list_content (ct, toplevel, realsize, verbose, debug);
-           break;
-
        case CT_APPLICATION:
        case CT_APPLICATION:
-           return list_application (ct, toplevel, realsize, verbose, debug);
-           break;
-
        default:
        default:
-           /* list_debug (ct); */
-           adios (NULL, "unknown content type %d", ct->c_type);
-           break;
+            return list_content (ct, toplevel, realsize, verbose, debug, dispo);
     }
 
     return 0;  /* NOT REACHED */
 }
 
 
     }
 
     return 0;  /* NOT REACHED */
 }
 
 
-#define empty(s) ((s) ? (s) : "")
-
 /*
  * Method for listing information about a simple/generic content
  */
 
 int
 /*
  * Method for listing information about a simple/generic content
  */
 
 int
-list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_content (CT ct, int toplevel, int realsize, int verbose, int debug,
+            int dispo)
 {
     unsigned long size;
     char *cp, buffer[BUFSIZ];
     CI ci = &ct->c_ctinfo;
 {
     unsigned long size;
     char *cp, buffer[BUFSIZ];
     CI ci = &ct->c_ctinfo;
+    PM pm;
+
+    if (toplevel > 0)
+       printf (LSTFMT2a, atoi (r1bindex (FENDNULL(ct->c_file), '/')));
+    else
+       printf(toplevel < 0 ? "part " : "     ");
 
 
-    printf (toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : "     ",
-           atoi (r1bindex (empty (ct->c_file), '/')));
-    snprintf (buffer, sizeof(buffer), "%s/%s", empty (ci->ci_type),
-               empty (ci->ci_subtype));
-    printf (LSTFMT2b, empty (ct->c_partno), buffer);
+    snprintf (buffer, sizeof(buffer), "%s/%s", FENDNULL(ci->ci_type),
+               FENDNULL(ci->ci_subtype));
+    if (verbose)
+       printf (LSTFMT2bv, FENDNULL(ct->c_partno), buffer);
+    else
+       printf (LSTFMT2b, FENDNULL(ct->c_partno), buffer);
 
     if (ct->c_cesizefnx && realsize)
        size = (*ct->c_cesizefnx) (ct);
 
     if (ct->c_cesizefnx && realsize)
        size = (*ct->c_cesizefnx) (ct);
@@ -172,7 +156,7 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
        size = ct->c_end - ct->c_begin;
 
     /* find correct scale for size (Kilo/Mega/Giga/Tera) */
        size = ct->c_end - ct->c_begin;
 
     /* find correct scale for size (Kilo/Mega/Giga/Tera) */
-    for (cp = " KMGT"; size > 9999; size >>= 10)
+    for (cp = " KMGT"; size > 9999; size /= 1000)
        if (!*++cp)
            break;
 
        if (!*++cp)
            break;
 
@@ -197,26 +181,47 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
     if (ct->c_descr) {
        char *dp;
 
     if (ct->c_descr) {
        char *dp;
 
-       dp = trimcpy (cp = add (ct->c_descr, NULL));
-       free (cp);
-       printf (LSTFMT2d1, dp);
+       dp = cpytrim (ct->c_descr);
+       if (verbose)
+           printf (LSTFMT2d1v, dp);
+       else
+           printf (LSTFMT2d1, dp);
        free (dp);
     }
 
        free (dp);
     }
 
-    printf ("\n");
+    putchar('\n');
 
 
-    /*
-     * If verbose, print any RFC-822 comments in the
-     * Content-Type line.
-     */
-    if (verbose && ci->ci_comment) {
-       char *dp;
+    if (verbose) {
+       CI ci = &ct->c_ctinfo;
 
 
-       dp = trimcpy (cp = add (ci->ci_comment, NULL));
-       free (cp);
-       snprintf (buffer, sizeof(buffer), "(%s)", dp);
-       free (dp);
-       printf (LSTFMT2d2, buffer);
+       for (pm = ci->ci_first_pm; pm; pm = pm->pm_next) {
+           printf ("\t     %s=\"%s\"\n", pm->pm_name,
+                   get_param_value(pm, '?'));
+       }
+
+       /*
+        * If verbose, print any RFC-822 comments in the
+        * Content-Type line.
+        */
+       if (ci->ci_comment) {
+           char *dp;
+
+           dp = cpytrim (ci->ci_comment);
+           snprintf (buffer, sizeof(buffer), "(%s)", dp);
+           free (dp);
+           printf (LSTFMT2d2, buffer);
+       }
+    }
+
+    if (dispo && ct->c_dispo_type) {
+       printf ("\t     disposition \"%s\"\n", ct->c_dispo_type);
+
+       if (verbose) {
+           for (pm = ct->c_dispo_first; pm; pm = pm->pm_next) {
+               printf ("\t       %s=\"%s\"\n", pm->pm_name,
+                       get_param_value(pm, '?'));
+           }
+       }
     }
 
     if (debug)
     }
 
     if (debug)
@@ -233,11 +238,11 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
 static int
 list_debug (CT ct)
 {
 static int
 list_debug (CT ct)
 {
-    char **ap, **ep;
     CI ci = &ct->c_ctinfo;
     CI ci = &ct->c_ctinfo;
+    PM pm;
 
     fflush (stdout);
 
     fflush (stdout);
-    fprintf (stderr, "  partno \"%s\"\n", empty (ct->c_partno));
+    fprintf (stderr, "  partno \"%s\"\n", FENDNULL(ct->c_partno));
 
     /* print MIME-Version line */
     if (ct->c_vrsn)
 
     /* print MIME-Version line */
     if (ct->c_vrsn)
@@ -248,31 +253,32 @@ list_debug (CT ct)
        fprintf (stderr, "  %s:%s\n", TYPE_FIELD, ct->c_ctline);
 
     /* print parsed elements of content type */
        fprintf (stderr, "  %s:%s\n", TYPE_FIELD, ct->c_ctline);
 
     /* print parsed elements of content type */
-    fprintf (stderr, "    type    \"%s\"\n", empty (ci->ci_type));
-    fprintf (stderr, "    subtype \"%s\"\n", empty (ci->ci_subtype));
-    fprintf (stderr, "    comment \"%s\"\n", empty (ci->ci_comment));
-    fprintf (stderr, "    magic   \"%s\"\n", empty (ci->ci_magic));
+    fprintf (stderr, "    type    \"%s\"\n", FENDNULL(ci->ci_type));
+    fprintf (stderr, "    subtype \"%s\"\n", FENDNULL(ci->ci_subtype));
+    fprintf (stderr, "    comment \"%s\"\n", FENDNULL(ci->ci_comment));
+    fprintf (stderr, "    magic   \"%s\"\n", FENDNULL(ci->ci_magic));
 
     /* print parsed parameters attached to content type */
     fprintf (stderr, "    parameters\n");
 
     /* print parsed parameters attached to content type */
     fprintf (stderr, "    parameters\n");
-    for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
-       fprintf (stderr, "      %s=\"%s\"\n", *ap, *ep);
+    for (pm = ci->ci_first_pm; pm; pm = pm->pm_next)
+       fprintf (stderr, "      %s=\"%s\"\n", pm->pm_name,
+                get_param_value(pm, '?'));
 
     /* print internal flags for type/subtype */
 
     /* print internal flags for type/subtype */
-    fprintf (stderr, "    type 0x%x subtype 0x%x params 0x%x\n",
-            ct->c_type, ct->c_subtype, (unsigned int) ct->c_ctparams);
+    fprintf(stderr, "    type %#x subtype %#x params %p\n",
+        ct->c_type, ct->c_subtype, (void *)ct->c_ctparams);
 
 
-    fprintf (stderr, "    showproc  \"%s\"\n", empty (ct->c_showproc));
-    fprintf (stderr, "    termproc  \"%s\"\n", empty (ct->c_termproc));
-    fprintf (stderr, "    storeproc \"%s\"\n", empty (ct->c_storeproc));
+    fprintf (stderr, "    showproc  \"%s\"\n", FENDNULL(ct->c_showproc));
+    fprintf (stderr, "    termproc  \"%s\"\n", FENDNULL(ct->c_termproc));
+    fprintf (stderr, "    storeproc \"%s\"\n", FENDNULL(ct->c_storeproc));
 
     /* print transfer encoding information */
     if (ct->c_celine)
        fprintf (stderr, "  %s:%s", ENCODING_FIELD, ct->c_celine);
 
     /* print internal flags for transfer encoding */
 
     /* print transfer encoding information */
     if (ct->c_celine)
        fprintf (stderr, "  %s:%s", ENCODING_FIELD, ct->c_celine);
 
     /* print internal flags for transfer encoding */
-    fprintf (stderr, "    transfer encoding 0x%x params 0x%x\n",
-            ct->c_encoding, (unsigned int) ct->c_cefile);
+    fprintf(stderr, "    transfer encoding %#x params %p\n",
+        ct->c_encoding, (void *)&ct->c_cefile);
 
     /* print Content-ID */
     if (ct->c_id)
 
     /* print Content-ID */
     if (ct->c_id)
@@ -282,9 +288,18 @@ list_debug (CT ct)
     if (ct->c_descr)
        fprintf (stderr, "  %s:%s", DESCR_FIELD, ct->c_descr);
 
     if (ct->c_descr)
        fprintf (stderr, "  %s:%s", DESCR_FIELD, ct->c_descr);
 
-    fprintf (stderr, "    read fp 0x%x file \"%s\" begin %ld end %ld\n",
-            (unsigned int) ct->c_fp, empty (ct->c_file),
-            ct->c_begin, ct->c_end);
+    /* print Content-Disposition */
+    if (ct->c_dispo)
+       fprintf (stderr, "  %s:%s", DISPO_FIELD, ct->c_dispo);
+
+    fprintf(stderr, "    disposition \"%s\"\n", FENDNULL(ct->c_dispo_type));
+    fprintf(stderr, "    disposition parameters\n");
+    for (pm = ct->c_dispo_first; pm; pm = pm->pm_next)
+       fprintf (stderr, "      %s=\"%s\"\n", pm->pm_name,
+                get_param_value(pm, '?'));
+
+    fprintf(stderr, "    read fp %p file \"%s\" begin %ld end %ld\n",
+        (void *)ct->c_fp, FENDNULL(ct->c_file), ct->c_begin, ct->c_end);
 
     /* print more information about transfer encoding */
     list_encoding (ct);
 
     /* print more information about transfer encoding */
     list_encoding (ct);
@@ -292,28 +307,27 @@ list_debug (CT ct)
     return OK;
 }
 
     return OK;
 }
 
-#undef empty
-
 
 /*
  * list content information for type "multipart"
  */
 
 static int
 
 /*
  * list content information for type "multipart"
  */
 
 static int
-list_multi (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_multi (CT ct, int toplevel, int realsize, int verbose, int debug,
+           int dispo)
 {
     struct multipart *m = (struct multipart *) ct->c_ctparams;
     struct part *part;
 
     /* list the content for toplevel of this multipart */
 {
     struct multipart *m = (struct multipart *) ct->c_ctparams;
     struct part *part;
 
     /* list the content for toplevel of this multipart */
-    list_content (ct, toplevel, realsize, verbose, debug);
+    list_content (ct, toplevel, realsize, verbose, debug, dispo);
 
     /* now list for all the subparts */
     for (part = m->mp_parts; part; part = part->mp_next) {
        CT p = part->mp_part;
 
 
     /* now list for all the subparts */
     for (part = m->mp_parts; part; part = part->mp_next) {
        CT p = part->mp_part;
 
-       if (part_ok (p, 1) && type_ok (p, 1))
-           list_switch (p, 0, realsize, verbose, debug);
+       if (part_ok (p) && type_ok (p, 1))
+           list_switch (p, 0, realsize, verbose, debug, dispo);
     }
 
     return OK;
     }
 
     return OK;
@@ -325,16 +339,17 @@ list_multi (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 static int
  */
 
 static int
-list_partial (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_partial (CT ct, int toplevel, int realsize, int verbose, int debug,
+             int dispo)
 {
     struct partial *p = (struct partial *) ct->c_ctparams;
 
 {
     struct partial *p = (struct partial *) ct->c_ctparams;
 
-    list_content (ct, toplevel, realsize, verbose, debug);
+    list_content (ct, toplevel, realsize, verbose, debug, dispo);
     if (verbose) {
        printf ("\t     [message %s, part %d", p->pm_partid, p->pm_partno);
        if (p->pm_maxno)
            printf (" of %d", p->pm_maxno);
     if (verbose) {
        printf ("\t     [message %s, part %d", p->pm_partid, p->pm_partno);
        if (p->pm_maxno)
            printf (" of %d", p->pm_maxno);
-       printf ("]\n");
+       puts("]");
     }
 
     return OK;
     }
 
     return OK;
@@ -346,7 +361,8 @@ list_partial (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 static int
  */
 
 static int
-list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_external (CT ct, int toplevel, int realsize, int verbose, int debug,
+              int dispo)
 {
     struct exbody *e = (struct exbody *) ct->c_ctparams;
 
 {
     struct exbody *e = (struct exbody *) ct->c_ctparams;
 
@@ -354,57 +370,20 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
      * First list the information for the
      * message/external content itself.
      */
      * First list the information for the
      * message/external content itself.
      */
-    list_content (ct, toplevel, realsize, verbose, debug);
+    list_content (ct, toplevel, realsize, verbose, debug, dispo);
 
     if (verbose) {
 
     if (verbose) {
-       if (e->eb_name)
-           printf ("\t     name=\"%s\"\n", e->eb_name);
-       if (e->eb_dir)
-           printf ("\t     directory=\"%s\"\n", e->eb_dir);
-       if (e->eb_site)
-           printf ("\t     site=\"%s\"\n", e->eb_site);
-       if (e->eb_server)
-           printf ("\t     server=\"%s\"\n", e->eb_server);
-       if (e->eb_subject)
-           printf ("\t     subject=\"%s\"\n", e->eb_subject);
-
-       /* This must be defined */
-       printf     ("\t     access-type=\"%s\"\n", e->eb_access);
-
-       if (e->eb_mode)
-           printf ("\t     mode=\"%s\"\n", e->eb_mode);
-       if (e->eb_permission)
-           printf ("\t     permission=\"%s\"\n", e->eb_permission);
-
+        if (!e->eb_access)
+            puts("\t     [missing access-type]"); /* Must be defined. */
        if (e->eb_flags == NOTOK)
        if (e->eb_flags == NOTOK)
-           printf ("\t     [service unavailable]\n");
+           puts("\t     [service unavailable]");
     }
 
     /*
      * Now list the information for the external content
      * to which this content points.
      */
     }
 
     /*
      * Now list the information for the external content
      * to which this content points.
      */
-    list_content (e->eb_content, 0, realsize, verbose, debug);
-
-    return OK;
-}
-
-
-/*
- * list content information for type "application"
- */
-
-static int
-list_application (CT ct, int toplevel, int realsize, int verbose, int debug)
-{
-    list_content (ct, toplevel, realsize, verbose, debug);
-    if (verbose) {
-       char **ap, **ep;
-       CI ci = &ct->c_ctinfo;
-
-       for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
-           printf ("\t     %s=\"%s\"\n", *ap, *ep);
-    }
+    list_content (e->eb_content, 0, realsize, verbose, debug, dispo);
 
     return OK;
 }
 
     return OK;
 }
@@ -418,11 +397,10 @@ list_application (CT ct, int toplevel, int realsize, int verbose, int debug)
 static int
 list_encoding (CT ct)
 {
 static int
 list_encoding (CT ct)
 {
-    CE ce;
+    CE ce = &ct->c_cefile;
 
 
-    if ((ce = ct->c_cefile))
-       fprintf (stderr, "    decoded fp 0x%x file \"%s\"\n",
-                (unsigned int) ce->ce_fp, ce->ce_file ? ce->ce_file : "");
+    fprintf(stderr, "    decoded fp %p file \"%s\"\n",
+        (void *)ce->ce_fp, FENDNULL(ce->ce_file));
 
     return OK;
 }
 
     return OK;
 }