]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
6b4852fce523c657951f53e1976e1e755218e4fc
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_external (CT
, int, int, int, int, int);
27 static int list_encoding (CT
);
31 * various formats for -list option
33 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
34 #define LSTFMT2a "%4d "
35 #define LSTFMT2b "%-5s %-24.24s "
36 #define LSTFMT2bv "%-5s %-24s "
37 #define LSTFMT2c1 "%5lu"
38 #define LSTFMT2c2 "%4lu%c"
39 #define LSTFMT2c3 "huge "
41 #define LSTFMT2d1 " %.36s"
42 #define LSTFMT2d1v " %s"
43 #define LSTFMT2d2 "\t %-65s\n"
47 * Top level entry point to list group of messages
51 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
57 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
59 for (ctp
= cts
; *ctp
; ctp
++) {
61 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
69 * Entry point to list a single message
73 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
75 if (type_ok (ct
, 1)) {
77 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
83 (*ct
->c_ceclosefnx
) (ct
);
89 * Primary switching routine to list information about a content
93 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
98 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
101 switch (ct
->c_subtype
) {
102 case MESSAGE_EXTERNAL
:
103 return list_external (ct
, toplevel
, realsize
, verbose
,
108 return list_content (ct
, toplevel
, realsize
, verbose
,
118 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
121 return 0; /* NOT REACHED */
126 * Method for listing information about a simple/generic content
130 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
134 char *cp
, buffer
[BUFSIZ
];
135 CI ci
= &ct
->c_ctinfo
;
139 printf (LSTFMT2a
, atoi (r1bindex (FENDNULL(ct
->c_file
), '/')));
141 printf(toplevel
< 0 ? "part " : " ");
143 snprintf (buffer
, sizeof(buffer
), "%s/%s", FENDNULL(ci
->ci_type
),
144 FENDNULL(ci
->ci_subtype
));
146 printf (LSTFMT2bv
, FENDNULL(ct
->c_partno
), buffer
);
148 printf (LSTFMT2b
, FENDNULL(ct
->c_partno
), buffer
);
150 if (ct
->c_cesizefnx
&& realsize
)
151 size
= (*ct
->c_cesizefnx
) (ct
);
153 size
= ct
->c_end
- ct
->c_begin
;
155 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
156 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
160 /* print size of this body part */
163 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
164 printf (LSTFMT2c1
, size
);
170 printf (LSTFMT2c2
, size
, *cp
);
177 /* print Content-Description */
181 dp
= cpytrim (ct
->c_descr
);
183 printf (LSTFMT2d1v
, dp
);
185 printf (LSTFMT2d1
, dp
);
192 CI ci
= &ct
->c_ctinfo
;
194 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
195 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
196 get_param_value(pm
, '?'));
200 * If verbose, print any RFC-822 comments in the
203 if (ci
->ci_comment
) {
206 dp
= cpytrim (ci
->ci_comment
);
207 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
209 printf (LSTFMT2d2
, buffer
);
213 if (dispo
&& ct
->c_dispo_type
) {
214 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
217 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
218 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
219 get_param_value(pm
, '?'));
232 * Print debugging information about a content
238 CI ci
= &ct
->c_ctinfo
;
242 fprintf (stderr
, " partno \"%s\"\n", FENDNULL(ct
->c_partno
));
244 /* print MIME-Version line */
246 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
248 /* print Content-Type line */
250 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
252 /* print parsed elements of content type */
253 fprintf (stderr
, " type \"%s\"\n", FENDNULL(ci
->ci_type
));
254 fprintf (stderr
, " subtype \"%s\"\n", FENDNULL(ci
->ci_subtype
));
255 fprintf (stderr
, " comment \"%s\"\n", FENDNULL(ci
->ci_comment
));
256 fprintf (stderr
, " magic \"%s\"\n", FENDNULL(ci
->ci_magic
));
258 /* print parsed parameters attached to content type */
259 fprintf (stderr
, " parameters\n");
260 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
261 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
262 get_param_value(pm
, '?'));
264 /* print internal flags for type/subtype */
265 fprintf(stderr
, " type %#x subtype %#x params %p\n",
266 ct
->c_type
, ct
->c_subtype
, (void *)ct
->c_ctparams
);
268 fprintf (stderr
, " showproc \"%s\"\n", FENDNULL(ct
->c_showproc
));
269 fprintf (stderr
, " termproc \"%s\"\n", FENDNULL(ct
->c_termproc
));
270 fprintf (stderr
, " storeproc \"%s\"\n", FENDNULL(ct
->c_storeproc
));
272 /* print transfer encoding information */
274 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
276 /* print internal flags for transfer encoding */
277 fprintf(stderr
, " transfer encoding %#x params %p\n",
278 ct
->c_encoding
, (void *)&ct
->c_cefile
);
280 /* print Content-ID */
282 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
284 /* print Content-Description */
286 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
288 /* print Content-Disposition */
290 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
292 fprintf(stderr
, " disposition \"%s\"\n", FENDNULL(ct
->c_dispo_type
));
293 fprintf(stderr
, " disposition parameters\n");
294 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
295 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
296 get_param_value(pm
, '?'));
298 fprintf(stderr
, " read fp %p file \"%s\" begin %ld end %ld\n",
299 (void *)ct
->c_fp
, FENDNULL(ct
->c_file
), ct
->c_begin
, ct
->c_end
);
301 /* print more information about transfer encoding */
309 * list content information for type "multipart"
313 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
316 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
319 /* list the content for toplevel of this multipart */
320 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
322 /* now list for all the subparts */
323 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
324 CT p
= part
->mp_part
;
326 if (part_ok (p
) && type_ok (p
, 1))
327 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
335 * list content information for type "message/external"
339 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
342 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
345 * First list the information for the
346 * message/external content itself.
348 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
352 puts("\t [missing access-type]"); /* Must be defined. */
353 if (e
->eb_flags
== NOTOK
)
354 puts("\t [service unavailable]");
358 * Now list the information for the external content
359 * to which this content points.
361 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
368 * list information about the Content-Transfer-Encoding
373 list_encoding (CT ct
)
375 CE ce
= &ct
->c_cefile
;
377 fprintf(stderr
, " decoded fp %p file \"%s\"\n",
378 (void *)ce
->ce_fp
, FENDNULL(ce
->ce_file
));