From 2cb4cd29b1a56aa2142803124f951d1aae9219a2 Mon Sep 17 00:00:00 2001 From: Paul Fox Date: Wed, 23 Apr 2014 21:44:54 -0400 Subject: [PATCH] mhshow: apply marker form to all part separators the format now supports a "hidden" component, only set if display of the content has been suppressed. --- etc/mhshow.marker | 2 +- man/mhshow.man | 2 ++ uip/mhshowsbr.c | 84 ++++++++++++++++++++++++++++++----------------------- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/etc/mhshow.marker b/etc/mhshow.marker index cc9ec85..46f1cd1 100644 --- a/etc/mhshow.marker +++ b/etc/mhshow.marker @@ -3,4 +3,4 @@ %; used by mhshow when it decides to not display content. %; [ part %{part} - %{content-type} - %<{description}\ -%{description}%?{cdispo-filename}%{cdispo-filename}%|%{ctype-name}%> ] +%{description}%?{cdispo-filename}%{cdispo-filename}%|%{ctype-name}%> %{hidden} ] diff --git a/man/mhshow.man b/man/mhshow.man index d220914..1a6b905 100644 --- a/man/mhshow.man +++ b/man/mhshow.man @@ -629,6 +629,8 @@ disposition string Content disposition (attachment or inline) ctype- string Value of from Content\-Type header cdispo- string Value of from Content\-Disposition header +hidden string Only set (to "[suppressed]") if display of + the content has been suppressed. .fi .RE All MIME parameters and the \*(lqContent-Description\*(rq header will have diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 45c73cb..9604141 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -42,7 +42,7 @@ void flush_errors (void); /* * prototypes */ -int show_content_aux (CT, int, char *, char *); +int show_content_aux (CT, int, char *, char *, struct format *fmt); /* * static prototypes @@ -50,20 +50,20 @@ int show_content_aux (CT, int, char *, char *); static void show_single_message (CT, char *, int, int, int, struct format *); static void DisplayMsgHeader (CT, char *, int); static int show_switch (CT, int, int, int, int, struct format *); -static int show_content (CT, int, int, int, struct format *fmt); -static int show_content_aux2 (CT, int, char *, char *, int, int, int); -static int show_text (CT, int, int); +static int show_content (CT, int, int, int, struct format *); +static int show_content_aux2 (CT, int, char *, char *, int, int, int, struct format *); +static int show_text (CT, int, int, struct format *); static int show_multi (CT, int, int, int, int, struct format *); -static int show_multi_internal (CT, int, int, int, int, struct format *fmt); -static int show_multi_aux (CT, int, char *); -static int show_message_rfc822 (CT, int); +static int show_multi_internal (CT, int, int, int, int, struct format *); +static int show_multi_aux (CT, int, char *, struct format *); +static int show_message_rfc822 (CT, int, struct format *); static int show_partial (CT, int); static int show_external (CT, int, int, int, int, struct format *); static int parse_display_string (CT, char *, int *, int *, char *, char *, size_t, int multipart); static int convert_content_charset (CT, char **); static struct format *compile_marker(char *); -static void output_marker (CT, struct format *); +static void output_marker (CT, struct format *, int); static void free_markercomps (void); static int pidcheck(int); @@ -75,6 +75,7 @@ static int pidcheck(int); static struct comp *part_comp = NULL; static struct comp *ctype_comp = NULL; static struct comp *description_comp = NULL; +static struct comp *ishidden_comp = NULL; static struct comp *dispo_comp = NULL; struct param_comp_list { @@ -264,11 +265,11 @@ show_switch (CT ct, int alternate, int concatsw, int textonly, int inlineonly, case MESSAGE_RFC822: default: - return show_message_rfc822 (ct, alternate); + return show_message_rfc822 (ct, alternate, fmt); } case CT_TEXT: - return show_text (ct, alternate, concatsw); + return show_text (ct, alternate, concatsw, fmt); case CT_AUDIO: case CT_IMAGE: @@ -301,7 +302,7 @@ show_content (CT ct, int alternate, int textonly, int inlineonly, */ if (textonly || (inlineonly && !is_inline(ct))) { - output_marker(ct, fmt); + output_marker(ct, fmt, 1); return OK; } @@ -309,15 +310,15 @@ show_content (CT ct, int alternate, int textonly, int inlineonly, snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", invo_name, ci->ci_type, ci->ci_subtype); if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); /* Check for invo_name-show-type */ snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); if ((cp = ct->c_showproc)) - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); /* complain if we are not a part of a multipart/alternative */ if (!alternate) @@ -332,7 +333,7 @@ show_content (CT ct, int alternate, int textonly, int inlineonly, */ int -show_content_aux (CT ct, int alternate, char *cp, char *cracked) +show_content_aux (CT ct, int alternate, char *cp, char *cracked, struct format *fmt) { int fd; int xstdin = 0, xlist = 0; @@ -382,7 +383,7 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked) got_command: return show_content_aux2 (ct, alternate, cracked, buffer, - fd, xlist, xstdin); + fd, xlist, xstdin, fmt); } @@ -392,7 +393,7 @@ got_command: static int show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, - int fd, int xlist, int xstdin) + int fd, int xlist, int xstdin, struct format *fmt) { pid_t child_id; int i, vecp; @@ -412,10 +413,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, } if (xlist) { - if (ct->c_type == CT_MULTIPART) - list_content (ct, -1, 1, 0, 0, 0); - else - list_switch (ct, -1, 1, 0, 0, 0); + output_marker(ct, fmt, 0); } /* @@ -487,7 +485,7 @@ show_content_aux2 (CT ct, int alternate, char *cracked, char *buffer, */ static int -show_text (CT ct, int alternate, int concatsw) +show_text (CT ct, int alternate, int concatsw, struct format *fmt) { char *cp, buffer[BUFSIZ]; CI ci = &ct->c_ctinfo; @@ -496,12 +494,12 @@ show_text (CT ct, int alternate, int concatsw) snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", invo_name, ci->ci_type, ci->ci_subtype); if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); /* Check for invo_name-show-type */ snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); /* * Use default method if content is text/plain, or if @@ -517,7 +515,7 @@ show_text (CT ct, int alternate, int concatsw) snprintf (buffer, sizeof(buffer), "%%l%s %%F", progsw ? progsw : moreproc && *moreproc ? moreproc : DEFAULT_PAGER); cp = (ct->c_showproc = add (buffer, NULL)); - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); } return NOTOK; @@ -539,15 +537,15 @@ show_multi (CT ct, int alternate, int concatsw, int textonly, int inlineonly, snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", invo_name, ci->ci_type, ci->ci_subtype); if ((cp = context_find (buffer)) && *cp != '\0') - return show_multi_aux (ct, alternate, cp); + return show_multi_aux (ct, alternate, cp, fmt); /* Check for invo_name-show-type */ snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); if ((cp = context_find (buffer)) && *cp != '\0') - return show_multi_aux (ct, alternate, cp); + return show_multi_aux (ct, alternate, cp, fmt); if ((cp = ct->c_showproc)) - return show_multi_aux (ct, alternate, cp); + return show_multi_aux (ct, alternate, cp, fmt); /* * Use default method to display this multipart content. Even @@ -639,7 +637,7 @@ out: */ static int -show_multi_aux (CT ct, int alternate, char *cp) +show_multi_aux (CT ct, int alternate, char *cp, struct format *fmt) { /* xstdin is only used in the call to parse_display_string(): its value is ignored in the function. */ @@ -677,7 +675,7 @@ show_multi_aux (CT ct, int alternate, char *cp) return NOTOK; } - return show_content_aux2 (ct, alternate, NULL, buffer, NOTOK, xlist, 0); + return show_content_aux2 (ct, alternate, NULL, buffer, NOTOK, xlist, 0, fmt); } @@ -686,7 +684,7 @@ show_multi_aux (CT ct, int alternate, char *cp) */ static int -show_message_rfc822 (CT ct, int alternate) +show_message_rfc822 (CT ct, int alternate, struct format *fmt) { char *cp, buffer[BUFSIZ]; CI ci = &ct->c_ctinfo; @@ -695,20 +693,20 @@ show_message_rfc822 (CT ct, int alternate) snprintf (buffer, sizeof(buffer), "%s-show-%s/%s", invo_name, ci->ci_type, ci->ci_subtype); if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); /* Check for invo_name-show-type */ snprintf (buffer, sizeof(buffer), "%s-show-%s", invo_name, ci->ci_type); if ((cp = context_find (buffer)) && *cp != '\0') - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); if ((cp = ct->c_showproc)) - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); /* default method for message/rfc822 */ if (ct->c_subtype == MESSAGE_RFC822) { cp = (ct->c_showproc = add ("%pshow -file %F", NULL)); - return show_content_aux (ct, alternate, cp, NULL); + return show_content_aux (ct, alternate, cp, NULL, fmt); } /* complain if we are not a part of a multipart/alternative */ @@ -1226,7 +1224,7 @@ convert_content_charset (CT ct, char **file) { #define DEFAULT_MARKER "[ part %{part} - %{content-type} - %<{description}" \ "%{description}%?{cdispo-filename}%{cdispo-filename}" \ - "%|%{ctype-name}%> ]" + "%|%{ctype-name}%> %{hidden} ]" static struct format * compile_marker(char *markerform) @@ -1253,6 +1251,9 @@ compile_marker(char *markerform) * cdispo- - Content-Disposition parameter */ + /* flags whether part is being displayed or not */ + fmt_addcompentry("hidden"); + while ((comp = fmt_nextcomp(comp, &bucket)) != NULL) { if (strcasecmp(comp->c_name, "part") == 0) { part_comp = comp; @@ -1262,6 +1263,8 @@ compile_marker(char *markerform) description_comp = comp; } else if (strcasecmp(comp->c_name, "disposition") == 0) { dispo_comp = comp; + } else if (strcasecmp(comp->c_name, "hidden") == 0) { + ishidden_comp = comp; } else if (strncasecmp(comp->c_name, "ctype-", 6) == 0 && strlen(comp->c_name) > 6) { pc_entry = mh_xmalloc(sizeof(*pc_entry)); @@ -1287,7 +1290,7 @@ compile_marker(char *markerform) */ static void -output_marker(CT ct, struct format *fmt) +output_marker(CT ct, struct format *fmt, int hidden) { char outbuf[BUFSIZ]; struct param_comp_list *pcentry; @@ -1314,6 +1317,12 @@ output_marker(CT ct, struct format *fmt) dispo_comp->c_text = getcpy(ct->c_dispo_type); } + /* supply a useful string, whose presence or absence can also be + * used as a flag */ + if (ishidden_comp && hidden) { + ishidden_comp->c_text = getcpy("(suppressed)"); + } + for (pcentry = ctype_pc_list; pcentry != NULL; pcentry = pcentry->next) { pcentry->comp->c_text = get_param(ct->c_ctinfo.ci_first_pm, pcentry->param, '?', 0); @@ -1343,6 +1352,7 @@ free_markercomps(void) part_comp = NULL; ctype_comp = NULL; description_comp = NULL; + ishidden_comp = NULL; dispo_comp = NULL; for (pc_entry = ctype_pc_list; pc_entry != NULL; ) { -- 1.7.9.5