]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
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 */
137 * Method for listing information about a simple/generic content
141 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
145 char *cp
, buffer
[BUFSIZ
];
146 CI ci
= &ct
->c_ctinfo
;
150 printf (LSTFMT2a
, atoi (r1bindex (FENDNULL(ct
->c_file
), '/')));
152 printf(toplevel
< 0 ? "part " : " ");
154 snprintf (buffer
, sizeof(buffer
), "%s/%s", FENDNULL(ci
->ci_type
),
155 FENDNULL(ci
->ci_subtype
));
157 printf (LSTFMT2bv
, FENDNULL(ct
->c_partno
), buffer
);
159 printf (LSTFMT2b
, FENDNULL(ct
->c_partno
), buffer
);
161 if (ct
->c_cesizefnx
&& realsize
)
162 size
= (*ct
->c_cesizefnx
) (ct
);
164 size
= ct
->c_end
- ct
->c_begin
;
166 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
167 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
171 /* print size of this body part */
174 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
175 printf (LSTFMT2c1
, size
);
181 printf (LSTFMT2c2
, size
, *cp
);
188 /* print Content-Description */
192 dp
= cpytrim (ct
->c_descr
);
194 printf (LSTFMT2d1v
, dp
);
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", FENDNULL(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", FENDNULL(ci
->ci_type
));
265 fprintf (stderr
, " subtype \"%s\"\n", FENDNULL(ci
->ci_subtype
));
266 fprintf (stderr
, " comment \"%s\"\n", FENDNULL(ci
->ci_comment
));
267 fprintf (stderr
, " magic \"%s\"\n", FENDNULL(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", FENDNULL(ct
->c_showproc
));
281 fprintf (stderr
, " termproc \"%s\"\n", FENDNULL(ct
->c_termproc
));
282 fprintf (stderr
, " storeproc \"%s\"\n", FENDNULL(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", FENDNULL(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
, FENDNULL(ct
->c_file
),
312 ct
->c_begin
, ct
->c_end
);
314 /* print more information about transfer encoding */
322 * list content information for type "multipart"
326 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
329 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
332 /* list the content for toplevel of this multipart */
333 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
335 /* now list for all the subparts */
336 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
337 CT p
= part
->mp_part
;
339 if (part_ok (p
) && type_ok (p
, 1))
340 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
348 * list content information for type "message/partial"
352 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
355 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
357 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
359 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
361 printf (" of %d", p
->pm_maxno
);
370 * list content information for type "message/external"
374 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
377 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
380 * First list the information for the
381 * message/external content itself.
383 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
387 printf ("\t name=\"%s\"\n", e
->eb_name
);
389 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
391 printf ("\t site=\"%s\"\n", e
->eb_site
);
393 printf ("\t server=\"%s\"\n", e
->eb_server
);
395 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
397 printf ("\t url=\"%s\"\n", e
->eb_url
);
399 /* This must be defined */
400 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
403 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
404 if (e
->eb_permission
)
405 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
407 if (e
->eb_flags
== NOTOK
)
408 puts("\t [service unavailable]");
413 * Now list the information for the external content
414 * to which this content points.
416 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
423 * list content information for type "application"
424 * This no longer needs to be a separate function. It used to
425 * produce some output with verbose enabled, but that has been
426 * moved to list_content ().
430 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
433 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
440 * list information about the Content-Transfer-Encoding
445 list_encoding (CT ct
)
447 CE ce
= &ct
->c_cefile
;
449 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
450 (unsigned int)(unsigned long) ce
->ce_fp
,
451 FENDNULL(ce
->ce_file
));