From: Ken Hornstein Date: Wed, 5 Mar 2014 18:03:30 +0000 (-0500) Subject: Update mhlist and other relevant utilities to output disposition information X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/a77de92766e31f0d8973a9bc303574c3bbe4f82f?ds=inline;hp=0a7838e0e8026cbfe8a8924ef256ad9e930fb03d Update mhlist and other relevant utilities to output disposition information with a new -disposition switch. --- diff --git a/h/mhparse.h b/h/mhparse.h index ead187be..b6754794 100644 --- a/h/mhparse.h +++ b/h/mhparse.h @@ -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. diff --git a/man/mhbuild.man b/man/mhbuild.man index db80e232..7d35cedd 100644 --- a/man/mhbuild.man +++ b/man/mhbuild.man @@ -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 diff --git a/man/mhlist.man b/man/mhlist.man index 46b75636..69394fec 100644 --- a/man/mhlist.man +++ b/man/mhlist.man @@ -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 diff --git a/uip/mhbuild.c b/uip/mhbuild.c index 85bfef47..06577740 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -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)); diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index e2bcf392..95bbd414 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -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); diff --git a/uip/mhlist.c b/uip/mhlist.c index f37041c3..f9dbbd68 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -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++) diff --git a/uip/mhlistsbr.c b/uip/mhlistsbr.c index f5676a49..3b442e48 100644 --- a/uip/mhlistsbr.c +++ b/uip/mhlistsbr.c @@ -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; } diff --git a/uip/mhn.c b/uip/mhn.c index 08405d4d..220a73d5 100644 --- 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 diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 1682ce80..bb0a646e 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -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;