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, int, int);
29 int list_switch(CT, int, int, int, int);
30 int list_content(CT, int, int, int, int);
35 static void list_single_message(CT, int, int, int);
36 static int list_debug(CT);
37 static int list_multi(CT, int, int, int, int);
38 static int list_partial(CT, int, int, int, int);
39 static int list_external(CT, int, int, int, int);
40 static int list_encoding(CT);
44 ** various formats for -list option
46 #define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n"
47 #define LSTFMT2a "%4d "
48 #define LSTFMT2b "%-5s %-24.24s "
49 #define LSTFMT2c1 "%5lu"
50 #define LSTFMT2c2 "%4lu%c"
51 #define LSTFMT2c3 "huge "
53 #define LSTFMT2d1 " %-36.36s"
54 #define LSTFMT2d2 "\t %-65.65s\n"
58 ** Top level entry point to list group of messages
61 list_all_messages(CT *cts, int headers, int realsize, int verbose, int debug)
66 printf(LSTFMT1, "msg", "part", "type/subtype", "size",
69 for (ctp = cts; *ctp; ctp++) {
71 list_single_message(ct, realsize, verbose, debug);
79 ** Entry point to list a single message
82 list_single_message(CT ct, int realsize, int verbose, int debug)
86 list_switch(ct, 1, realsize, verbose, debug);
92 (*ct->c_ceclosefnx) (ct);
98 ** Primary switching routine to list information about a content
101 list_switch(CT ct, int toplevel, int realsize, int verbose, int debug)
103 switch (ct->c_type) {
105 return list_multi(ct, toplevel, realsize, verbose, debug);
109 switch (ct->c_subtype) {
110 case MESSAGE_PARTIAL:
111 return list_partial(ct, toplevel, realsize, verbose,
115 case MESSAGE_EXTERNAL:
116 return list_external(ct, toplevel, realsize, verbose,
122 return list_content(ct, toplevel, realsize, verbose,
133 return list_content(ct, toplevel, realsize, verbose, debug);
137 /* list_debug (ct); */
138 adios(NULL, "unknown content type %d", ct->c_type);
142 return 0; /* NOT REACHED */
146 #define empty(s) ((s) ? (s) : "")
149 ** Method for listing information about a simple/generic content
152 list_content(CT ct, int toplevel, int realsize, int verbose, int debug)
155 char *cp, buffer[BUFSIZ];
156 CI ci = &ct->c_ctinfo;
158 printf(toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : " ",
159 atoi(mhbasename(empty(ct->c_file))));
160 snprintf(buffer, sizeof(buffer), "%s/%s", empty(ci->ci_type),
161 empty(ci->ci_subtype));
162 printf(LSTFMT2b, empty(ct->c_partno), buffer);
164 if (ct->c_cesizefnx && realsize)
165 size = (*ct->c_cesizefnx) (ct);
167 size = ct->c_end - ct->c_begin;
169 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
170 for (cp = " KMGT"; size > 9999; size >>= 10)
174 /* print size of this body part */
177 if (size > 0 || ct->c_encoding != CE_EXTERNAL)
178 printf(LSTFMT2c1, size);
184 printf(LSTFMT2c2, size, *cp);
191 /* print Content-Description */
195 dp = trimcpy(cp = getcpy(ct->c_descr));
197 printf(LSTFMT2d1, dp);
205 CI ci = &ct->c_ctinfo;
207 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) {
208 printf("\t %s=\"%s\"\n", *ap, *ep);
212 ** If verbose, print any RFC-822 comments in the
213 ** Content-Type line.
215 if (ci->ci_comment) {
218 dp = trimcpy(cp = add(ci->ci_comment, NULL));
220 snprintf(buffer, sizeof(buffer), "(%s)", dp);
222 printf(LSTFMT2d2, buffer);
234 ** Print debugging information about a content
240 CI ci = &ct->c_ctinfo;
243 fprintf(stderr, " partno \"%s\"\n", empty(ct->c_partno));
245 /* print MIME-Version line */
247 fprintf(stderr, " %s:%s\n", VRSN_FIELD, ct->c_vrsn);
249 /* print Content-Type line */
251 fprintf(stderr, " %s:%s\n", TYPE_FIELD, ct->c_ctline);
253 /* print parsed elements of content type */
254 fprintf(stderr, " type \"%s\"\n", empty(ci->ci_type));
255 fprintf(stderr, " subtype \"%s\"\n", empty(ci->ci_subtype));
256 fprintf(stderr, " comment \"%s\"\n", empty(ci->ci_comment));
257 fprintf(stderr, " magic \"%s\"\n", empty(ci->ci_magic));
259 /* print parsed parameters attached to content type */
260 fprintf(stderr, " parameters\n");
261 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
262 fprintf(stderr, " %s=\"%s\"\n", *ap, *ep);
264 /* print internal flags for type/subtype */
265 fprintf(stderr, " type 0x%x subtype 0x%x params 0x%x\n",
266 ct->c_type, ct->c_subtype,
267 (unsigned int)(unsigned long) ct->c_ctparams);
269 fprintf(stderr, " showproc \"%s\"\n", empty(ct->c_showproc));
270 fprintf(stderr, " termproc \"%s\"\n", empty(ct->c_termproc));
271 fprintf(stderr, " storeproc \"%s\"\n", empty(ct->c_storeproc));
273 /* print transfer encoding information */
275 fprintf(stderr, " %s:%s", ENCODING_FIELD, ct->c_celine);
277 /* print internal flags for transfer encoding */
278 fprintf(stderr, " transfer encoding 0x%x params 0x%x\n",
280 (unsigned int)(unsigned long) ct->c_cefile);
282 /* print Content-ID */
284 fprintf(stderr, " %s:%s", ID_FIELD, ct->c_id);
286 /* print Content-Description */
288 fprintf(stderr, " %s:%s", DESCR_FIELD, ct->c_descr);
290 fprintf(stderr, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
291 (unsigned int)(unsigned long) ct->c_fp,
292 empty(ct->c_file), ct->c_begin, ct->c_end);
294 /* print more information about transfer encoding */
304 ** list content information for type "multipart"
307 list_multi(CT ct, int toplevel, int realsize, int verbose, int debug)
309 struct multipart *m = (struct multipart *) ct->c_ctparams;
312 /* list the content for toplevel of this multipart */
313 list_content(ct, toplevel, realsize, verbose, debug);
315 /* now list for all the subparts */
316 for (part = m->mp_parts; part; part = part->mp_next) {
317 CT p = part->mp_part;
319 if (part_ok(p, 1) && type_ok(p, 1))
320 list_switch(p, 0, realsize, verbose, debug);
328 ** list content information for type "message/partial"
331 list_partial(CT ct, int toplevel, int realsize, int verbose, int debug)
333 struct partial *p = (struct partial *) ct->c_ctparams;
335 list_content(ct, toplevel, realsize, verbose, debug);
337 printf("\t [message %s, part %d",
338 p->pm_partid, p->pm_partno);
340 printf(" of %d", p->pm_maxno);
349 ** list content information for type "message/external"
352 list_external(CT ct, int toplevel, int realsize, int verbose, int debug)
354 struct exbody *e = (struct exbody *) ct->c_ctparams;
357 * First list the information for the
358 * message/external content itself.
360 list_content(ct, toplevel, realsize, verbose, debug);
364 printf("\t name=\"%s\"\n", e->eb_name);
366 printf("\t directory=\"%s\"\n", e->eb_dir);
368 printf("\t site=\"%s\"\n", e->eb_site);
370 printf("\t server=\"%s\"\n", e->eb_server);
372 printf("\t subject=\"%s\"\n", e->eb_subject);
374 /* This must be defined */
375 printf("\t access-type=\"%s\"\n", e->eb_access);
378 printf("\t mode=\"%s\"\n", e->eb_mode);
379 if (e->eb_permission)
380 printf("\t permission=\"%s\"\n", e->eb_permission);
382 if (e->eb_flags == NOTOK)
383 printf("\t [service unavailable]\n");
387 ** Now list the information for the external content
388 ** to which this content points.
390 list_content(e->eb_content, 0, realsize, verbose, debug);
397 ** list information about the Content-Transfer-Encoding
398 ** used by a content.
405 if ((ce = ct->c_cefile))
406 fprintf(stderr, " decoded fp 0x%x file \"%s\"\n",
407 (unsigned int)(unsigned long) ce->ce_fp,
408 ce->ce_file ? ce->ce_file : "");