]>
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>
21 static void list_single_message (CT
, int, int, int, int);
22 static int list_debug (CT
);
23 static int list_multi (CT
, int, int, int, int, int);
24 static int list_partial (CT
, int, int, int, int, int);
25 static int list_external (CT
, int, int, int, int, int);
26 static int list_encoding (CT
);
30 * various formats for -list option
32 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
33 #define LSTFMT2a "%4d "
34 #define LSTFMT2b "%-5s %-24.24s "
35 #define LSTFMT2bv "%-5s %-24s "
36 #define LSTFMT2c1 "%5lu"
37 #define LSTFMT2c2 "%4lu%c"
38 #define LSTFMT2c3 "huge "
40 #define LSTFMT2d1 " %.36s"
41 #define LSTFMT2d1v " %s"
42 #define LSTFMT2d2 "\t %-65s\n"
46 * Top level entry point to list group of messages
50 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
56 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
58 for (ctp
= cts
; *ctp
; ctp
++) {
60 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
68 * Entry point to list a single message
72 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
74 if (type_ok (ct
, 1)) {
76 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
82 (*ct
->c_ceclosefnx
) (ct
);
88 * Primary switching routine to list information about a content
92 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
97 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
100 switch (ct
->c_subtype
) {
101 case MESSAGE_PARTIAL
:
102 return list_partial (ct
, toplevel
, realsize
, verbose
,
105 case MESSAGE_EXTERNAL
:
106 return list_external (ct
, toplevel
, realsize
, verbose
,
111 return list_content (ct
, toplevel
, realsize
, verbose
,
121 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
124 return 0; /* NOT REACHED */
129 * Method for listing information about a simple/generic content
133 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
137 char *cp
, buffer
[BUFSIZ
];
138 CI ci
= &ct
->c_ctinfo
;
142 printf (LSTFMT2a
, atoi (r1bindex (FENDNULL(ct
->c_file
), '/')));
144 printf(toplevel
< 0 ? "part " : " ");
146 snprintf (buffer
, sizeof(buffer
), "%s/%s", FENDNULL(ci
->ci_type
),
147 FENDNULL(ci
->ci_subtype
));
149 printf (LSTFMT2bv
, FENDNULL(ct
->c_partno
), buffer
);
151 printf (LSTFMT2b
, FENDNULL(ct
->c_partno
), buffer
);
153 if (ct
->c_cesizefnx
&& realsize
)
154 size
= (*ct
->c_cesizefnx
) (ct
);
156 size
= ct
->c_end
- ct
->c_begin
;
158 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
159 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
163 /* print size of this body part */
166 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
167 printf (LSTFMT2c1
, size
);
173 printf (LSTFMT2c2
, size
, *cp
);
180 /* print Content-Description */
184 dp
= cpytrim (ct
->c_descr
);
186 printf (LSTFMT2d1v
, dp
);
188 printf (LSTFMT2d1
, dp
);
195 CI ci
= &ct
->c_ctinfo
;
197 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
198 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
199 get_param_value(pm
, '?'));
203 * If verbose, print any RFC-822 comments in the
206 if (ci
->ci_comment
) {
209 dp
= cpytrim (ci
->ci_comment
);
210 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
212 printf (LSTFMT2d2
, buffer
);
216 if (dispo
&& ct
->c_dispo_type
) {
217 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
220 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
221 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
222 get_param_value(pm
, '?'));
235 * Print debugging information about a content
241 CI ci
= &ct
->c_ctinfo
;
245 fprintf (stderr
, " partno \"%s\"\n", FENDNULL(ct
->c_partno
));
247 /* print MIME-Version line */
249 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
251 /* print Content-Type line */
253 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
255 /* print parsed elements of content type */
256 fprintf (stderr
, " type \"%s\"\n", FENDNULL(ci
->ci_type
));
257 fprintf (stderr
, " subtype \"%s\"\n", FENDNULL(ci
->ci_subtype
));
258 fprintf (stderr
, " comment \"%s\"\n", FENDNULL(ci
->ci_comment
));
259 fprintf (stderr
, " magic \"%s\"\n", FENDNULL(ci
->ci_magic
));
261 /* print parsed parameters attached to content type */
262 fprintf (stderr
, " parameters\n");
263 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
264 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
265 get_param_value(pm
, '?'));
267 /* print internal flags for type/subtype */
268 fprintf(stderr
, " type %#x subtype %#x params %p\n",
269 ct
->c_type
, ct
->c_subtype
, (void *)ct
->c_ctparams
);
271 fprintf (stderr
, " showproc \"%s\"\n", FENDNULL(ct
->c_showproc
));
272 fprintf (stderr
, " termproc \"%s\"\n", FENDNULL(ct
->c_termproc
));
273 fprintf (stderr
, " storeproc \"%s\"\n", FENDNULL(ct
->c_storeproc
));
275 /* print transfer encoding information */
277 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
279 /* print internal flags for transfer encoding */
280 fprintf(stderr
, " transfer encoding %#x params %p\n",
281 ct
->c_encoding
, (void *)&ct
->c_cefile
);
283 /* print Content-ID */
285 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
287 /* print Content-Description */
289 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
291 /* print Content-Disposition */
293 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
295 fprintf(stderr
, " disposition \"%s\"\n", FENDNULL(ct
->c_dispo_type
));
296 fprintf(stderr
, " disposition parameters\n");
297 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
298 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
299 get_param_value(pm
, '?'));
301 fprintf(stderr
, " read fp %p file \"%s\" begin %ld end %ld\n",
302 (void *)ct
->c_fp
, FENDNULL(ct
->c_file
), ct
->c_begin
, ct
->c_end
);
304 /* print more information about transfer encoding */
312 * list content information for type "multipart"
316 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
319 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
322 /* list the content for toplevel of this multipart */
323 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
325 /* now list for all the subparts */
326 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
327 CT p
= part
->mp_part
;
329 if (part_ok (p
) && type_ok (p
, 1))
330 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
338 * list content information for type "message/partial"
342 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
345 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
347 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
349 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
351 printf (" of %d", p
->pm_maxno
);
360 * list content information for type "message/external"
364 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
367 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
370 * First list the information for the
371 * message/external content itself.
373 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
377 puts("\t [missing access-type]"); /* Must be defined. */
378 if (e
->eb_flags
== NOTOK
)
379 puts("\t [service unavailable]");
383 * Now list the information for the external content
384 * to which this content points.
386 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
393 * list information about the Content-Transfer-Encoding
398 list_encoding (CT ct
)
400 CE ce
= &ct
->c_cefile
;
402 fprintf(stderr
, " decoded fp %p file \"%s\"\n",
403 (void *)ce
->ce_fp
, FENDNULL(ce
->ce_file
));