]> diplodocus.org Git - nmh/commitdiff
Update mhlist and other relevant utilities to output disposition information
authorKen Hornstein <kenh@pobox.com>
Wed, 5 Mar 2014 18:03:30 +0000 (13:03 -0500)
committerKen Hornstein <kenh@pobox.com>
Wed, 5 Mar 2014 18:03:30 +0000 (13:03 -0500)
with a new -disposition switch.

h/mhparse.h
man/mhbuild.man
man/mhlist.man
uip/mhbuild.c
uip/mhbuildsbr.c
uip/mhlist.c
uip/mhlistsbr.c
uip/mhn.c
uip/mhshowsbr.c

index ead187bea664cd08e22328baf6358f93cb3e61bd..b67547942b14e79a199064d65fc0c7f144456e47 100644 (file)
@@ -322,13 +322,14 @@ CT parse_mime (char *);
  *               CE_QUOTED.
  * maxunencoded        - The maximum line length before the default encoding for
  *               text parts is quoted-printable.
+ * verbose     - If 1, output verbose information during message composition
  *
  * Returns a CT structure describing the resulting MIME message.  If the
  * -auto flag is set and a MIME-Version header is encountered, the return
  * value is NULL.
  */
 CT build_mime (char *infile, int autobuild, int dist, int directives,
-              int encoding, size_t maxunencoded);
+              int encoding, size_t maxunencoded, int verbose);
 
 int add_header (CT, char *, char *);
 int get_ctinfo (char *, CT, int);
@@ -342,6 +343,51 @@ const struct str2init *get_ct_init (int);
 const char *ce_str (int);
 const struct str2init *get_ce_method (const char *);
 
+/*
+ * Given a list of messages, display information about them on standard
+ * output.
+ *
+ * Argumens are:
+ *
+ * cts         - An array of CT elements of messages that need to be
+ *               displayed.  Array is terminated by a NULL.
+ * headsw      - If 1, display a column header.
+ * sizesw      - If 1, display the size of the part.
+ * verbosw     - If 1, display verbose information
+ * debugsw     - If 1, turn on debugging for the output.
+ * disposw     - If 1, display MIME part disposition information.
+ *
+ */
+void list_all_messages(CT *cts, int headsw, int sizesw, int verbosw,
+                      int debugsw, int disposw);
+
+/*
+ * List the content information of a single MIME part on stdout.
+ *
+ * Arguments are:
+ *
+ * ct          - MIME Content structure to display.
+ * toplevel    - If set, we're at the top level of a message
+ * realsize    - If set, determine the real size of the content
+ * verbose     - If set, output verbose information
+ * debug       - If set, turn on debugging for the output
+ * dispo       - If set, display MIME part disposition information.
+ *
+ * Returns OK on success, NOTOK otherwise.
+ */
+int list_content(CT ct, int toplevel, int realsize, int verbose, int debug,
+                int dispo);
+
+/*
+ * Display content-appropriate information on MIME parts, decending recursively
+ * into multipart content if appropriate.  Uses list_content() for displaying
+ * generic information.
+ *
+ * Arguments and return value are the same as list_content().
+ */
+int list_switch(CT ct, int toplevel, int realsize, int verbose, int debug,
+               int dispo);
+
 /*
  * Given a linked list of parameters, build an output string for them.  This
  * string is designed to be concatenated on an already-built header.
index db80e232d6d39388874d66e5399bb420562ca19b..7d35cedd72ad0a69ee9e0f10190cef9def2ac8e2 100644 (file)
@@ -17,6 +17,7 @@ mhbuild \- translate MIME composition draft
 .RB [ \-rfc934mode " | " \-norfc934mode ]
 .RB [ \-contentid " | " \-nocontentid ]
 .RB [ \-verbose " | " \-noverbose ]
+.RB [ \-disposition " | " \-nodisposition ]
 .RB [ \-check " | " \-nocheck ]
 .RB [ \-headerencoding 
 .IR encoding\-algorithm
@@ -81,6 +82,11 @@ switch
 is present, then the listing will show any \*(lqextra\*(rq information
 that is present in the message, such as comments in the
 \*(lqContent-Type\*(rq header.
+.PP
+If the
+.B \-disposition
+switch is present, then the listing will show any relevant information from
+the \*(lqContent-Disposition\*(rq header.
 .SS "Simplified Attachment Interface"
 For users who wish to simply attach files to text content,
 .B mhbuild
@@ -777,6 +783,7 @@ is checked.
 .RB ` \-contentid '
 .RB ` \-nocheck '
 .RB ` \-noverbose '
+.RB ` \-nodisposition '
 .RB ` \-autoheaderencoding '
 .RB ` "\-maxunencoded\ 78"'
 .fi
index 46b75636a41c3d88cbf00276158064b05705feda..69394fec7b80489d0b37acf556a12625c3e59e87 100644 (file)
@@ -27,6 +27,7 @@ mhlist \- list information about MIME messages
 .RB [ \-check " | " \-nocheck ]
 .RB [ \-changecur " | " \-nochangecur ]
 .RB [ \-verbose " | " \-noverbose ]
+.RB [ \-disposition " | " \-nodisposition ]
 .RB [ \-version ]
 .RB [ \-help ]
 .ad
@@ -61,6 +62,11 @@ switch is present, then the listing will show
 any \*(lqextra\*(rq information that is present in the message,
 such as comments in the \*(lqContent-Type\*(rq header.
 .PP
+If the
+.B \-disposition
+switch is present, then the listing will show any relevant information from
+the \*(lqContent-Disposition\*(rq header.
+.PP
 The option
 .B \-file
 .I file
@@ -187,6 +193,7 @@ integrity of the content.
 .RB ` \-wcache\ ask '
 .RB ` \-changecur '
 .RB ` \-noverbose '
+.RB ` \-nodisposition '
 .fi
 .SH CONTEXT
 If a folder is given, it will become the current folder.  The last
index 85bfef473b0c08e21da1d23b53ece7e434b1db78..065777405ede3fcdbd125d6f6265a119a17d41a5 100644 (file)
@@ -35,6 +35,8 @@
     X("norfc934mode", 0, NRFC934SW) \
     X("verbose", 0, VERBSW) \
     X("noverbose", 0, NVERBSW) \
+    X("disposition", 0, DISPOSW) \
+    X("nodisposition", 0, NDISPOSW) \
     X("rcache policy", 0, RCACHESW) \
     X("wcache policy", 0, WCACHESW) \
     X("contentid", 0, CONTENTIDSW) \
@@ -74,7 +76,6 @@ extern char *cache_public;
 extern char *cache_private;
 
 int debugsw = 0;
-int verbosw = 0;
 
 int listsw   = 0;
 int rfc934sw = 0;
@@ -95,14 +96,12 @@ static void unlink_done (int) NORETURN;
 int output_message (CT, char *);
 int output_message_fp (CT, FILE *, char*);
 
-/* mhlistsbr.c */
-int list_all_messages (CT *, int, int, int, int);
-
 
 int
 main (int argc, char **argv)
 {
     int sizesw = 1, headsw = 1, directives = 1, autobuild = 0, dist = 0;
+    int verbosw = 0, dispo = 0;
     size_t maxunencoded = MAXTEXTPERLN;
     int *icachesw;
     char *cp, buf[BUFSIZ];
@@ -270,6 +269,12 @@ main (int argc, char **argv)
            case NVERBSW: 
                verbosw = 0;
                continue;
+           case DISPOSW:
+               dispo = 1;
+               continue;
+           case NDISPOSW:
+               dispo = 0;
+               continue;
            case DEBUGSW:
                debugsw = 1;
                continue;
@@ -338,7 +343,7 @@ main (int argc, char **argv)
 
        /* build the content structures for MIME message */
        ct = build_mime (infile, autobuild, dist, directives, header_encoding,
-                        maxunencoded);
+                        maxunencoded, verbosw);
 
        /*
         * If ct == NULL, that means that -auto was set and a MIME version
@@ -369,7 +374,7 @@ main (int argc, char **argv)
 
     /* build the content structures for MIME message */
     ct = build_mime (compfile, autobuild, dist, directives, header_encoding,
-                    maxunencoded);
+                    maxunencoded, verbosw);
 
     /*
      * If ct == NULL, that means -auto was set and we found a MIME version
@@ -397,7 +402,7 @@ main (int argc, char **argv)
      * List the message info
      */
     if (listsw)
-       list_all_messages (cts, headsw, sizesw, verbosw, debugsw);
+       list_all_messages (cts, headsw, sizesw, verbosw, debugsw, dispo);
 
     /* Rename composition draft */
     snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile));
index e2bcf392e5543509a0bbb053f64c41e7853ac076..95bbd4149f098c1427bd6915764662920c505426 100644 (file)
@@ -32,7 +32,6 @@
 
 
 extern int debugsw;
-extern int verbosw;
 
 extern int listsw;
 extern int rfc934sw;
@@ -76,7 +75,7 @@ static void setup_attach_content(CT, char *);
 static char *fgetstr (char *, int, FILE *);
 static int user_content (FILE *, char *, CT *);
 static void set_id (CT, int);
-static int compose_content (CT);
+static int compose_content (CT, int);
 static int scan_content (CT, size_t);
 static int build_headers (CT, int);
 static char *calculate_digest (CT, int);
@@ -124,7 +123,7 @@ static void directive_pop(void)
 
 CT
 build_mime (char *infile, int autobuild, int dist, int directives,
-           int header_encoding, size_t maxunencoded)
+           int header_encoding, size_t maxunencoded, int verbose)
 {
     int        compnum, state;
     char buf[BUFSIZ], name[NAMESZ];
@@ -439,7 +438,7 @@ finish_field:
      * Fill out, or expand directives.  Parse and execute
      * commands specified by profile composition strings.
      */
-    compose_content (ct);
+    compose_content (ct, verbose);
 
     if ((cp = strchr(prefix, 'a')) == NULL)
        adios (NULL, "internal error(4)");
@@ -1049,7 +1048,7 @@ set_id (CT ct, int top)
  */
 
 static int
-compose_content (CT ct)
+compose_content (CT ct, int verbose)
 {
     CE ce = &ct->c_cefile;
 
@@ -1075,7 +1074,7 @@ compose_content (CT ct)
 
            sprintf (pp, "%d", partnum);
            p->c_partno = add (partnam, NULL);
-           if (compose_content (p) == NOTOK)
+           if (compose_content (p, verbose) == NOTOK)
                return NOTOK;
        }
 
@@ -1212,7 +1211,7 @@ raw:
                }
            }
 
-           if (verbosw)
+           if (verbose)
                printf ("composing content %s/%s from command\n\t%s\n",
                        ci->ci_type, ci->ci_subtype, buffer);
 
index f37041c38f1cb07d01b52a4595296535e3c479c7..f9dbbd68bc260e70f9f1c834df55ab424f3b663d 100644 (file)
@@ -27,6 +27,8 @@
     X("norealsize", 0, NSIZESW) \
     X("verbose", 0, VERBSW) \
     X("noverbose", 0, NVERBSW) \
+    X("disposition", 0, DISPOSW) \
+    X("nodisposition", 0, NDISPOSW) \
     X("file file", 0, FILESW) \
     X("part number", 0, PARTSW) \
     X("type content", 0, TYPESW) \
@@ -67,7 +69,6 @@ extern int userrs;
 pid_t xpid  = 0;
 
 int debugsw = 0;
-int verbosw = 0;
 
 #define        quitser pipeser
 
@@ -79,9 +80,6 @@ int part_ok (CT, int);
 int type_ok (CT, int);
 void flush_errors (void);
 
-/* mhlistsbr.c */
-void list_all_messages (CT *, int, int, int, int);
-
 /* mhfree.c */
 extern CT *cts;
 void freects_done (int) NORETURN;
@@ -95,7 +93,7 @@ static void pipeser (int);
 int
 main (int argc, char **argv)
 {
-    int sizesw = 1, headsw = 1, chgflag = 1;
+    int sizesw = 1, headsw = 1, chgflag = 1, verbosw = 0, dispo = 0;
     int msgnum, *icachesw;
     char *cp, *file = NULL, *folder = NULL;
     char *maildir, buf[100], **argp;
@@ -209,6 +207,12 @@ do_cache:
            case NVERBSW: 
                verbosw = 0;
                continue;
+           case DISPOSW:
+               dispo = 1;
+               continue;
+           case NDISPOSW:
+               dispo = 0;
+               continue;
            case DEBUGSW:
                debugsw = 1;
                continue;
@@ -319,7 +323,7 @@ do_cache:
     /*
      * List the message content
      */
-    list_all_messages (cts, headsw, sizesw, verbosw, debugsw);
+    list_all_messages (cts, headsw, sizesw, verbosw, debugsw, dispo);
 
     /* Now free all the structures for the content */
     for (ctp = cts; *ctp; ctp++)
index f5676a4990e2751fcc62e1ac2b327ba468e786a4..3b442e4856ccbca71417f0f2bf02be3c0e83bbbd 100644 (file)
@@ -22,22 +22,15 @@ 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);
-
 /*
  * 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_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_application (CT, int, int, int, int, int);
 static int list_encoding (CT);
 
 
@@ -60,7 +53,8 @@ static int list_encoding (CT);
  */
 
 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;
 
@@ -69,7 +63,7 @@ list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
 
     for (ctp = cts; *ctp; ctp++) {
        ct = *ctp;
-       list_single_message (ct, realsize, verbose, debug);
+       list_single_message (ct, realsize, verbose, debug, dispo);
     }
 
     flush_errors ();
@@ -81,11 +75,11 @@ list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
  */
 
 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);
-       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;
@@ -101,33 +95,38 @@ list_single_message (CT ct, int realsize, int verbose, int debug)
  */
 
 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:
-           return list_multi (ct, toplevel, realsize, verbose, debug);
+           return list_multi (ct, toplevel, realsize, verbose, debug, dispo);
 
        case CT_MESSAGE:
            switch (ct->c_subtype) {
                case MESSAGE_PARTIAL:
-                   return list_partial (ct, toplevel, realsize, verbose, debug);
+                   return list_partial (ct, toplevel, realsize, verbose,
+                                        debug, dispo);
 
                case MESSAGE_EXTERNAL:
-                   return list_external (ct, toplevel, realsize, verbose, debug);
+                   return list_external (ct, toplevel, realsize, verbose,
+                                         debug, dispo);
 
                case MESSAGE_RFC822:
                default:
-                   return list_content (ct, toplevel, realsize, verbose, debug);
+                   return list_content (ct, toplevel, realsize, verbose,
+                                        debug, dispo);
            }
 
        case CT_TEXT:
        case CT_AUDIO:
        case CT_IMAGE:
        case CT_VIDEO:
-           return list_content (ct, toplevel, realsize, verbose, debug);
+           return list_content (ct, toplevel, realsize, verbose, debug, dispo);
 
        case CT_APPLICATION:
-           return list_application (ct, toplevel, realsize, verbose, debug);
+           return list_application (ct, toplevel, realsize, verbose, debug,
+                                    dispo);
 
        default:
            /* list_debug (ct); */
@@ -145,11 +144,13 @@ list_switch (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 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;
+    PM pm;
 
     if (toplevel > 0)
        printf (LSTFMT2a, atoi (r1bindex (empty (ct->c_file), '/')));
@@ -200,7 +201,6 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
 
     if (verbose) {
        CI ci = &ct->c_ctinfo;
-       PM pm;
 
        for (pm = ci->ci_first_pm; pm; pm = pm->pm_next) {
            printf ("\t     %s=\"%s\"\n", pm->pm_name,
@@ -221,6 +221,18 @@ list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
        }
     }
 
+    if (dispo && ct->c_dispo_type) {
+       printf (LSTFMT2d2, ct->c_dispo_type);
+       printf ("\n");
+
+       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)
        list_debug (ct);
 
@@ -286,6 +298,16 @@ list_debug (CT ct)
     if (ct->c_descr)
        fprintf (stderr, "  %s:%s", DESCR_FIELD, ct->c_descr);
 
+    /* print Content-Disposition */
+    if (ct->c_dispo)
+       fprintf (stderr, "  %s:%s", DISPO_FIELD, ct->c_dispo);
+
+    fprintf(stderr, "    disposition \"%s\"\n", empty (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 0x%x file \"%s\" begin %ld end %ld\n",
             (unsigned int)(unsigned long) ct->c_fp, empty (ct->c_file),
             ct->c_begin, ct->c_end);
@@ -304,20 +326,21 @@ list_debug (CT ct)
  */
 
 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 */
-    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;
 
        if (part_ok (p, 1) && type_ok (p, 1))
-           list_switch (p, 0, realsize, verbose, debug);
+           list_switch (p, 0, realsize, verbose, debug, dispo);
     }
 
     return OK;
@@ -329,11 +352,12 @@ list_multi (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 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;
 
-    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)
@@ -350,7 +374,8 @@ list_partial (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 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;
 
@@ -358,7 +383,7 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
      * 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 (e->eb_name)
@@ -371,6 +396,8 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
            printf ("\t     server=\"%s\"\n", e->eb_server);
        if (e->eb_subject)
            printf ("\t     subject=\"%s\"\n", e->eb_subject);
+       if (e->eb_url)
+           printf ("\t     url=\"%s\"\n", e->eb_url);
 
        /* This must be defined */
        printf     ("\t     access-type=\"%s\"\n", e->eb_access);
@@ -382,13 +409,14 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
 
        if (e->eb_flags == NOTOK)
            printf ("\t     [service unavailable]\n");
+
     }
 
     /*
      * Now list the information for the external content
      * to which this content points.
      */
-    list_content (e->eb_content, 0, realsize, verbose, debug);
+    list_content (e->eb_content, 0, realsize, verbose, debug, dispo);
 
     return OK;
 }
@@ -402,9 +430,10 @@ list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
  */
 
 static int
-list_application (CT ct, int toplevel, int realsize, int verbose, int debug)
+list_application (CT ct, int toplevel, int realsize, int verbose, int debug,
+                 int dispo)
 {
-    list_content (ct, toplevel, realsize, verbose, debug);
+    list_content (ct, toplevel, realsize, verbose, debug, dispo);
 
     return OK;
 }
index 08405d4d009dbd6f6bcc22f4f19c5d0abf3882c7..220a73d5aea5285472b0ddcb9a7de40e2d04fffe 100644 (file)
--- a/uip/mhn.c
+++ b/uip/mhn.c
@@ -132,9 +132,6 @@ void flush_errors (void);
 /* mhshowsbr.c */
 void show_all_messages (CT *);
 
-/* mhlistsbr.c */
-void list_all_messages (CT *, int, int, int, int);
-
 /* mhstoresbr.c */
 void store_all_messages (CT *);
 
@@ -556,7 +553,7 @@ do_cache:
      * List the message content
      */
     if (listsw)
-       list_all_messages (cts, headsw, sizesw, verbosw, debugsw);
+       list_all_messages (cts, headsw, sizesw, verbosw, debugsw, 0);
 
     /*
      * Store the message content
index 1682ce802aed962f0b23e4a97dcdfca3c37bd4b9..bb0a646ec0bb98578b2dd407df9800d0eb51245c 100644 (file)
@@ -41,10 +41,6 @@ int type_ok (CT, int);
 void content_error (char *, CT, char *, ...);
 void flush_errors (void);
 
-/* mhlistsbr.c */
-int list_switch (CT, int, int, int, int);
-int list_content (CT, int, int, int, int);
-
 /*
  * prototypes
  */
@@ -515,9 +511,9 @@ show_content_aux2 (CT ct, int serial, int alternate, char *cracked, char *buffer
        char prompt[BUFSIZ];
 
        if (ct->c_type == CT_MULTIPART)
-           list_content (ct, -1, 1, 0, 0);
+           list_content (ct, -1, 1, 0, 0, 0);
        else
-           list_switch (ct, -1, 1, 0, 0);
+           list_switch (ct, -1, 1, 0, 0, 0);
 
        if (xpause && isatty (fileno (stdout))) {
            int intr;