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>
21 void flush_errors(void);
26 void list_all_messages(CT *, int, int);
27 int list_switch(CT, int, int, int);
28 int list_content(CT, int, int, int);
33 static void list_single_message(CT, int, int);
34 static int list_debug(CT);
35 static int list_multi(CT, int, int, int);
36 static int list_partial(CT, int, int, int);
37 static int list_encoding(CT);
41 ** various formats for -list option
43 #define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n"
44 #define LSTFMT2a "%4d "
45 #define LSTFMT2b "%-5s %-24.24s "
46 #define LSTFMT2c1 "%5lu"
47 #define LSTFMT2c2 "%4lu%c"
48 #define LSTFMT2c3 "huge "
50 #define LSTFMT2d1 " %-36.36s"
51 #define LSTFMT2d2 "\t %-65.65s\n"
55 ** Top level entry point to list group of messages
58 list_all_messages(CT *cts, int verbose, int debug)
62 printf(LSTFMT1, "msg", "part", "type/subtype", "size", "description");
63 for (ctp = cts; *ctp; ctp++) {
65 list_single_message(ct, verbose, debug);
72 ** Entry point to list a single message
75 list_single_message(CT ct, int verbose, int debug)
79 list_switch(ct, 1, verbose, debug);
85 (*ct->c_ceclosefnx) (ct);
91 ** Primary switching routine to list information about a content
94 list_switch(CT ct, int toplevel, int verbose, int debug)
98 return list_multi(ct, toplevel, verbose, debug);
102 if (ct->c_subtype == MESSAGE_PARTIAL) {
103 return list_partial(ct, toplevel, verbose, debug);
105 return list_content(ct, toplevel, verbose, debug);
114 return list_content(ct, toplevel, verbose, debug);
118 /* list_debug (ct); */
119 adios(NULL, "unknown content type %d", ct->c_type);
123 return 0; /* NOT REACHED */
127 #define empty(s) ((s) ? (s) : "")
130 ** Method for listing information about a simple/generic content
133 list_content(CT ct, int toplevel, int verbose, int debug)
136 char *cp, buffer[BUFSIZ];
137 CI ci = &ct->c_ctinfo;
139 printf(toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : " ",
140 atoi(mhbasename(empty(ct->c_file))));
141 snprintf(buffer, sizeof(buffer), "%s/%s", empty(ci->ci_type),
142 empty(ci->ci_subtype));
143 printf(LSTFMT2b, empty(ct->c_partno), buffer);
146 size = (*ct->c_cesizefnx) (ct);
148 size = ct->c_end - ct->c_begin;
150 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
151 for (cp = " KMGT"; size > 9999; size >>= 10)
155 /* print size of this body part */
158 if (size > 0 || ct->c_encoding != CE_EXTERNAL)
159 printf(LSTFMT2c1, size);
165 printf(LSTFMT2c2, size, *cp);
172 /* print Content-Description */
176 dp = trimcpy(cp = getcpy(ct->c_descr));
178 printf(LSTFMT2d1, dp);
186 CI ci = &ct->c_ctinfo;
188 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
189 printf("\t\t%s=\"%s\"\n", *ap, *ep);
193 ** If verbose, print any RFC-822 comments in the
194 ** Content-Type line.
196 if (ci->ci_comment) {
199 dp = trimcpy(cp = add(ci->ci_comment, NULL));
201 snprintf(buffer, sizeof(buffer), "(%s)", dp);
203 printf(LSTFMT2d2, buffer);
215 ** Print debugging information about a content
221 CI ci = &ct->c_ctinfo;
224 fprintf(stderr, " partno \"%s\"\n", empty(ct->c_partno));
226 /* print MIME-Version line */
228 fprintf(stderr, " %s:%s\n", VRSN_FIELD, ct->c_vrsn);
230 /* print Content-Type line */
232 fprintf(stderr, " %s:%s\n", TYPE_FIELD, ct->c_ctline);
234 /* print parsed elements of content type */
235 fprintf(stderr, " type \"%s\"\n", empty(ci->ci_type));
236 fprintf(stderr, " subtype \"%s\"\n", empty(ci->ci_subtype));
237 fprintf(stderr, " comment \"%s\"\n", empty(ci->ci_comment));
238 fprintf(stderr, " magic \"%s\"\n", empty(ci->ci_magic));
240 /* print parsed parameters attached to content type */
241 fprintf(stderr, " parameters\n");
242 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
243 fprintf(stderr, " %s=\"%s\"\n", *ap, *ep);
245 /* print internal flags for type/subtype */
246 fprintf(stderr, " type 0x%x subtype 0x%x params 0x%x\n",
247 ct->c_type, ct->c_subtype,
248 (unsigned int)(unsigned long) ct->c_ctparams);
250 fprintf(stderr, " charset \"%s\"\n", empty(ct->c_charset));
251 fprintf(stderr, " showproc \"%s\"\n", empty(ct->c_showproc));
252 fprintf(stderr, " storeproc \"%s\"\n", empty(ct->c_storeproc));
254 /* print transfer encoding information */
256 fprintf(stderr, " %s:%s", ENCODING_FIELD, ct->c_celine);
258 /* print internal flags for transfer encoding */
259 fprintf(stderr, " transfer encoding 0x%x params 0x%x\n",
261 (unsigned int)(unsigned long) ct->c_cefile);
263 /* print Content-ID */
265 fprintf(stderr, " %s:%s", ID_FIELD, ct->c_id);
267 /* print Content-Description */
269 fprintf(stderr, " %s:%s", DESCR_FIELD, ct->c_descr);
271 fprintf(stderr, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
272 (unsigned int)(unsigned long) ct->c_fp,
273 empty(ct->c_file), ct->c_begin, ct->c_end);
275 /* print more information about transfer encoding */
285 ** list content information for type "multipart"
288 list_multi(CT ct, int toplevel, int verbose, int debug)
290 struct multipart *m = (struct multipart *) ct->c_ctparams;
293 /* list the content for toplevel of this multipart */
294 list_content(ct, toplevel, verbose, debug);
296 /* now list for all the subparts */
297 for (part = m->mp_parts; part; part = part->mp_next) {
298 CT p = part->mp_part;
300 if (part_ok(p, 1) && type_ok(p, 1))
301 list_switch(p, 0, verbose, debug);
309 ** list content information for type "message/partial"
312 list_partial(CT ct, int toplevel, int verbose, int debug)
314 struct partial *p = (struct partial *) ct->c_ctparams;
316 list_content(ct, toplevel, verbose, debug);
318 printf("\t [message %s, part %d",
319 p->pm_partid, p->pm_partno);
321 printf(" of %d", p->pm_maxno);
330 ** list information about the Content-Transfer-Encoding
331 ** used by a content.
338 if ((ce = ct->c_cefile))
339 fprintf(stderr, " decoded fp 0x%x file \"%s\"\n",
340 (unsigned int)(unsigned long) ce->ce_fp,
341 ce->ce_file ? ce->ce_file : "");