]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
461de6d74afdefa216f013fce145ba431e66e087
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_encoding (CT
);
34 * various formats for -list option
36 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
37 #define LSTFMT2a "%4d "
38 #define LSTFMT2b "%-5s %-24.24s "
39 #define LSTFMT2bv "%-5s %-24s "
40 #define LSTFMT2c1 "%5lu"
41 #define LSTFMT2c2 "%4lu%c"
42 #define LSTFMT2c3 "huge "
44 #define LSTFMT2d1 " %.36s"
45 #define LSTFMT2d1v " %s"
46 #define LSTFMT2d2 "\t %-65s\n"
50 * Top level entry point to list group of messages
54 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
60 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
62 for (ctp
= cts
; *ctp
; ctp
++) {
64 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
72 * Entry point to list a single message
76 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
78 if (type_ok (ct
, 1)) {
80 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
86 (*ct
->c_ceclosefnx
) (ct
);
92 * Primary switching routine to list information about a content
96 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
101 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
104 switch (ct
->c_subtype
) {
105 case MESSAGE_PARTIAL
:
106 return list_partial (ct
, toplevel
, realsize
, verbose
,
109 case MESSAGE_EXTERNAL
:
110 return list_external (ct
, toplevel
, realsize
, verbose
,
115 return list_content (ct
, toplevel
, realsize
, verbose
,
125 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
128 return 0; /* NOT REACHED */
133 * Method for listing information about a simple/generic content
137 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
141 char *cp
, buffer
[BUFSIZ
];
142 CI ci
= &ct
->c_ctinfo
;
146 printf (LSTFMT2a
, atoi (r1bindex (FENDNULL(ct
->c_file
), '/')));
148 printf(toplevel
< 0 ? "part " : " ");
150 snprintf (buffer
, sizeof(buffer
), "%s/%s", FENDNULL(ci
->ci_type
),
151 FENDNULL(ci
->ci_subtype
));
153 printf (LSTFMT2bv
, FENDNULL(ct
->c_partno
), buffer
);
155 printf (LSTFMT2b
, FENDNULL(ct
->c_partno
), buffer
);
157 if (ct
->c_cesizefnx
&& realsize
)
158 size
= (*ct
->c_cesizefnx
) (ct
);
160 size
= ct
->c_end
- ct
->c_begin
;
162 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
163 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
167 /* print size of this body part */
170 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
171 printf (LSTFMT2c1
, size
);
177 printf (LSTFMT2c2
, size
, *cp
);
184 /* print Content-Description */
188 dp
= cpytrim (ct
->c_descr
);
190 printf (LSTFMT2d1v
, dp
);
192 printf (LSTFMT2d1
, dp
);
199 CI ci
= &ct
->c_ctinfo
;
201 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
202 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
203 get_param_value(pm
, '?'));
207 * If verbose, print any RFC-822 comments in the
210 if (ci
->ci_comment
) {
213 dp
= cpytrim (ci
->ci_comment
);
214 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
216 printf (LSTFMT2d2
, buffer
);
220 if (dispo
&& ct
->c_dispo_type
) {
221 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
224 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
225 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
226 get_param_value(pm
, '?'));
239 * Print debugging information about a content
245 CI ci
= &ct
->c_ctinfo
;
249 fprintf (stderr
, " partno \"%s\"\n", FENDNULL(ct
->c_partno
));
251 /* print MIME-Version line */
253 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
255 /* print Content-Type line */
257 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
259 /* print parsed elements of content type */
260 fprintf (stderr
, " type \"%s\"\n", FENDNULL(ci
->ci_type
));
261 fprintf (stderr
, " subtype \"%s\"\n", FENDNULL(ci
->ci_subtype
));
262 fprintf (stderr
, " comment \"%s\"\n", FENDNULL(ci
->ci_comment
));
263 fprintf (stderr
, " magic \"%s\"\n", FENDNULL(ci
->ci_magic
));
265 /* print parsed parameters attached to content type */
266 fprintf (stderr
, " parameters\n");
267 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
268 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
269 get_param_value(pm
, '?'));
271 /* print internal flags for type/subtype */
272 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
273 ct
->c_type
, ct
->c_subtype
,
274 (unsigned int)(unsigned long) ct
->c_ctparams
);
276 fprintf (stderr
, " showproc \"%s\"\n", FENDNULL(ct
->c_showproc
));
277 fprintf (stderr
, " termproc \"%s\"\n", FENDNULL(ct
->c_termproc
));
278 fprintf (stderr
, " storeproc \"%s\"\n", FENDNULL(ct
->c_storeproc
));
280 /* print transfer encoding information */
282 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
284 /* print internal flags for transfer encoding */
285 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
286 ct
->c_encoding
, (unsigned int)(unsigned long) &ct
->c_cefile
);
288 /* print Content-ID */
290 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
292 /* print Content-Description */
294 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
296 /* print Content-Disposition */
298 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
300 fprintf(stderr
, " disposition \"%s\"\n", FENDNULL(ct
->c_dispo_type
));
301 fprintf(stderr
, " disposition parameters\n");
302 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
303 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
304 get_param_value(pm
, '?'));
306 fprintf(stderr
, " read fp %p file \"%s\" begin %ld end %ld\n",
307 (void *)ct
->c_fp
, FENDNULL(ct
->c_file
), ct
->c_begin
, ct
->c_end
);
309 /* print more information about transfer encoding */
317 * list content information for type "multipart"
321 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
324 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
327 /* list the content for toplevel of this multipart */
328 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
330 /* now list for all the subparts */
331 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
332 CT p
= part
->mp_part
;
334 if (part_ok (p
) && type_ok (p
, 1))
335 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
343 * list content information for type "message/partial"
347 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
350 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
352 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
354 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
356 printf (" of %d", p
->pm_maxno
);
365 * list content information for type "message/external"
369 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
372 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
375 * First list the information for the
376 * message/external content itself.
378 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
382 printf ("\t name=\"%s\"\n", e
->eb_name
);
384 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
386 printf ("\t site=\"%s\"\n", e
->eb_site
);
388 printf ("\t server=\"%s\"\n", e
->eb_server
);
390 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
392 printf ("\t url=\"%s\"\n", e
->eb_url
);
394 /* This must be defined */
395 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
398 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
399 if (e
->eb_permission
)
400 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
402 if (e
->eb_flags
== NOTOK
)
403 puts("\t [service unavailable]");
408 * Now list the information for the external content
409 * to which this content points.
411 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
418 * list information about the Content-Transfer-Encoding
423 list_encoding (CT ct
)
425 CE ce
= &ct
->c_cefile
;
427 fprintf(stderr
, " decoded fp %p file \"%s\"\n",
428 (void *)ce
->ce_fp
, FENDNULL(ce
->ce_file
));