2 ** mhlistsbr.c -- routines to list information about the
3 ** -- contents of MIME messages
5 ** This code is Copyright (c) 2002, by the authors of nmh. See the
6 ** COPYRIGHT file in the root directory of the nmh distribution for
7 ** complete copyright information.
15 #include <h/mhparse.h>
23 void flush_errors(void);
28 void list_all_messages(CT *, int, int);
29 int list_switch(CT, int, int, int);
30 int list_content(CT, int, int, int);
35 static void list_single_message(CT, int, int);
36 static int list_debug(CT);
37 static int list_multi(CT, int, int, int);
38 static int list_partial(CT, int, int, int);
39 static int list_encoding(CT);
43 ** various formats for -list option
45 #define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n"
46 #define LSTFMT2a "%4d "
47 #define LSTFMT2b "%-5s %-24.24s "
48 #define LSTFMT2c1 "%5lu"
49 #define LSTFMT2c2 "%4lu%c"
50 #define LSTFMT2c3 "huge "
52 #define LSTFMT2d1 " %-36.36s"
53 #define LSTFMT2d2 "\t %-65.65s\n"
57 ** Top level entry point to list group of messages
60 list_all_messages(CT *cts, int verbose, int debug)
64 printf(LSTFMT1, "msg", "part", "type/subtype", "size", "description");
65 for (ctp = cts; *ctp; ctp++) {
67 list_single_message(ct, verbose, debug);
74 ** Entry point to list a single message
77 list_single_message(CT ct, int verbose, int debug)
81 list_switch(ct, 1, verbose, debug);
87 (*ct->c_ceclosefnx) (ct);
93 ** Primary switching routine to list information about a content
96 list_switch(CT ct, int toplevel, int verbose, int debug)
100 return list_multi(ct, toplevel, verbose, debug);
104 if (ct->c_subtype == MESSAGE_PARTIAL) {
105 return list_partial(ct, toplevel, verbose, debug);
107 return list_content(ct, toplevel, verbose, debug);
116 return list_content(ct, toplevel, verbose, debug);
120 /* list_debug (ct); */
121 adios(EX_DATAERR, NULL, "unknown content type %d", ct->c_type);
125 return 0; /* NOT REACHED */
129 #define empty(s) ((s) ? (s) : "")
132 ** Method for listing information about a simple/generic content
135 list_content(CT ct, int toplevel, int verbose, int debug)
138 char *cp, buffer[BUFSIZ];
139 CI ci = &ct->c_ctinfo;
141 printf(toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : " ",
142 atoi(mhbasename(empty(ct->c_file))));
143 snprintf(buffer, sizeof(buffer), "%s/%s", empty(ci->ci_type),
144 empty(ci->ci_subtype));
145 printf(LSTFMT2b, empty(ct->c_partno), buffer);
148 size = (*ct->c_cesizefnx) (ct);
150 size = ct->c_end - ct->c_begin;
152 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
153 for (cp = " KMGT"; size > 9999; size >>= 10)
157 /* print size of this body part */
160 if (size > 0 || ct->c_encoding != CE_EXTERNAL)
161 printf(LSTFMT2c1, size);
167 printf(LSTFMT2c2, size, *cp);
174 /* print Content-Description */
177 dp = trimcpy(cp = mh_xstrdup(ct->c_descr));
179 printf(LSTFMT2d1, dp);
187 CI ci = &ct->c_ctinfo;
189 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
190 printf("\t\t%s=\"%s\"\n", *ap, *ep);
194 ** If verbose, print any RFC-822 comments in the
195 ** Content-Type line.
197 if (ci->ci_comment) {
200 dp = trimcpy(cp = add(ci->ci_comment, NULL));
202 snprintf(buffer, sizeof(buffer), "(%s)", dp);
204 printf(LSTFMT2d2, buffer);
216 ** Print debugging information about a content
222 CI ci = &ct->c_ctinfo;
225 fprintf(stderr, " partno \"%s\"\n", empty(ct->c_partno));
227 /* print MIME-Version line */
229 fprintf(stderr, " %s:%s\n", VRSN_FIELD, ct->c_vrsn);
231 /* print Content-Type line */
233 fprintf(stderr, " %s:%s\n", TYPE_FIELD, ct->c_ctline);
235 /* print parsed elements of content type */
236 fprintf(stderr, " type \"%s\"\n", empty(ci->ci_type));
237 fprintf(stderr, " subtype \"%s\"\n", empty(ci->ci_subtype));
238 fprintf(stderr, " comment \"%s\"\n", empty(ci->ci_comment));
239 fprintf(stderr, " magic \"%s\"\n", empty(ci->ci_magic));
241 /* print parsed parameters attached to content type */
242 fprintf(stderr, " parameters\n");
243 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
244 fprintf(stderr, " %s=\"%s\"\n", *ap, *ep);
246 /* print internal flags for type/subtype */
247 fprintf(stderr, " type 0x%x subtype 0x%x params 0x%x\n",
248 ct->c_type, ct->c_subtype,
249 (unsigned int)(unsigned long) ct->c_ctparams);
251 fprintf(stderr, " charset \"%s\"\n", empty(ct->c_charset));
252 fprintf(stderr, " showproc \"%s\"\n", empty(ct->c_showproc));
253 fprintf(stderr, " storeproc \"%s\"\n", empty(ct->c_storeproc));
255 /* print transfer encoding information */
257 fprintf(stderr, " %s:%s", ENCODING_FIELD, ct->c_celine);
259 /* print internal flags for transfer encoding */
260 fprintf(stderr, " transfer encoding 0x%x params 0x%x\n",
262 (unsigned int)(unsigned long) ct->c_cefile);
264 /* print Content-ID */
266 fprintf(stderr, " %s:%s", ID_FIELD, ct->c_id);
268 /* print Content-Description */
270 fprintf(stderr, " %s:%s", DESCR_FIELD, ct->c_descr);
272 fprintf(stderr, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
273 (unsigned int)(unsigned long) ct->c_fp,
274 empty(ct->c_file), ct->c_begin, ct->c_end);
276 /* print more information about transfer encoding */
286 ** list content information for type "multipart"
289 list_multi(CT ct, int toplevel, int verbose, int debug)
291 struct multipart *m = (struct multipart *) ct->c_ctparams;
294 /* list the content for toplevel of this multipart */
295 list_content(ct, toplevel, verbose, debug);
297 /* now list for all the subparts */
298 for (part = m->mp_parts; part; part = part->mp_next) {
299 CT p = part->mp_part;
301 if (part_ok(p, 1) && type_ok(p, 1))
302 list_switch(p, 0, verbose, debug);
310 ** list content information for type "message/partial"
313 list_partial(CT ct, int toplevel, int verbose, int debug)
315 struct partial *p = (struct partial *) ct->c_ctparams;
317 list_content(ct, toplevel, verbose, debug);
319 printf("\t [message %s, part %d",
320 p->pm_partid, p->pm_partno);
322 printf(" of %d", p->pm_maxno);
331 ** list information about the Content-Transfer-Encoding
332 ** used by a content.
339 if ((ce = ct->c_cefile))
340 fprintf(stderr, " decoded fp 0x%x file \"%s\"\n",
341 (unsigned int)(unsigned long) ce->ce_fp,
342 ce->ce_file ? ce->ce_file : "");