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.
12 #include <h/signals.h>
17 #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(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 */
178 dp = trimcpy(cp = getcpy(ct->c_descr));
180 printf(LSTFMT2d1, dp);
188 CI ci = &ct->c_ctinfo;
190 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
191 printf("\t\t%s=\"%s\"\n", *ap, *ep);
195 ** If verbose, print any RFC-822 comments in the
196 ** Content-Type line.
198 if (ci->ci_comment) {
201 dp = trimcpy(cp = add(ci->ci_comment, NULL));
203 snprintf(buffer, sizeof(buffer), "(%s)", dp);
205 printf(LSTFMT2d2, buffer);
217 ** Print debugging information about a content
223 CI ci = &ct->c_ctinfo;
226 fprintf(stderr, " partno \"%s\"\n", empty(ct->c_partno));
228 /* print MIME-Version line */
230 fprintf(stderr, " %s:%s\n", VRSN_FIELD, ct->c_vrsn);
232 /* print Content-Type line */
234 fprintf(stderr, " %s:%s\n", TYPE_FIELD, ct->c_ctline);
236 /* print parsed elements of content type */
237 fprintf(stderr, " type \"%s\"\n", empty(ci->ci_type));
238 fprintf(stderr, " subtype \"%s\"\n", empty(ci->ci_subtype));
239 fprintf(stderr, " comment \"%s\"\n", empty(ci->ci_comment));
240 fprintf(stderr, " magic \"%s\"\n", empty(ci->ci_magic));
242 /* print parsed parameters attached to content type */
243 fprintf(stderr, " parameters\n");
244 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
245 fprintf(stderr, " %s=\"%s\"\n", *ap, *ep);
247 /* print internal flags for type/subtype */
248 fprintf(stderr, " type 0x%x subtype 0x%x params 0x%x\n",
249 ct->c_type, ct->c_subtype,
250 (unsigned int)(unsigned long) ct->c_ctparams);
252 fprintf(stderr, " charset \"%s\"\n", empty(ct->c_charset));
253 fprintf(stderr, " showproc \"%s\"\n", empty(ct->c_showproc));
254 fprintf(stderr, " storeproc \"%s\"\n", empty(ct->c_storeproc));
256 /* print transfer encoding information */
258 fprintf(stderr, " %s:%s", ENCODING_FIELD, ct->c_celine);
260 /* print internal flags for transfer encoding */
261 fprintf(stderr, " transfer encoding 0x%x params 0x%x\n",
263 (unsigned int)(unsigned long) ct->c_cefile);
265 /* print Content-ID */
267 fprintf(stderr, " %s:%s", ID_FIELD, ct->c_id);
269 /* print Content-Description */
271 fprintf(stderr, " %s:%s", DESCR_FIELD, ct->c_descr);
273 fprintf(stderr, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
274 (unsigned int)(unsigned long) ct->c_fp,
275 empty(ct->c_file), ct->c_begin, ct->c_end);
277 /* print more information about transfer encoding */
287 ** list content information for type "multipart"
290 list_multi(CT ct, int toplevel, int verbose, int debug)
292 struct multipart *m = (struct multipart *) ct->c_ctparams;
295 /* list the content for toplevel of this multipart */
296 list_content(ct, toplevel, verbose, debug);
298 /* now list for all the subparts */
299 for (part = m->mp_parts; part; part = part->mp_next) {
300 CT p = part->mp_part;
302 if (part_ok(p, 1) && type_ok(p, 1))
303 list_switch(p, 0, verbose, debug);
311 ** list content information for type "message/partial"
314 list_partial(CT ct, int toplevel, int verbose, int debug)
316 struct partial *p = (struct partial *) ct->c_ctparams;
318 list_content(ct, toplevel, verbose, debug);
320 printf("\t [message %s, part %d",
321 p->pm_partid, p->pm_partno);
323 printf(" of %d", p->pm_maxno);
332 ** list information about the Content-Transfer-Encoding
333 ** used by a content.
340 if ((ce = ct->c_cefile))
341 fprintf(stderr, " decoded fp 0x%x file \"%s\"\n",
342 (unsigned int)(unsigned long) ce->ce_fp,
343 ce->ce_file ? ce->ce_file : "");