3 * mhlistsbr.c -- routines to list information about the
4 * -- contents of MIME messages
11 #include <h/signals.h>
14 #include <zotnet/mts/mts.h>
15 #include <zotnet/tws/tws.h>
17 #include <h/mhparse.h>
22 int part_ok (CT, int);
23 int type_ok (CT, int);
24 void flush_errors (void);
29 void list_all_messages (CT *, int, int, int, int);
30 int list_switch (CT, int, int, int, int);
31 int list_content (CT, int, int, int, int);
36 static void list_single_message (CT, int, int, int);
37 static int list_debug (CT);
38 static int list_multi (CT, int, int, int, int);
39 static int list_partial (CT, int, int, int, int);
40 static int list_external (CT, int, int, int, int);
41 static int list_application (CT, int, int, int, int);
42 static int list_encoding (CT);
46 * various formats for -list option
48 #define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n"
49 #define LSTFMT2a "%4d "
50 #define LSTFMT2b "%-5s %-24.24s "
51 #define LSTFMT2c1 "%5lu"
52 #define LSTFMT2c2 "%4lu%c"
53 #define LSTFMT2c3 "huge "
55 #define LSTFMT2d1 " %-36.36s"
56 #define LSTFMT2d2 "\t %-65.65s\n"
60 * Top level entry point to list group of messages
64 list_all_messages (CT *cts, int headers, int realsize, int verbose, int debug)
69 printf (LSTFMT1, "msg", "part", "type/subtype", "size", "description");
71 for (ctp = cts; *ctp; ctp++) {
73 list_single_message (ct, realsize, verbose, debug);
81 * Entry point to list a single message
85 list_single_message (CT ct, int realsize, int verbose, int debug)
87 if (type_ok (ct, 1)) {
89 list_switch (ct, 1, realsize, verbose, debug);
95 (*ct->c_ceclosefnx) (ct);
101 * Primary switching routine to list information about a content
105 list_switch (CT ct, int toplevel, int realsize, int verbose, int debug)
107 switch (ct->c_type) {
109 return list_multi (ct, toplevel, realsize, verbose, debug);
113 switch (ct->c_subtype) {
114 case MESSAGE_PARTIAL:
115 return list_partial (ct, toplevel, realsize, verbose, debug);
118 case MESSAGE_EXTERNAL:
119 return list_external (ct, toplevel, realsize, verbose, debug);
124 return list_content (ct, toplevel, realsize, verbose, debug);
133 return list_content (ct, toplevel, realsize, verbose, debug);
137 return list_application (ct, toplevel, realsize, verbose, debug);
141 /* list_debug (ct); */
142 adios (NULL, "unknown content type %d", ct->c_type);
146 return 0; /* NOT REACHED */
150 #define empty(s) ((s) ? (s) : "")
153 * Method for listing information about a simple/generic content
157 list_content (CT ct, int toplevel, int realsize, int verbose, int debug)
160 char *cp, buffer[BUFSIZ];
161 CI ci = &ct->c_ctinfo;
163 printf (toplevel > 0 ? LSTFMT2a : toplevel < 0 ? "part " : " ",
164 atoi (r1bindex (empty (ct->c_file), '/')));
165 snprintf (buffer, sizeof(buffer), "%s/%s", empty (ci->ci_type),
166 empty (ci->ci_subtype));
167 printf (LSTFMT2b, empty (ct->c_partno), buffer);
169 if (ct->c_cesizefnx && realsize)
170 size = (*ct->c_cesizefnx) (ct);
172 size = ct->c_end - ct->c_begin;
174 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
175 for (cp = " KMGT"; size > 9999; size >>= 10)
179 /* print size of this body part */
182 if (size > 0 || ct->c_encoding != CE_EXTERNAL)
183 printf (LSTFMT2c1, size);
189 printf (LSTFMT2c2, size, *cp);
196 /* print Content-Description */
200 dp = trimcpy (cp = add (ct->c_descr, NULL));
202 printf (LSTFMT2d1, dp);
209 * If verbose, print any RFC-822 comments in the
212 if (verbose && ci->ci_comment) {
215 dp = trimcpy (cp = add (ci->ci_comment, NULL));
217 snprintf (buffer, sizeof(buffer), "(%s)", dp);
219 printf (LSTFMT2d2, buffer);
230 * Print debugging information about a content
237 CI ci = &ct->c_ctinfo;
240 fprintf (stderr, " partno \"%s\"\n", empty (ct->c_partno));
242 /* print MIME-Version line */
244 fprintf (stderr, " %s:%s\n", VRSN_FIELD, ct->c_vrsn);
246 /* print Content-Type line */
248 fprintf (stderr, " %s:%s\n", TYPE_FIELD, ct->c_ctline);
250 /* print parsed elements of content type */
251 fprintf (stderr, " type \"%s\"\n", empty (ci->ci_type));
252 fprintf (stderr, " subtype \"%s\"\n", empty (ci->ci_subtype));
253 fprintf (stderr, " comment \"%s\"\n", empty (ci->ci_comment));
254 fprintf (stderr, " magic \"%s\"\n", empty (ci->ci_magic));
256 /* print parsed parameters attached to content type */
257 fprintf (stderr, " parameters\n");
258 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
259 fprintf (stderr, " %s=\"%s\"\n", *ap, *ep);
261 /* print internal flags for type/subtype */
262 fprintf (stderr, " type 0x%x subtype 0x%x params 0x%x\n",
263 ct->c_type, ct->c_subtype, (unsigned int) ct->c_ctparams);
265 fprintf (stderr, " showproc \"%s\"\n", empty (ct->c_showproc));
266 fprintf (stderr, " termproc \"%s\"\n", empty (ct->c_termproc));
267 fprintf (stderr, " storeproc \"%s\"\n", empty (ct->c_storeproc));
269 /* print transfer encoding information */
271 fprintf (stderr, " %s:%s", ENCODING_FIELD, ct->c_celine);
273 /* print internal flags for transfer encoding */
274 fprintf (stderr, " transfer encoding 0x%x params 0x%x\n",
275 ct->c_encoding, (unsigned int) ct->c_cefile);
277 /* print Content-ID */
279 fprintf (stderr, " %s:%s", ID_FIELD, ct->c_id);
281 /* print Content-Description */
283 fprintf (stderr, " %s:%s", DESCR_FIELD, ct->c_descr);
285 fprintf (stderr, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
286 (unsigned int) ct->c_fp, empty (ct->c_file),
287 ct->c_begin, ct->c_end);
289 /* print more information about transfer encoding */
299 * list content information for type "multipart"
303 list_multi (CT ct, int toplevel, int realsize, int verbose, int debug)
305 struct multipart *m = (struct multipart *) ct->c_ctparams;
308 /* list the content for toplevel of this multipart */
309 list_content (ct, toplevel, realsize, verbose, debug);
311 /* now list for all the subparts */
312 for (part = m->mp_parts; part; part = part->mp_next) {
313 CT p = part->mp_part;
315 if (part_ok (p, 1) && type_ok (p, 1))
316 list_switch (p, 0, realsize, verbose, debug);
324 * list content information for type "message/partial"
328 list_partial (CT ct, int toplevel, int realsize, int verbose, int debug)
330 struct partial *p = (struct partial *) ct->c_ctparams;
332 list_content (ct, toplevel, realsize, verbose, debug);
334 printf ("\t [message %s, part %d", p->pm_partid, p->pm_partno);
336 printf (" of %d", p->pm_maxno);
345 * list content information for type "message/external"
349 list_external (CT ct, int toplevel, int realsize, int verbose, int debug)
351 struct exbody *e = (struct exbody *) ct->c_ctparams;
354 * First list the information for the
355 * message/external content itself.
357 list_content (ct, toplevel, realsize, verbose, debug);
361 printf ("\t name=\"%s\"\n", e->eb_name);
363 printf ("\t directory=\"%s\"\n", e->eb_dir);
365 printf ("\t site=\"%s\"\n", e->eb_site);
367 printf ("\t server=\"%s\"\n", e->eb_server);
369 printf ("\t subject=\"%s\"\n", e->eb_subject);
371 /* This must be defined */
372 printf ("\t access-type=\"%s\"\n", e->eb_access);
375 printf ("\t mode=\"%s\"\n", e->eb_mode);
376 if (e->eb_permission)
377 printf ("\t permission=\"%s\"\n", e->eb_permission);
379 if (e->eb_flags == NOTOK)
380 printf ("\t [service unavailable]\n");
384 * Now list the information for the external content
385 * to which this content points.
387 list_content (e->eb_content, 0, realsize, verbose, debug);
394 * list content information for type "application"
398 list_application (CT ct, int toplevel, int realsize, int verbose, int debug)
400 list_content (ct, toplevel, realsize, verbose, debug);
403 CI ci = &ct->c_ctinfo;
405 for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++)
406 printf ("\t %s=\"%s\"\n", *ap, *ep);
414 * list information about the Content-Transfer-Encoding
419 list_encoding (CT ct)
423 if ((ce = ct->c_cefile))
424 fprintf (stderr, " decoded fp 0x%x file \"%s\"\n",
425 (unsigned int) ce->ce_fp, ce->ce_file ? ce->ce_file : "");