]>
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.
10 #include "sbr/r1bindex.h"
11 #include "sbr/trimcpy.h"
16 #include "h/mhparse.h"
23 static void list_single_message (CT
, int, int, int, int);
24 static int list_debug (CT
);
25 static int list_multi (CT
, int, int, int, int, int);
26 static int list_partial (CT
, int, int, int, int, int);
27 static int list_external (CT
, int, int, int, int, int);
28 static int list_encoding (CT
);
32 * various formats for -list option
34 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
35 #define LSTFMT2a "%4d "
36 #define LSTFMT2b "%-5s %-24.24s "
37 #define LSTFMT2bv "%-5s %-24s "
38 #define LSTFMT2c1 "%5lu"
39 #define LSTFMT2c2 "%4lu%c"
40 #define LSTFMT2c3 "huge "
42 #define LSTFMT2d1 " %.36s"
43 #define LSTFMT2d1v " %s"
44 #define LSTFMT2d2 "\t %-65s\n"
48 * Top level entry point to list group of messages
52 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
58 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
60 for (ctp
= cts
; *ctp
; ctp
++) {
62 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
70 * Entry point to list a single message
74 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
76 if (type_ok (ct
, 1)) {
78 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
84 (*ct
->c_ceclosefnx
) (ct
);
90 * Primary switching routine to list information about a content
94 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
99 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
102 switch (ct
->c_subtype
) {
103 case MESSAGE_PARTIAL
:
104 return list_partial (ct
, toplevel
, realsize
, verbose
,
107 case MESSAGE_EXTERNAL
:
108 return list_external (ct
, toplevel
, realsize
, verbose
,
113 return list_content (ct
, toplevel
, realsize
, verbose
,
123 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
126 return 0; /* NOT REACHED */
131 * Method for listing information about a simple/generic content
135 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
139 char *cp
, buffer
[BUFSIZ
];
140 CI ci
= &ct
->c_ctinfo
;
144 printf (LSTFMT2a
, atoi (r1bindex (FENDNULL(ct
->c_file
), '/')));
146 printf(toplevel
< 0 ? "part " : " ");
148 snprintf (buffer
, sizeof(buffer
), "%s/%s", FENDNULL(ci
->ci_type
),
149 FENDNULL(ci
->ci_subtype
));
151 printf (LSTFMT2bv
, FENDNULL(ct
->c_partno
), buffer
);
153 printf (LSTFMT2b
, FENDNULL(ct
->c_partno
), buffer
);
155 if (ct
->c_cesizefnx
&& realsize
)
156 size
= (*ct
->c_cesizefnx
) (ct
);
158 size
= ct
->c_end
- ct
->c_begin
;
160 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
161 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
165 /* print size of this body part */
168 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
169 printf (LSTFMT2c1
, size
);
175 printf (LSTFMT2c2
, size
, *cp
);
182 /* print Content-Description */
186 dp
= cpytrim (ct
->c_descr
);
188 printf (LSTFMT2d1v
, dp
);
190 printf (LSTFMT2d1
, dp
);
197 CI ci
= &ct
->c_ctinfo
;
199 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
200 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
201 get_param_value(pm
, '?'));
205 * If verbose, print any RFC-822 comments in the
208 if (ci
->ci_comment
) {
211 dp
= cpytrim (ci
->ci_comment
);
212 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
214 printf (LSTFMT2d2
, buffer
);
218 if (dispo
&& ct
->c_dispo_type
) {
219 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
222 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
223 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
224 get_param_value(pm
, '?'));
237 * Print debugging information about a content
243 CI ci
= &ct
->c_ctinfo
;
247 fprintf (stderr
, " partno \"%s\"\n", FENDNULL(ct
->c_partno
));
249 /* print MIME-Version line */
251 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
253 /* print Content-Type line */
255 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
257 /* print parsed elements of content type */
258 fprintf (stderr
, " type \"%s\"\n", FENDNULL(ci
->ci_type
));
259 fprintf (stderr
, " subtype \"%s\"\n", FENDNULL(ci
->ci_subtype
));
260 fprintf (stderr
, " comment \"%s\"\n", FENDNULL(ci
->ci_comment
));
261 fprintf (stderr
, " magic \"%s\"\n", FENDNULL(ci
->ci_magic
));
263 /* print parsed parameters attached to content type */
264 fprintf (stderr
, " parameters\n");
265 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
266 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
267 get_param_value(pm
, '?'));
269 /* print internal flags for type/subtype */
270 fprintf(stderr
, " type %#x subtype %#x params %p\n",
271 ct
->c_type
, ct
->c_subtype
, (void *)ct
->c_ctparams
);
273 fprintf (stderr
, " showproc \"%s\"\n", FENDNULL(ct
->c_showproc
));
274 fprintf (stderr
, " termproc \"%s\"\n", FENDNULL(ct
->c_termproc
));
275 fprintf (stderr
, " storeproc \"%s\"\n", FENDNULL(ct
->c_storeproc
));
277 /* print transfer encoding information */
279 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
281 /* print internal flags for transfer encoding */
282 fprintf(stderr
, " transfer encoding %#x params %p\n",
283 ct
->c_encoding
, (void *)&ct
->c_cefile
);
285 /* print Content-ID */
287 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
289 /* print Content-Description */
291 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
293 /* print Content-Disposition */
295 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
297 fprintf(stderr
, " disposition \"%s\"\n", FENDNULL(ct
->c_dispo_type
));
298 fprintf(stderr
, " disposition parameters\n");
299 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
300 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
301 get_param_value(pm
, '?'));
303 fprintf(stderr
, " read fp %p file \"%s\" begin %ld end %ld\n",
304 (void *)ct
->c_fp
, FENDNULL(ct
->c_file
), ct
->c_begin
, ct
->c_end
);
306 /* print more information about transfer encoding */
314 * list content information for type "multipart"
318 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
321 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
324 /* list the content for toplevel of this multipart */
325 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
327 /* now list for all the subparts */
328 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
329 CT p
= part
->mp_part
;
331 if (part_ok (p
) && type_ok (p
, 1))
332 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
340 * list content information for type "message/partial"
344 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
347 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
349 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
351 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
353 printf (" of %d", p
->pm_maxno
);
362 * list content information for type "message/external"
366 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
369 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
372 * First list the information for the
373 * message/external content itself.
375 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
379 puts("\t [missing access-type]"); /* Must be defined. */
380 if (e
->eb_flags
== NOTOK
)
381 puts("\t [service unavailable]");
385 * Now list the information for the external content
386 * to which this content points.
388 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
395 * list information about the Content-Transfer-Encoding
400 list_encoding (CT ct
)
402 CE ce
= &ct
->c_cefile
;
404 fprintf(stderr
, " decoded fp %p file \"%s\"\n",
405 (void *)ce
->ce_fp
, FENDNULL(ce
->ce_file
));