/* profile entry for external url access command */
char *nmhaccessurl = "nmh-access-url";
-char *mhlibexecdir = NMHLIBEXECDIR;
+char *mhbindir = NMHBINDIR;
char *mhetcdir = NMHETCDIR;
+char *mhlibexecdir = NMHLIBEXECDIR;
/*
* nmh not-so constants
- Added mhical(1), to display, reply to, and cancel iCalendar (RFC 5545)
event requests.
- added multiply format function
+- "mhparam bindir" prints the path to the directory containing the public
+ executables (${bindir}).
+- new "-prefer" switch for mhshow (and mhlist and mhshow), to allow specifying
+ the preferred content types to show, if present in a multipart alternative.
+- mh-format now has %(kilo) and %(kibi) functions, to allow printing
+ numbers as, for example, "10K", or "2.3Mi"
-----------------
OBSOLETE FEATURES
#define NPARTS 50
#define NTYPES 20
-#define NPARMS 10
+#define NPREFS 20
/*
* Abstract type for header fields
.RB [ \-type
.IR content ]
\&...
+.RB [ \-prefer
+.IR content ]
+\&...
.RB [ \-headers " | " \-noheaders ]
.RB [ \-realsize " | " \-norealsize ]
.RB [ \-rcache
be used twice: once for message/external-body and once for the content
externally referenced.
.PP
-The parts of a multipart/alternative part are listed in the reverse
-order of their placement in the message. The listing therefore is
-in decreasing order of preference, as defined in RFC 2046.
+By default, the parts of a multipart/alternative part are listed in
+the reverse order of their placement in the message. The listing
+therefore is in decreasing order of preference, as defined in RFC
+2046. The
+.B \-prefer
+switch can be used (one or more times, in order of descending
+preference) to let MH know which content types from a
+multipart/alternative MIME part are preferred by the user, in order to
+override the default preference order. Thus, when viewed by
+.BR mhlist ,
+the ordering of multipart/alternative parts will appear to change when
+invoked with or without various
+.B \-prefer
+switches.
+The
+.B \-prefer
+switch is functionally most important for
+.IR mhshow ,
+but is also implemented in
+.B mhlist
+and
+.B mhstore
+to make common part number ordering possible across all three programs.
.SS "Checking the Contents"
The
.B \-check
can provide other information, such as the
.B nmh
version identifier, the locations of the nmh
+.IR bindir ,
.I etcdir
and
.I libexecdir
.RB [ \-type
.IR content ]
\&...
+.RB [ \-prefer
+.IR content ]
+\&...
.RB [ \-concat " | " \-noconcat ]
.RB [ \-textonly " | " \-notextonly ]
.RB [ \-inlineonly " | " \-noinlineonly ]
messages, see
.IR inc (1)).
.PP
+The
+.B \-part
+switch can be used (one or more times) to restrict the
+set of subparts that will be displayed. (Obviously with no
+.B \-part
+switches, all parts will be considered.) If a
+.B \-part
+switch specifies a specific subpart (i.e., a "leaf" in the tree of
+MIME parts), then that part will always be displayed. If a
+.B \-part
+switch references a multipart/alternative part, then (in
+the absence of a
+.B \-type
+switch) only the default subpart of that multipart will be displayed.
+.PP
A part specification consists of a series of numbers separated by dots.
For example, in a multipart content containing three parts, these
would be named as 1, 2, and 3, respectively. If part 2 was also a
multipart content containing two parts, these would be named as 2.1 and
2.2, respectively. Note that the
.B \-part
-switch is effective for only
+switch is effective only for
messages containing a multipart content. If a message has some other
kind of content, or if the part is itself another multipart content, the
.B \-part
switch will not prevent the content from being acted upon.
.PP
+The
+.B \-type
+switch can also be used to restrict (or, when used in conjunction with
+.BR \-part ,
+to further restrict) the display of parts according to content type.
+One or more
+.B \-type
+switches part will only select the first match
+from a multipart/alternative, even if there is more than one
+subpart that matches (one of) the given content type(s).
+.PP
A content specification consists of a content type and a subtype.
The initial list of \*(lqstandard\*(rq content types and subtypes can
be found in RFC 2046.
To specify a content, regardless of its subtype, just use the
name of the content, e.g., \*(lqaudio\*(rq. To specify a specific
subtype, separate the two with a slash, e.g., \*(lqaudio/basic\*(rq.
-Note that regardless of the values given to the `\-type' switch, a
+Note that regardless of the values given to the
+.B \-type
+switch, a
multipart content (of any subtype listed above) is always acted upon.
-Further note that if the `\-type' switch is used, and it is desirable to
-act on a message/external-body content, then the `\-type' switch must
+Further note that if the
+.B \-type
+switch is used, and it is desirable to
+act on a message/external-body content, then the
+.B \-type
+switch must
be used twice: once for message/external-body and once for the content
externally referenced.
+.PP
+In the absence of
+.BR \-prefer ,
+.B mhshow
+will select the "best" displayable subpart from
+multipart/alternative content. The
+.B \-prefer
+switch can be used (one or more times, in order of descending
+preference) to let MH know which content types from a
+multipart/alternative MIME part are preferred by the user, in order to
+override the default selection for display. For example, mail is
+often sent containing both plaintext and HTML-formatted versions of
+the same content, and the HTML version is usually indicated to be the
+"best" format for viewing. Using \*(lq-prefer text/plain\*(rq will
+cause the plaintext version to be displayed if possible, but still
+allow display of the HTML part if there is no plaintext subpart
+available. Using \*(lq-prefer text/plain -prefer image/png\*(rq
+would add a preference for PNG images, which might or might not
+ever appear in the same multipart/alternative section with text/plain.
+Implementation note: RFC 2046 requires that the subparts
+of a multipart/alternative be ordered according to "faithfulness to
+the original content", and MH by default selects the subpart ranked
+most "faithful" by that ordering. The
+.B \-prefer
+switch reorders the alternative parts (only internally, never changing
+the message file) to move the user's preferred part(s) to the "most
+faithful" position. Thus, when viewed by
+.BR mhlist ,
+the ordering of multipart/alternative parts will appear to change when
+invoked with or without various
+.B \-prefer
+switches.
.SS "Unseen Sequence"
If the profile entry \*(lqUnseen\-Sequence\*(rq is present and
non\-empty, then
.IR iconv (3),
then all text/plain parts of the message(s) will be displayed using
the character set of the current locale. See the
-.BR mhparam (1)
+.IR mhparam (1)
man page for how determine whether your
.B nmh
installation includes
.RB [ \-type
.IR content ]
\&...
+.RB [ \-prefer
+.IR content ]
+\&...
.RB [ \-auto " | " \-noauto ]
.RB [ \-clobber
.IR always " | " auto " | " suffix " | " ask " | " never ]
.B \-type
switch must be used twice: once for message/external-body
and once for the content externally referenced.
+.PP
+The
+.B \-prefer
+switch will alter the part ordering of multipart/alternative MIME sections
+in order to override the sender-imposed default ordering.
+The
+.B \-prefer
+switch is functionally most important for
+.BR mhshow ,
+but is also implemented in
+.B mhlist
+and
+.B mhstore
+to make common part number ordering possible across all three programs.
+See
+.IR mhlist (1)
+and
+.IR mhshow (1)
+for more information on
+.BR \-prefer.
.SS "Checking the Contents"
The
.B \-check
EOF
msgfile=`mhpath new`
+msgnum=`basename $msgfile`
cat > $msgfile <<EOF
To: recipient@example.com, recipient@example.com, recipient@example.com,
recipient@example.com, recipient@example.com, recipient@example.com,
run_prog mhlist last > $actual 2>&1
check $expected $actual
+## now check mhlist output
+
+msgfile=`mhpath new`
+msgnum=`basename $msgfile`
+cat > $msgfile <<EOF
+To: example@example.org
+From: someone <someone@example.com>
+Subject: mhlist test
+Date: Thu, 29 Jan 2015 18:12:21 +0000 (GMT)
+Content-Type: multipart/mixed; boundary="BoundaryMixed"
+
+--BoundaryMixed
+Content-type: multipart/alternative;
+ boundary="BoundaryAlternative1"
+
+--BoundaryAlternative1
+Content-type: text/enriched; CHARSET=US-ASCII
+Content-transfer-encoding: 7bit
+
+This is supposedly enriched.
+
+--BoundaryAlternative1
+Content-type: text/plain; charset=ISO-8859-1; format=flowed
+Content-transfer-encoding: 8bit
+
+This is the body text/plain part.
+
+--BoundaryAlternative1
+Content-type: text/html; CHARSET=US-ASCII
+Content-transfer-encoding: 7bit
+
+<html><body><div><span style="line-height: 1.5;">
+This is the text/html body part.
+</span></div></body></html>
+
+--BoundaryAlternative1--
+
+--BoundaryMixed
+Content-type: multipart/alternative;
+ boundary="BoundaryAlternative2"
+
+--BoundaryAlternative2
+Content-type: audio/wav
+Content-transfer-encoding: 8bit
+
+pretend wav audio
+
+--BoundaryAlternative2
+Content-type: audio/mp3
+Content-transfer-encoding: 8bit
+
+pretend mp3 audio
+
+--BoundaryAlternative2
+Content-type: audio/basic
+Content-transfer-encoding: 8bit
+
+pretend basic audio
+
+--BoundaryAlternative2--
+
+--BoundaryMixed--
+EOF
+
+# Write the expected output.
+cat > $expected <<EOF
+ msg part type/subtype size description
+ 13 multipart/mixed 1038
+ 1 multipart/alternative 518
+ 1.1 text/html 111
+ 1.2 text/plain 34
+ 1.3 text/enriched 29
+ 2 multipart/alternative 326
+ 2.1 audio/basic 20
+ 2.2 audio/mp3 18
+ 2.3 audio/wav 18
+EOF
+
+# check it -- vanilla output
+run_prog mhlist $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+ msg part type/subtype size description
+ 13 multipart/mixed 1038
+ 1 multipart/alternative 518
+ 1.1 text/html 111
+ 1.2 text/plain 34
+ 1.3 text/enriched 29
+ 2 multipart/alternative 326
+EOF
+
+# check it -- just part 1
+run_prog mhlist -part 1 $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+ msg part type/subtype size description
+ 13 multipart/mixed 1038
+ 1 multipart/alternative 518
+ 2 multipart/alternative 326
+EOF
+
+# check it -- ask for audio/basic in part 1, should get nothing
+run_prog mhlist -part 1 -type audio/basic $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+ msg part type/subtype size description
+ 13 multipart/mixed 1038
+ 1 multipart/alternative 518
+ 1.1 text/plain 34
+ 1.2 text/html 111
+ 1.3 text/enriched 29
+ 2 multipart/alternative 326
+ 2.1 audio/wav 18
+ 2.2 audio/basic 20
+ 2.3 audio/mp3 18
+EOF
+
+# check it -- bump plain and wav to the top of their parts
+run_prog mhlist -prefer text/plain -prefer audio/wav $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+ msg part type/subtype size description
+ 13 multipart/mixed 1038
+ 1 multipart/alternative 518
+ 1.1 text/plain 34
+ 1.2 text/enriched 29
+ 1.3 text/html 111
+ 2 multipart/alternative 326
+ 2.1 audio/basic 20
+ 2.2 audio/mp3 18
+ 2.3 audio/wav 18
+EOF
+
+# check it -- bump plain and enriched to the top. add a bogus type as well.
+run_prog mhlist -prefer foo/bar -prefer text/plain -prefer text/enriched $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
exit $failed
run_prog mhshow -part 1.1 -form mhl.null $msgnum > $actual 2>&1
check "$expected" "$actual"
+cat > $msgfile <<EOF
+To: example@example.org
+From: someone <someone@example.com>
+Subject: mhshow -part/-type/prefer test
+Date: Thu, 29 Jan 2015 18:12:21 +0000 (GMT)
+Content-Type: multipart/mixed; boundary="BoundaryMixed"
+
+--BoundaryMixed
+Content-type: multipart/alternative;
+ boundary="BoundaryAlternative1"
+
+--BoundaryAlternative1
+Content-type: text/plain; charset=ISO-8859-1; format=flowed
+Content-transfer-encoding: 8bit
+
+This is the body text/plain part.
+--BoundaryAlternative1
+Content-type: multipart/related;
+ boundary="BoundaryAlternative2"; type="text/html"
+
+--BoundaryAlternative2
+Content-type: text/html; CHARSET=US-ASCII
+Content-transfer-encoding: quoted-printable
+
+<html><body><div><span style=3D"line-height: 1.5;">
+This is the text/html body part.
+</span></div></body></html>
+
+--BoundaryAlternative2--
+
+--BoundaryAlternative1--
+
+--BoundaryMixed
+Content-Type: text/plain; charset="us-ascii"
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Disposition: inline
+
+_______________________________________________
+This is the final text/plain signature part.
+
+--BoundaryMixed--
+EOF
+
+# Write the expected output.
+cat > $expected <<EOF
+[ part 1.1.1 - text/html - 111B ]
+This is the text/html body part.
+EOF
+
+# check it
+run_prog mhshow -part 1.1.1 -form mhl.null $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+[ part 1.2 - text/plain - 33B ]
+This is the body text/plain part.
+EOF
+
+# check it
+run_prog mhshow -part 1.2 -form mhl.null $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+[ part 1.1 - text/plain - 33B ]
+This is the body text/plain part.
+EOF
+
+# check it
+run_prog mhshow -prefer text/plain -part 1 -form mhl.null $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+[ part 2 - text/plain - 93B ]
+_______________________________________________
+This is the final text/plain signature part.
+EOF
+
+# check it
+run_prog mhshow -part 2 -form mhl.null $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+[ part 1.2 - text/plain - 33B ]
+This is the body text/plain part.
+[ part 2 - text/plain - 93B ]
+_______________________________________________
+This is the final text/plain signature part.
+EOF
+
+# check it
+run_prog mhshow -type text/plain -form mhl.null $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
+# Write the expected output.
+cat > $expected <<EOF
+[ part 1.1 - text/plain - 33B ]
+This is the body text/plain part.
+[ part 2 - text/plain - 93B ]
+_______________________________________________
+This is the final text/plain signature part.
+EOF
+
+run_prog mhshow -prefer text/plain -form mhl.null $msgnum > $actual 2>&1
+check "$expected" "$actual"
+
exit $failed
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
int type_ok (CT, int);
void content_error (char *, CT, char *, ...);
void flush_errors (void);
X("file file", 0, FILESW) \
X("part number", 0, PARTSW) \
X("type content", 0, TYPESW) \
+ X("prefer content", 0, PREFERSW) \
X("rcache policy", 0, RCACHESW) \
X("wcache policy", 0, WCACHESW) \
X("changecur", 0, CHGSW) \
extern char *types[NTYPES + 1];
extern int userrs;
+/* mhparse.c */
+extern char *preferred_types[];
+extern char *preferred_subtypes[];
+extern int npreferred;
+
/*
* This is currently needed to keep mhparse happy.
* This needs to be changed.
CT parse_mime (char *);
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
int type_ok (CT, int);
void flush_errors (void);
types[ntype++] = cp;
continue;
+ case PREFERSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ if (npreferred >= NPREFS)
+ adios (NULL, "too many preferred types (starting with %s), %d max",
+ cp, NPREFS);
+ preferred_types[npreferred] = cp;
+ cp = strchr(cp, '/');
+ if (cp) *cp++ = '\0';
+ preferred_subtypes[npreferred++] = cp;
+ continue;
+
case FILESW:
if (!(cp = *argp++) || (*cp == '-' && cp[1]))
adios (NULL, "missing argument to %s", argp[-2]);
#include <h/utils.h>
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
int type_ok (CT, int);
void flush_errors (void);
for (part = m->mp_parts; part; part = part->mp_next) {
CT p = part->mp_part;
- if (part_ok (p, 1) && type_ok (p, 1))
+ if (part_ok (p) && type_ok (p, 1))
list_switch (p, 0, realsize, verbose, debug, dispo);
}
/*
* prototypes
*/
-int part_ok (CT, int);
+int part_ok (CT);
+int part_exact(CT ct);
int type_ok (CT, int);
void content_error (char *, CT, char *, ...);
void flush_errors (void);
int
-part_ok (CT ct, int sP)
+part_ok (CT ct)
{
char **ap;
int len;
- if (npart == 0 || (ct->c_type == CT_MULTIPART && (sP || ct->c_subtype)))
+ /* a part is "ok", i.e., should be processed, if:
+ - there were no -part arguments
+ - this part is a multipart
+ */
+ if (npart == 0 || ct->c_type == CT_MULTIPART) {
return 1;
+ }
+ /* or if:
+ - this part is a an exact match for any -part option
+ - this part is a sub-part of any -part option
+ */
for (ap = parts; *ap; ap++) {
len = strlen(*ap);
if (!strncmp (*ap, ct->c_partno, len) &&
- (!ct->c_partno[len] || ct->c_partno[len] == '.' ))
+ (!ct->c_partno[len] || ct->c_partno[len] == '.' )) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int
+part_exact(CT ct)
+{
+ char **ap;
+
+ if (!ct->c_partno)
+ return 0;
+
+ for (ap = parts; *ap; ap++) {
+ if (!strcmp (*ap, ct->c_partno)) {
return 1;
+ }
}
return 0;
CT parse_mime (char *);
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
int type_ok (CT, int);
void flush_errors (void);
DEFINE_SWITCH_ARRAY(MHPARAM, switches);
#undef X
+extern char *mhbindir;
extern char *mhetcdir;
extern char *mhlibexecdir;
{ "version", &version_num },
{ "whatnowproc", &whatnowproc },
{ "whomproc", &whomproc },
+ { "bindir", &mhbindir },
{ "etcdir", &mhetcdir },
{ "libdir", &mhlibexecdir },
{ "libexecdir", &mhlibexecdir },
int suppress_extraneous_trailing_semicolon_warning;
int extraneous_trailing_semicolon;
+/* list of preferred type/subtype pairs, for -prefer */
+char *preferred_types[NPREFS],
+ *preferred_subtypes[NPREFS];
+int npreferred;
+
+
/*
* Structures for TEXT messages
*/
int find_cache (CT, int, int *, char *, char *, int);
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
int type_ok (CT, int);
void content_error (char *, CT, char *, ...);
static int InitText (CT);
static int InitMultiPart (CT);
static void reverse_parts (CT);
+static void prefer_parts(CT ct);
static int InitMessage (CT);
static int InitApplication (CT);
static int init_encoding (CT, OpenCEFunc);
last_part:
/* reverse the order of the parts for multipart/alternative */
- if (ct->c_subtype == MULTI_ALTERNATE)
+ if (ct->c_subtype == MULTI_ALTERNATE) {
reverse_parts (ct);
+ prefer_parts (ct);
+ }
/*
* label all subparts with part number, and
/*
- * reverse the order of the parts of a multipart/alternative
+ * reverse the order of the parts of a multipart/alternative,
+ * presumably to put the "most favored" alternative first, for
+ * ease of choosing/displaying it later on. from a mail message on
+ * nmh-workers, from kenh:
+ * "Stock" MH 6.8.5 did not have a reverse_parts() function, but I
+ * see code in mhn that did the same thing... Acccording to the RCS
+ * logs, that code was around from the initial checkin of mhn.c by
+ * John Romine in 1992, which is as far back as we have."
*/
-
static void
reverse_parts (CT ct)
{
}
}
+static void
+move_preferred_part (CT ct, char *type, char *subtype)
+{
+ struct multipart *m = (struct multipart *) ct->c_ctparams;
+ struct part *part, *prev, *head, *nhead, *ntail;
+ struct part h, n;
+ CI ci;
+
+ /* move the matching part(s) to the head of the list: walk the
+ * list of parts, move matching parts to a new list (maintaining
+ * their order), and finally, concatenate the old list onto the
+ * new.
+ */
+
+ head = &h;
+ nhead = &n;
+
+ head->mp_next = m->mp_parts;
+ nhead->mp_next = NULL;
+ ntail = nhead;
+
+ prev = head;
+ part = head->mp_next;
+ while (part != NULL) {
+ ci = &part->mp_part->c_ctinfo;
+ if (!strcasecmp(ci->ci_type, type) &&
+ (!subtype || !strcasecmp(ci->ci_subtype, subtype))) {
+ prev->mp_next = part->mp_next;
+ part->mp_next = NULL;
+ ntail->mp_next = part;
+ ntail = part;
+ part = prev->mp_next;
+ } else {
+ prev = part;
+ part = prev->mp_next;
+ }
+ }
+ ntail->mp_next = head->mp_next;
+ m->mp_parts = nhead->mp_next;
+
+}
+
+/*
+ * move parts that match the user's preferences (-prefer) to the head
+ * of the line. process preferences in reverse so first one given
+ * ends up first in line
+ */
+static void
+prefer_parts(CT ct)
+{
+ int i;
+ for (i = npreferred-1; i >= 0; i--)
+ move_preferred_part(ct, preferred_types[i], preferred_subtypes[i]);
+}
X("markform formfile", 0, MARKFORMSW) \
X("part number", 0, PARTSW) \
X("type content", 0, TYPESW) \
+ X("prefer content", 0, PREFERSW) \
X("rcache policy", 0, RCACHESW) \
X("wcache policy", 0, WCACHESW) \
X("version", 0, VERSIONSW) \
extern char *types[NTYPES + 1];
extern int userrs;
+/* mhparse.c */
+extern char *preferred_types[];
+extern char *preferred_subtypes[];
+extern int npreferred;
+
int debugsw = 0;
int verbosw = 0;
CT parse_mime (char *);
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
int type_ok (CT, int);
void flush_errors (void);
types[ntype++] = cp;
continue;
+ case PREFERSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ if (npreferred >= NPREFS)
+ adios (NULL, "too many preferred types (starting with %s), %d max",
+ cp, NPREFS);
+ preferred_types[npreferred] = cp;
+ cp = strchr(cp, '/');
+ if (cp) *cp++ = '\0';
+ preferred_subtypes[npreferred++] = cp;
+ continue;
+
case FILESW:
if (!(cp = *argp++) || (*cp == '-' && cp[1]))
adios (NULL, "missing argument to %s", argp[-2]);
#endif /* ! HAVE_ICONV */
extern int debugsw;
+extern int npart;
+extern int ntype;
int nolist = 0;
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
+int part_exact (CT);
int type_ok (CT, int);
void content_error (char *, CT, char *, ...);
void flush_errors (void);
if ((fd = (*ct->c_ceopenfnx) (ct, &file)) == NOTOK)
return NOTOK;
if (ct->c_showproc && !strcmp (ct->c_showproc, "true"))
- return (alternate ? DONE : OK);
+ return OK;
if (! strcmp(invo_name, "mhshow") &&
ct->c_type == CT_TEXT && ct->c_subtype == TEXT_PLAIN) {
if (fd != NOTOK)
(*ct->c_ceclosefnx) (ct);
- return (alternate ? DONE : status);
+ return (alternate ? OK : status);
}
}
}
if ((cp = context_find_by_type ("show", ci->ci_type, ci->ci_subtype)))
return show_multi_aux (ct, alternate, cp, fmt);
- if ((cp = ct->c_showproc))
+ if ((cp = ct->c_showproc)) {
return show_multi_aux (ct, alternate, cp, fmt);
+ }
/*
* Use default method to display this multipart content. Even
struct multipart *m = (struct multipart *) ct->c_ctparams;
struct part *part;
int request_matched;
+ int display_success;
+ int mult_alt_done;
+ int ret;
CT p;
alternating = 0;
}
/*
- * alternate -> we are a part inside an multipart/alternative
+ * alternate -> we are a part inside a multipart/alternative
* alternating -> we are a multipart/alternative
*/
- result = alternate ? NOTOK : OK;
+ result = NOTOK;
request_matched = 0;
+ display_success = 0;
+ mult_alt_done = 0;
for (part = m->mp_parts; part; part = part->mp_next) {
p = part->mp_part;
- if (part_ok (p, 1) && type_ok (p, 1)) {
- int inneresult;
+ /* while looking for the right displayable alternative, we
+ * use a looser search criterion than we do after finding it.
+ * specifically, while still looking, part_ok() will match
+ * "parent" parts (e.g. "-part 2" where 2 is a high-level
+ * multipart). after finding it, we use part_exact() to only
+ * choose a part that was requested explicitly.
+ */
+ if ((part_exact(p) && type_ok(p, 1)) ||
+ (!mult_alt_done && part_ok (p) && type_ok (p, 1))) {
- request_matched = 1;
+ int inneresult;
inneresult = show_switch (p, nowalternate, concatsw, textonly,
inlineonly, fmt);
switch (inneresult) {
- case NOTOK:
+ case NOTOK: /* hard display error */
+ request_matched = 1;
if (alternate && !alternating) {
result = NOTOK;
goto out;
}
continue;
- case OK:
- case DONE:
+ case DONE: /* found no match on content type */
+ continue;
+
+ case OK: /* display successful */
+ request_matched = 1;
+ display_success = 1;
+ result = OK;
+
+ /* if we got success on a sub-part of
+ * multipart/alternative, we're done, unless
+ * there's a chance an explicit part should be
+ * matched later in the alternatives. */
if (alternating) {
- result = DONE;
- break;
- }
- if (alternate) {
+ mult_alt_done = 1;
+ } else if (alternate) {
alternate = nowalternate = 0;
- if (result == NOTOK)
- result = inneresult;
}
continue;
}
}
}
- if (alternating && !part && request_matched) {
+ /* we're supposed to be displaying at least something from a
+ * multipart/alternative. if we've had parts to consider, and
+ * we've had no success, then we should complain. we shouldn't
+ * complain if none of the parts matched any -part or -type option.
+ */
+ if (alternating && request_matched && !display_success) {
+ /* if we're ourselves an alternate. don't complain yet. */
if (!alternate)
content_error (NULL, ct, "don't know how to display any of the contents");
result = NOTOK;
- goto out;
}
out:
/* if no parts matched what was requested, there can't have been
- * any display errors, so we report OK. */
- return request_matched ? result : OK;
+ * any display errors. we report DONE rather than OK. */
+ ret = request_matched ? result : DONE;
+ return ret;
}
p->c_storage = add (file, NULL);
if (p->c_showproc && !strcmp (p->c_showproc, "true"))
- return (alternate ? DONE : OK);
+ return OK;
(*p->c_ceclosefnx) (p);
}
}
X("outfile outfile", 0, OUTFILESW) \
X("part number", 0, PARTSW) \
X("type content", 0, TYPESW) \
+ X("prefer content", 0, PREFERSW) \
X("rcache policy", 0, RCACHESW) \
X("wcache policy", 0, WCACHESW) \
X("version", 0, VERSIONSW) \
extern char *types[NTYPES + 1];
extern int userrs;
+/* mhparse.c */
+extern char *preferred_types[];
+extern char *preferred_subtypes[];
+extern int npreferred;
+
#define quitser pipeser
/* mhparse.c */
CT parse_mime (char *);
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
int type_ok (CT, int);
void flush_errors (void);
types[ntype++] = cp;
continue;
+ case PREFERSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ if (npreferred >= NPREFS)
+ adios (NULL, "too many preferred types (starting with %s), %d max",
+ cp, NPREFS);
+ preferred_types[npreferred] = cp;
+ cp = strchr(cp, '/');
+ if (cp) *cp++ = '\0';
+ preferred_subtypes[npreferred++] = cp;
+ continue;
+
case FILESW:
if (!(cp = *argp++) || (*cp == '-' && cp[1]))
adios (NULL, "missing argument to %s", argp[-2]);
/* mhmisc.c */
-int part_ok (CT, int);
+int part_ok (CT);
int type_ok (CT, int);
void flush_errors (void);
for (part = m->mp_parts; part; part = part->mp_next) {
CT p = part->mp_part;
- if (part_ok (p, 1) && type_ok (p, 1)) {
+ if (part_ok (p) && type_ok (p, 1)) {
if (ct->c_storage) {
/* Support mhstore -outfile. The MIME parser doesn't
load c_storage, so we know that p->c_storage is