]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
3 * mhlistsbr.c -- routines to list information about the
4 * -- contents of MIME messages
6 * This code is Copyright (c) 2002, by the authors of nmh. See the
7 * COPYRIGHT file in the root directory of the nmh distribution for
8 * complete copyright information.
16 #include <h/mhparse.h>
21 int type_ok (CT
, int);
22 void flush_errors (void);
27 static void list_single_message (CT
, int, int, int, int);
28 static int list_debug (CT
);
29 static int list_multi (CT
, int, int, int, int, int);
30 static int list_partial (CT
, int, int, int, int, int);
31 static int list_external (CT
, int, int, int, int, int);
32 static int list_application (CT
, int, int, int, int, int);
33 static int list_encoding (CT
);
37 * various formats for -list option
39 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
40 #define LSTFMT2a "%4d "
41 #define LSTFMT2b "%-5s %-24.24s "
42 #define LSTFMT2bv "%-5s %-24s "
43 #define LSTFMT2c1 "%5lu"
44 #define LSTFMT2c2 "%4lu%c"
45 #define LSTFMT2c3 "huge "
47 #define LSTFMT2d1 " %.36s"
48 #define LSTFMT2d1v " %s"
49 #define LSTFMT2d2 "\t %-65s\n"
53 * Top level entry point to list group of messages
57 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
63 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
65 for (ctp
= cts
; *ctp
; ctp
++) {
67 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
75 * Entry point to list a single message
79 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
81 if (type_ok (ct
, 1)) {
83 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
89 (*ct
->c_ceclosefnx
) (ct
);
95 * Primary switching routine to list information about a content
99 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
102 switch (ct
->c_type
) {
104 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
107 switch (ct
->c_subtype
) {
108 case MESSAGE_PARTIAL
:
109 return list_partial (ct
, toplevel
, realsize
, verbose
,
112 case MESSAGE_EXTERNAL
:
113 return list_external (ct
, toplevel
, realsize
, verbose
,
118 return list_content (ct
, toplevel
, realsize
, verbose
,
126 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
130 return list_application (ct
, toplevel
, realsize
, verbose
, debug
,
134 return 0; /* NOT REACHED */
138 #define empty(s) ((s) ? (s) : "")
141 * Method for listing information about a simple/generic content
145 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
149 char *cp
, buffer
[BUFSIZ
];
150 CI ci
= &ct
->c_ctinfo
;
154 printf (LSTFMT2a
, atoi (r1bindex (empty (ct
->c_file
), '/')));
156 printf(toplevel
< 0 ? "part " : " ");
158 snprintf (buffer
, sizeof(buffer
), "%s/%s", empty (ci
->ci_type
),
159 empty (ci
->ci_subtype
));
161 printf (LSTFMT2bv
, empty (ct
->c_partno
), buffer
);
163 printf (LSTFMT2b
, empty (ct
->c_partno
), buffer
);
165 if (ct
->c_cesizefnx
&& realsize
)
166 size
= (*ct
->c_cesizefnx
) (ct
);
168 size
= ct
->c_end
- ct
->c_begin
;
170 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
171 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
175 /* print size of this body part */
178 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
179 printf (LSTFMT2c1
, size
);
185 printf (LSTFMT2c2
, size
, *cp
);
192 /* print Content-Description */
196 dp
= cpytrim (ct
->c_descr
);
198 printf (LSTFMT2d1v
, dp
);
200 printf (LSTFMT2d1
, dp
);
207 CI ci
= &ct
->c_ctinfo
;
209 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
210 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
211 get_param_value(pm
, '?'));
215 * If verbose, print any RFC-822 comments in the
218 if (ci
->ci_comment
) {
221 dp
= cpytrim (ci
->ci_comment
);
222 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
224 printf (LSTFMT2d2
, buffer
);
228 if (dispo
&& ct
->c_dispo_type
) {
229 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
232 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
233 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
234 get_param_value(pm
, '?'));
247 * Print debugging information about a content
253 CI ci
= &ct
->c_ctinfo
;
257 fprintf (stderr
, " partno \"%s\"\n", empty (ct
->c_partno
));
259 /* print MIME-Version line */
261 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
263 /* print Content-Type line */
265 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
267 /* print parsed elements of content type */
268 fprintf (stderr
, " type \"%s\"\n", empty (ci
->ci_type
));
269 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
270 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
271 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
273 /* print parsed parameters attached to content type */
274 fprintf (stderr
, " parameters\n");
275 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
276 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
277 get_param_value(pm
, '?'));
279 /* print internal flags for type/subtype */
280 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
281 ct
->c_type
, ct
->c_subtype
,
282 (unsigned int)(unsigned long) ct
->c_ctparams
);
284 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
285 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
286 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
288 /* print transfer encoding information */
290 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
292 /* print internal flags for transfer encoding */
293 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
294 ct
->c_encoding
, (unsigned int)(unsigned long) &ct
->c_cefile
);
296 /* print Content-ID */
298 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
300 /* print Content-Description */
302 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
304 /* print Content-Disposition */
306 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
308 fprintf(stderr
, " disposition \"%s\"\n", empty (ct
->c_dispo_type
));
309 fprintf(stderr
, " disposition parameters\n");
310 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
311 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
312 get_param_value(pm
, '?'));
314 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
315 (unsigned int)(unsigned long) ct
->c_fp
, empty (ct
->c_file
),
316 ct
->c_begin
, ct
->c_end
);
318 /* print more information about transfer encoding */
328 * list content information for type "multipart"
332 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
335 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
338 /* list the content for toplevel of this multipart */
339 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
341 /* now list for all the subparts */
342 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
343 CT p
= part
->mp_part
;
345 if (part_ok (p
) && type_ok (p
, 1))
346 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
354 * list content information for type "message/partial"
358 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
361 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
363 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
365 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
367 printf (" of %d", p
->pm_maxno
);
376 * list content information for type "message/external"
380 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
383 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
386 * First list the information for the
387 * message/external content itself.
389 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
393 printf ("\t name=\"%s\"\n", e
->eb_name
);
395 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
397 printf ("\t site=\"%s\"\n", e
->eb_site
);
399 printf ("\t server=\"%s\"\n", e
->eb_server
);
401 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
403 printf ("\t url=\"%s\"\n", e
->eb_url
);
405 /* This must be defined */
406 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
409 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
410 if (e
->eb_permission
)
411 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
413 if (e
->eb_flags
== NOTOK
)
414 printf ("\t [service unavailable]\n");
419 * Now list the information for the external content
420 * to which this content points.
422 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
429 * list content information for type "application"
430 * This no longer needs to be a separate function. It used to
431 * produce some output with verbose enabled, but that has been
432 * moved to list_content ().
436 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
439 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
446 * list information about the Content-Transfer-Encoding
451 list_encoding (CT ct
)
453 CE ce
= &ct
->c_cefile
;
455 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
456 (unsigned int)(unsigned long) ce
->ce_fp
,
457 ce
->ce_file
? ce
->ce_file
: "");