--- /dev/null
+%;
+%; This is provided as reference only; it shows the default content marker
+%; used by mhshow when it decides to not display content.
+%;
+[ Message %{folder}%<{folder}:%>%(msg) ]
* markerform - The name of a file containg mh-format(5) code used to
* display markers about non-displayed MIME parts.
*/
-void show_all_messages(CT *cts, int concat, int textonly, int inlineonly,
- char *markerform);
+void show_all_messages(CT *cts, int concat, int textonly, int inlineonly);
/*
* Display (or store) a single MIME part using the specified command
* Show the message content
*/
if (showsw)
- show_all_messages (cts, 0, 0, 0, NULL);
+ show_all_messages (cts, 0, 0, 0);
/* Now free all the structures for the content */
for (ctp = cts; *ctp; ctp++)
X("noinlineonly", 0, NINLINESW) \
X("file file", 0, FILESW) \
X("form formfile", 0, FORMSW) \
+ X("header", 0, HEADSW) \
+ X("noheader", 0, NHEADSW) \
+ X("headerform formfile", 0, HEADFORMSW) \
X("markform formfile", 0, MARKFORMSW) \
X("part number", 0, PARTSW) \
X("type content", 0, TYPESW) \
extern char *progsw;
extern int nomore; /* flags for moreproc/header display */
extern char *formsw;
+extern char *folder;
+extern char *headerform;
+extern char *markerform;
+extern int headersw;
/* mhmisc.c */
extern int npart;
main (int argc, char **argv)
{
int msgnum, *icachesw, concatsw = -1, textonly = -1, inlineonly = -1;
- char *cp, *file = NULL, *folder = NULL, *markform = NULL;
+ char *cp, *file = NULL;
char *maildir, buf[100], **argp;
char **arguments;
struct msgs_array msgs = { 0, 0, NULL };
while ((cp = *argp++)) {
if (*cp == '-') {
switch (smatch (++cp, switches)) {
- case AMBIGSW:
+ case AMBIGSW:
ambigsw (cp, switches);
done (1);
- case UNKWNSW:
+ case UNKWNSW:
adios (NULL, "-%s unknown", cp);
- case HELPSW:
+ case HELPSW:
snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
invo_name);
print_help (buf, switches, 1);
formsw = getcpy (etcpath (cp));
continue;
+ case HEADSW:
+ headersw = 1;
+ continue;
+ case NHEADSW:
+ headersw = 0;
+ continue;
+
+ case HEADFORMSW:
+ if (!(headerform = *argp++) || *headerform == '-')
+ adios (NULL, "missing argument to %s", argp[-2]);
+ continue;
+
case MARKFORMSW:
- if (!(markform = *argp++) || *markform == '-')
+ if (!(markerform = *argp++) || *markerform == '-')
adios (NULL, "missing argument to %s", argp[-2]);
continue;
adios (NULL, "missing argument to %s", argp[-2]);
continue;
- case VERBSW:
+ case VERBSW:
verbosw = 1;
continue;
- case NVERBSW:
+ case NVERBSW:
verbosw = 0;
continue;
case DEBUGSW:
if ((ct = parse_mime (file)))
*ctp++ = ct;
+
+ headersw = 0;
} else {
/*
* message(s) are coming from a folder
/*
* Show the message content
*/
- show_all_messages (cts, concatsw, textonly, inlineonly, markform);
+ show_all_messages (cts, concatsw, textonly, inlineonly);
/* Now free all the structures for the content */
for (ctp = cts; *ctp; ctp++)
int nomore = 0;
char *formsw = NULL;
+/* for output markerss and headers */
+char *folder = NULL;
+char *markerform;
+char *headerform;
+int headersw = -1;
+
/* mhmisc.c */
int part_ok (CT);
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_header(char *);
static struct format *compile_marker(char *);
+static void output_header (CT, struct format *);
static void output_marker (CT, struct format *, int);
static void free_markercomps (void);
static int pidcheck(int);
* content marker display.
*/
+static struct comp *folder_comp = NULL;
static struct comp *part_comp = NULL;
static struct comp *ctype_comp = NULL;
static struct comp *description_comp = NULL;
*/
void
-show_all_messages (CT *cts, int concatsw, int textonly, int inlineonly,
- char *markerform)
+show_all_messages (CT *cts, int concatsw, int textonly, int inlineonly)
{
CT ct, *ctp;
- struct format *fmt;
+ struct format *hfmt, *mfmt;
/*
* If form is not specified, then get default form
formsw = getcpy (etcpath ("mhl.headers"));
/*
- * Compile the content marker format line
+ * Compile the content marker and header format lines
*/
- fmt = compile_marker(markerform);
+ mfmt = compile_marker(markerform);
+ hfmt = compile_header(headerform);
/*
* If form is "mhl.null", suppress display of header.
/* if top-level type is ok, then display message */
if (type_ok (ct, 1))
+ if (headersw) output_header(ct, hfmt);
+
show_single_message (ct, formsw, concatsw, textonly, inlineonly,
- fmt);
+ mfmt);
}
free_markercomps();
- fmt_free(fmt, 1);
+ fmt_free(hfmt, 1);
+ fmt_free(mfmt, 1);
}
* Compile our format string and save any parameters we care about.
*/
+#define DEFAULT_HEADER "[ Message %{folder}%<{folder}:%>%(msg) ]"
#define DEFAULT_MARKER "[ part %{part} - %{content-type} - " \
"%<{description}%{description}" \
"%?{cdispo-filename}%{cdispo-filename}" \
"%(kilo(size))B %<(unseen)\\(suppressed\\)%> ]"
static struct format *
-compile_marker(char *markerform)
+compile_header(char *form)
+{
+ struct format *fmt;
+ char *fmtstring;
+ struct comp *comp = NULL;
+ unsigned int bucket;
+
+ fmtstring = new_fs(form, NULL, DEFAULT_HEADER);
+
+ (void) fmt_compile(fmtstring, &fmt, 1);
+ free_fs();
+
+ while ((comp = fmt_nextcomp(comp, &bucket)) != NULL) {
+ if (strcasecmp(comp->c_name, "folder") == 0) {
+ folder_comp = comp;
+ }
+ }
+
+ return fmt;
+}
+
+static struct format *
+compile_marker(char *form)
{
struct format *fmt;
char *fmtstring;
unsigned int bucket;
struct param_comp_list *pc_entry;
- fmtstring = new_fs(markerform, NULL, DEFAULT_MARKER);
+ fmtstring = new_fs(form, NULL, DEFAULT_MARKER);
(void) fmt_compile(fmtstring, &fmt, 1);
- free(fmtstring);
+ free_fs();
/*
* Things we care about:
* Output on stdout an appropriate marker for this content, using mh-format
*/
+static void
+output_header(CT ct, struct format *fmt)
+{
+ charstring_t outbuf = charstring_create (BUFSIZ);
+ int dat[5];
+ char *endp;
+ int message = 0;
+
+ dat[0] = dat[1] = dat[2] = dat[3] = dat[4] = dat[5] = 0;
+
+ if (folder_comp)
+ folder_comp->c_text = getcpy(folder);
+
+ if (ct->c_file && *ct->c_file) {
+ message = strtol(ct->c_file, &endp, 10);
+ if (*endp) message = 0;
+ dat[0] = message;
+ }
+
+ /* it would be nice to populate dat[2], for %(size) here,
+ * but it's not available. it might also be nice to know
+ * if the message originally had any mime parts or not -- but
+ * there's also no record of that. (except for MIME-version:)
+ */
+
+ fmt_scan(fmt, outbuf, BUFSIZ, dat, NULL);
+
+ fputs(charstring_buffer (outbuf), stdout);
+ charstring_free (outbuf);
+
+ fmt_freecomptext();
+}
+
static void
output_marker(CT ct, struct format *fmt, int hidden)
{
charstring_t outbuf = charstring_create (BUFSIZ);
struct param_comp_list *pcentry;
int partsize;
+ int message = 0;
+ char *endp;
int dat[5];
+ dat[0] = dat[1] = dat[2] = dat[3] = dat[4] = dat[5] = 0;
+
/*
* Grab any items we care about.
*/
else
partsize = ct->c_end - ct->c_begin;
+ if (ct->c_file && *ct->c_file) {
+ message = strtol(ct->c_file, &endp, 10);
+ if (*endp) message = 0;
+ dat[0] = message;
+ }
+ dat[2] = partsize;
+
/* make the part's hidden aspect available by overloading the
* %(unseen) function. make the part's size available via %(size).
* see comments in h/fmt_scan.h.
*/
- dat[2] = partsize;
dat[4] = hidden;
- dat[0] = dat[1] = dat[3] = 0;
fmt_scan(fmt, outbuf, BUFSIZ, dat, NULL);
{
struct param_comp_list *pc_entry, *pc2;
+ folder_comp = NULL;
part_comp = NULL;
ctype_comp = NULL;
description_comp = NULL;
-
/*
* show.c -- show/list messages
*
while ((cp = *argp++)) {
if (*cp == '-') {
switch (smatch (++cp, switches)) {
- case AMBIGSW:
+ case AMBIGSW:
ambigsw (cp, switches);
done (1);
+ case HEADSW:
+ headersw = 1;
+ goto non_mhl_switches;
+ case NHEADSW:
+ headersw = 0;
case CONCATSW:
case NCONCATSW:
+non_mhl_switches:
/* mhl can't handle these, so keep them separate. */
app_msgarg(&non_mhl_vec, --cp);
continue;
- case UNKWNSW:
+ case UNKWNSW:
case NPROGSW:
case NFMTPROCSW:
app_msgarg(&vec, --cp);
continue;
- case HELPSW:
+ case HELPSW:
snprintf (buf, sizeof(buf),
"%s [+folder] %s[switches] [switches for showproc]",
invo_name, mode == SHOW ? "[msgs] ": "");
print_version(invo_name);
done (0);
- case DRFTSW:
+ case DRFTSW:
if (file)
adios (NULL, "only one file at a time!");
draftsw++;
adios (NULL,
"usage: %s [+folder] [switches] [switches for showproc]",
invo_name);
- case FILESW:
+ case FILESW:
if (mode != SHOW)
goto usage;
if (draftsw || file)
file = path (cp, TFILE);
continue;
- case HEADSW:
- headersw++;
- continue;
- case NHEADSW:
- headersw = 0;
- continue;
-
case FORMSW:
app_msgarg(&vec, --cp);
if (!(cp = *argp++) || *cp == '-')
app_msgarg(&vec, cp);
continue;
- case SHOWSW:
+ case SHOWSW:
if (!(showproc = *argp++) || *showproc == '-')
adios (NULL, "missing argument to %s", argp[-2]);
nshow = 0;
continue;
- case NSHOWSW:
+ case NSHOWSW:
nshow++;
continue;
app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf)));
else
app_msgarg(&vec, file);
+ headersw = 0;
goto go_to_it;
}
context_replace (pfolder, folder); /* update current folder */
context_save (); /* save the context file */
- if (headersw && vec.size == 1)
- printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
-
go_to_it: ;
- fflush (stdout);
/*
* Decide which "proc" to use
if (folder && !draftsw && !file)
m_putenv ("mhfolder", folder);
- if (strcmp (r1bindex (proc, '/'), "mhl") == 0) {
+ if (strcmp (r1bindex (proc, '/'), "cat") == 0) {
+
+ if (headersw && vec.size == 1)
+ printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
+
+ } else if (strcmp (r1bindex (proc, '/'), "mhl") == 0) {
+
+ if (headersw && vec.size == 1)
+ printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
+
/* If "mhl", then run it internally */
argsplit_insert(&vec, "mhl", &program);
app_msgarg(&vec, NULL);
mhl (vec.size, vec.msgs);
done (0);
+
} else {
int i;
char **mp;
app_msgarg(&vec, vec.msgs[vec.size - 1]);
vec.msgs[vec.size - 2] = "-file";
}
+ } else {
+ if (headersw && vec.size == 1)
+ printf ("(Message %s:%s)\n", folder, vec.msgs[0]);
}
}
+ fflush (stdout);
+
argsplit_insert(&vec, proc, &program);
app_msgarg(&vec, NULL);
execvp (program, vec.msgs);