]>
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.
13 #include <h/signals.h>
17 #include <h/mhparse.h>
21 int part_ok (CT
, int);
22 int type_ok (CT
, int);
23 void flush_errors (void);
28 static void list_single_message (CT
, int, int, int, int);
29 static int list_debug (CT
);
30 static int list_multi (CT
, int, int, int, int, int);
31 static int list_partial (CT
, int, int, int, int, int);
32 static int list_external (CT
, int, int, int, int, int);
33 static int list_application (CT
, int, int, int, int, int);
34 static int list_encoding (CT
);
38 * various formats for -list option
40 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
41 #define LSTFMT2a "%4d "
42 #define LSTFMT2b "%-5s %-24.24s "
43 #define LSTFMT2c1 "%5lu"
44 #define LSTFMT2c2 "%4lu%c"
45 #define LSTFMT2c3 "huge "
47 #define LSTFMT2d1 " %.36s"
48 #define LSTFMT2d2 "\t %-65.65s\n"
52 * Top level entry point to list group of messages
56 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
62 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
64 for (ctp
= cts
; *ctp
; ctp
++) {
66 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
74 * Entry point to list a single message
78 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
80 if (type_ok (ct
, 1)) {
82 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
88 (*ct
->c_ceclosefnx
) (ct
);
94 * Primary switching routine to list information about a content
98 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
101 switch (ct
->c_type
) {
103 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
106 switch (ct
->c_subtype
) {
107 case MESSAGE_PARTIAL
:
108 return list_partial (ct
, toplevel
, realsize
, verbose
,
111 case MESSAGE_EXTERNAL
:
112 return list_external (ct
, toplevel
, realsize
, verbose
,
117 return list_content (ct
, toplevel
, realsize
, verbose
,
125 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
128 return list_application (ct
, toplevel
, realsize
, verbose
, debug
,
132 /* list_debug (ct); */
133 adios (NULL
, "unknown content type %d", ct
->c_type
);
136 return 0; /* NOT REACHED */
140 #define empty(s) ((s) ? (s) : "")
143 * Method for listing information about a simple/generic content
147 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
151 char *cp
, buffer
[BUFSIZ
];
152 CI ci
= &ct
->c_ctinfo
;
156 printf (LSTFMT2a
, atoi (r1bindex (empty (ct
->c_file
), '/')));
158 printf(toplevel
< 0 ? "part " : " ");
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
= cpytrim (ct
->c_descr
);
196 printf (LSTFMT2d1
, dp
);
203 CI ci
= &ct
->c_ctinfo
;
205 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
206 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
207 get_param_value(pm
, '?'));
211 * If verbose, print any RFC-822 comments in the
214 if (ci
->ci_comment
) {
217 dp
= cpytrim (ci
->ci_comment
);
218 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
220 printf (LSTFMT2d2
, buffer
);
224 if (dispo
&& ct
->c_dispo_type
) {
225 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
228 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
229 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
230 get_param_value(pm
, '?'));
243 * Print debugging information about a content
249 CI ci
= &ct
->c_ctinfo
;
253 fprintf (stderr
, " partno \"%s\"\n", empty (ct
->c_partno
));
255 /* print MIME-Version line */
257 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
259 /* print Content-Type line */
261 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
263 /* print parsed elements of content type */
264 fprintf (stderr
, " type \"%s\"\n", empty (ci
->ci_type
));
265 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
266 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
267 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
269 /* print parsed parameters attached to content type */
270 fprintf (stderr
, " parameters\n");
271 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
272 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
273 get_param_value(pm
, '?'));
275 /* print internal flags for type/subtype */
276 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
277 ct
->c_type
, ct
->c_subtype
,
278 (unsigned int)(unsigned long) ct
->c_ctparams
);
280 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
281 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
282 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
284 /* print transfer encoding information */
286 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
288 /* print internal flags for transfer encoding */
289 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
290 ct
->c_encoding
, (unsigned int)(unsigned long) &ct
->c_cefile
);
292 /* print Content-ID */
294 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
296 /* print Content-Description */
298 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
300 /* print Content-Disposition */
302 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
304 fprintf(stderr
, " disposition \"%s\"\n", empty (ct
->c_dispo_type
));
305 fprintf(stderr
, " disposition parameters\n");
306 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
307 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
308 get_param_value(pm
, '?'));
310 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
311 (unsigned int)(unsigned long) ct
->c_fp
, empty (ct
->c_file
),
312 ct
->c_begin
, ct
->c_end
);
314 /* print more information about transfer encoding */
324 * list content information for type "multipart"
328 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
331 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
334 /* list the content for toplevel of this multipart */
335 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
337 /* now list for all the subparts */
338 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
339 CT p
= part
->mp_part
;
341 if (part_ok (p
, 1) && type_ok (p
, 1))
342 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
350 * list content information for type "message/partial"
354 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
357 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
359 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
361 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
363 printf (" of %d", p
->pm_maxno
);
372 * list content information for type "message/external"
376 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
379 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
382 * First list the information for the
383 * message/external content itself.
385 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
389 printf ("\t name=\"%s\"\n", e
->eb_name
);
391 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
393 printf ("\t site=\"%s\"\n", e
->eb_site
);
395 printf ("\t server=\"%s\"\n", e
->eb_server
);
397 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
399 printf ("\t url=\"%s\"\n", e
->eb_url
);
401 /* This must be defined */
402 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
405 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
406 if (e
->eb_permission
)
407 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
409 if (e
->eb_flags
== NOTOK
)
410 printf ("\t [service unavailable]\n");
415 * Now list the information for the external content
416 * to which this content points.
418 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
425 * list content information for type "application"
426 * This no longer needs to be a separate function. It used to
427 * produce some output with verbose enabled, but that has been
428 * moved to list_content ().
432 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
435 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
442 * list information about the Content-Transfer-Encoding
447 list_encoding (CT ct
)
449 CE ce
= &ct
->c_cefile
;
451 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
452 (unsigned int)(unsigned long) ce
->ce_fp
,
453 ce
->ce_file
? ce
->ce_file
: "");