]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
452c7fd4022ff09b95ed719423786b6357a61634
1 /* mhlistsbr.c -- routines to list information about the
2 * -- contents of MIME messages
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
14 #include <h/mhparse.h>
19 int type_ok (CT
, int);
20 void flush_errors (void);
25 static void list_single_message (CT
, int, int, int, int);
26 static int list_debug (CT
);
27 static int list_multi (CT
, int, int, int, int, int);
28 static int list_partial (CT
, int, int, int, int, int);
29 static int list_external (CT
, int, int, int, int, int);
30 static int list_application (CT
, int, int, int, int, int);
31 static int list_encoding (CT
);
35 * various formats for -list option
37 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
38 #define LSTFMT2a "%4d "
39 #define LSTFMT2b "%-5s %-24.24s "
40 #define LSTFMT2bv "%-5s %-24s "
41 #define LSTFMT2c1 "%5lu"
42 #define LSTFMT2c2 "%4lu%c"
43 #define LSTFMT2c3 "huge "
45 #define LSTFMT2d1 " %.36s"
46 #define LSTFMT2d1v " %s"
47 #define LSTFMT2d2 "\t %-65s\n"
51 * Top level entry point to list group of messages
55 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
61 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
63 for (ctp
= cts
; *ctp
; ctp
++) {
65 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
73 * Entry point to list a single message
77 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
79 if (type_ok (ct
, 1)) {
81 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
87 (*ct
->c_ceclosefnx
) (ct
);
93 * Primary switching routine to list information about a content
97 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
100 switch (ct
->c_type
) {
102 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
105 switch (ct
->c_subtype
) {
106 case MESSAGE_PARTIAL
:
107 return list_partial (ct
, toplevel
, realsize
, verbose
,
110 case MESSAGE_EXTERNAL
:
111 return list_external (ct
, toplevel
, realsize
, verbose
,
116 return list_content (ct
, toplevel
, realsize
, verbose
,
124 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
128 return list_application (ct
, toplevel
, realsize
, verbose
, debug
,
132 return 0; /* NOT REACHED */
136 #define empty(s) ((s) ? (s) : "")
139 * Method for listing information about a simple/generic content
143 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
147 char *cp
, buffer
[BUFSIZ
];
148 CI ci
= &ct
->c_ctinfo
;
152 printf (LSTFMT2a
, atoi (r1bindex (empty (ct
->c_file
), '/')));
154 printf(toplevel
< 0 ? "part " : " ");
156 snprintf (buffer
, sizeof(buffer
), "%s/%s", empty (ci
->ci_type
),
157 empty (ci
->ci_subtype
));
159 printf (LSTFMT2bv
, empty (ct
->c_partno
), buffer
);
161 printf (LSTFMT2b
, empty (ct
->c_partno
), buffer
);
163 if (ct
->c_cesizefnx
&& realsize
)
164 size
= (*ct
->c_cesizefnx
) (ct
);
166 size
= ct
->c_end
- ct
->c_begin
;
168 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
169 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
173 /* print size of this body part */
176 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
177 printf (LSTFMT2c1
, size
);
183 printf (LSTFMT2c2
, size
, *cp
);
190 /* print Content-Description */
194 dp
= cpytrim (ct
->c_descr
);
196 printf (LSTFMT2d1v
, dp
);
198 printf (LSTFMT2d1
, dp
);
205 CI ci
= &ct
->c_ctinfo
;
207 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
208 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
209 get_param_value(pm
, '?'));
213 * If verbose, print any RFC-822 comments in the
216 if (ci
->ci_comment
) {
219 dp
= cpytrim (ci
->ci_comment
);
220 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
222 printf (LSTFMT2d2
, buffer
);
226 if (dispo
&& ct
->c_dispo_type
) {
227 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
230 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
231 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
232 get_param_value(pm
, '?'));
245 * Print debugging information about a content
251 CI ci
= &ct
->c_ctinfo
;
255 fprintf (stderr
, " partno \"%s\"\n", empty (ct
->c_partno
));
257 /* print MIME-Version line */
259 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
261 /* print Content-Type line */
263 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
265 /* print parsed elements of content type */
266 fprintf (stderr
, " type \"%s\"\n", empty (ci
->ci_type
));
267 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
268 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
269 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
271 /* print parsed parameters attached to content type */
272 fprintf (stderr
, " parameters\n");
273 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
274 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
275 get_param_value(pm
, '?'));
277 /* print internal flags for type/subtype */
278 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
279 ct
->c_type
, ct
->c_subtype
,
280 (unsigned int)(unsigned long) ct
->c_ctparams
);
282 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
283 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
284 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
286 /* print transfer encoding information */
288 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
290 /* print internal flags for transfer encoding */
291 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
292 ct
->c_encoding
, (unsigned int)(unsigned long) &ct
->c_cefile
);
294 /* print Content-ID */
296 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
298 /* print Content-Description */
300 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
302 /* print Content-Disposition */
304 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
306 fprintf(stderr
, " disposition \"%s\"\n", empty (ct
->c_dispo_type
));
307 fprintf(stderr
, " disposition parameters\n");
308 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
309 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
310 get_param_value(pm
, '?'));
312 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
313 (unsigned int)(unsigned long) ct
->c_fp
, empty (ct
->c_file
),
314 ct
->c_begin
, ct
->c_end
);
316 /* print more information about transfer encoding */
326 * list content information for type "multipart"
330 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
333 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
336 /* list the content for toplevel of this multipart */
337 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
339 /* now list for all the subparts */
340 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
341 CT p
= part
->mp_part
;
343 if (part_ok (p
) && type_ok (p
, 1))
344 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
352 * list content information for type "message/partial"
356 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
359 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
361 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
363 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
365 printf (" of %d", p
->pm_maxno
);
374 * list content information for type "message/external"
378 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
381 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
384 * First list the information for the
385 * message/external content itself.
387 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
391 printf ("\t name=\"%s\"\n", e
->eb_name
);
393 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
395 printf ("\t site=\"%s\"\n", e
->eb_site
);
397 printf ("\t server=\"%s\"\n", e
->eb_server
);
399 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
401 printf ("\t url=\"%s\"\n", e
->eb_url
);
403 /* This must be defined */
404 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
407 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
408 if (e
->eb_permission
)
409 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
411 if (e
->eb_flags
== NOTOK
)
412 puts("\t [service unavailable]");
417 * Now list the information for the external content
418 * to which this content points.
420 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
427 * list content information for type "application"
428 * This no longer needs to be a separate function. It used to
429 * produce some output with verbose enabled, but that has been
430 * moved to list_content ().
434 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
437 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
444 * list information about the Content-Transfer-Encoding
449 list_encoding (CT ct
)
451 CE ce
= &ct
->c_cefile
;
453 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
454 (unsigned int)(unsigned long) ce
->ce_fp
,
455 ce
->ce_file
? ce
->ce_file
: "");