]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
8923b61764f7ec53bcb287eef8931ef1baa28b07
2 * mhlistsbr.c -- routines to list information about the
3 * -- contents of MIME messages
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
15 #include <h/mhparse.h>
20 int type_ok (CT
, int);
21 void flush_errors (void);
26 static void list_single_message (CT
, int, int, int, int);
27 static int list_debug (CT
);
28 static int list_multi (CT
, int, int, int, int, int);
29 static int list_partial (CT
, int, int, int, int, int);
30 static int list_external (CT
, int, int, int, int, int);
31 static int list_application (CT
, int, int, int, int, int);
32 static int list_encoding (CT
);
36 * various formats for -list option
38 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
39 #define LSTFMT2a "%4d "
40 #define LSTFMT2b "%-5s %-24.24s "
41 #define LSTFMT2bv "%-5s %-24s "
42 #define LSTFMT2c1 "%5lu"
43 #define LSTFMT2c2 "%4lu%c"
44 #define LSTFMT2c3 "huge "
46 #define LSTFMT2d1 " %.36s"
47 #define LSTFMT2d1v " %s"
48 #define LSTFMT2d2 "\t %-65s\n"
52 * Top level entry point to list group of messages
56 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
62 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
64 for (ctp
= cts
; *ctp
; ctp
++) {
66 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
74 * Entry point to list a single message
78 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
80 if (type_ok (ct
, 1)) {
82 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
88 (*ct
->c_ceclosefnx
) (ct
);
94 * Primary switching routine to list information about a content
98 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
101 switch (ct
->c_type
) {
103 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
106 switch (ct
->c_subtype
) {
107 case MESSAGE_PARTIAL
:
108 return list_partial (ct
, toplevel
, realsize
, verbose
,
111 case MESSAGE_EXTERNAL
:
112 return list_external (ct
, toplevel
, realsize
, verbose
,
117 return list_content (ct
, toplevel
, realsize
, verbose
,
125 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
129 return list_application (ct
, toplevel
, realsize
, verbose
, debug
,
133 return 0; /* NOT REACHED */
137 #define empty(s) ((s) ? (s) : "")
140 * Method for listing information about a simple/generic content
144 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
148 char *cp
, buffer
[BUFSIZ
];
149 CI ci
= &ct
->c_ctinfo
;
153 printf (LSTFMT2a
, atoi (r1bindex (empty (ct
->c_file
), '/')));
155 printf(toplevel
< 0 ? "part " : " ");
157 snprintf (buffer
, sizeof(buffer
), "%s/%s", empty (ci
->ci_type
),
158 empty (ci
->ci_subtype
));
160 printf (LSTFMT2bv
, empty (ct
->c_partno
), buffer
);
162 printf (LSTFMT2b
, empty (ct
->c_partno
), buffer
);
164 if (ct
->c_cesizefnx
&& realsize
)
165 size
= (*ct
->c_cesizefnx
) (ct
);
167 size
= ct
->c_end
- ct
->c_begin
;
169 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
170 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
174 /* print size of this body part */
177 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
178 printf (LSTFMT2c1
, size
);
184 printf (LSTFMT2c2
, size
, *cp
);
191 /* print Content-Description */
195 dp
= cpytrim (ct
->c_descr
);
197 printf (LSTFMT2d1v
, dp
);
199 printf (LSTFMT2d1
, dp
);
206 CI ci
= &ct
->c_ctinfo
;
208 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
209 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
210 get_param_value(pm
, '?'));
214 * If verbose, print any RFC-822 comments in the
217 if (ci
->ci_comment
) {
220 dp
= cpytrim (ci
->ci_comment
);
221 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
223 printf (LSTFMT2d2
, buffer
);
227 if (dispo
&& ct
->c_dispo_type
) {
228 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
231 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
232 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
233 get_param_value(pm
, '?'));
246 * Print debugging information about a content
252 CI ci
= &ct
->c_ctinfo
;
256 fprintf (stderr
, " partno \"%s\"\n", empty (ct
->c_partno
));
258 /* print MIME-Version line */
260 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
262 /* print Content-Type line */
264 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
266 /* print parsed elements of content type */
267 fprintf (stderr
, " type \"%s\"\n", empty (ci
->ci_type
));
268 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
269 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
270 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
272 /* print parsed parameters attached to content type */
273 fprintf (stderr
, " parameters\n");
274 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
275 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
276 get_param_value(pm
, '?'));
278 /* print internal flags for type/subtype */
279 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
280 ct
->c_type
, ct
->c_subtype
,
281 (unsigned int)(unsigned long) ct
->c_ctparams
);
283 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
284 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
285 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
287 /* print transfer encoding information */
289 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
291 /* print internal flags for transfer encoding */
292 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
293 ct
->c_encoding
, (unsigned int)(unsigned long) &ct
->c_cefile
);
295 /* print Content-ID */
297 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
299 /* print Content-Description */
301 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
303 /* print Content-Disposition */
305 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
307 fprintf(stderr
, " disposition \"%s\"\n", empty (ct
->c_dispo_type
));
308 fprintf(stderr
, " disposition parameters\n");
309 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
310 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
311 get_param_value(pm
, '?'));
313 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
314 (unsigned int)(unsigned long) ct
->c_fp
, empty (ct
->c_file
),
315 ct
->c_begin
, ct
->c_end
);
317 /* print more information about transfer encoding */
327 * list content information for type "multipart"
331 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
334 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
337 /* list the content for toplevel of this multipart */
338 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
340 /* now list for all the subparts */
341 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
342 CT p
= part
->mp_part
;
344 if (part_ok (p
) && type_ok (p
, 1))
345 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
353 * list content information for type "message/partial"
357 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
360 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
362 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
364 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
366 printf (" of %d", p
->pm_maxno
);
375 * list content information for type "message/external"
379 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
382 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
385 * First list the information for the
386 * message/external content itself.
388 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
392 printf ("\t name=\"%s\"\n", e
->eb_name
);
394 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
396 printf ("\t site=\"%s\"\n", e
->eb_site
);
398 printf ("\t server=\"%s\"\n", e
->eb_server
);
400 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
402 printf ("\t url=\"%s\"\n", e
->eb_url
);
404 /* This must be defined */
405 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
408 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
409 if (e
->eb_permission
)
410 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
412 if (e
->eb_flags
== NOTOK
)
413 puts("\t [service unavailable]");
418 * Now list the information for the external content
419 * to which this content points.
421 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
428 * list content information for type "application"
429 * This no longer needs to be a separate function. It used to
430 * produce some output with verbose enabled, but that has been
431 * moved to list_content ().
435 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
438 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
445 * list information about the Content-Transfer-Encoding
450 list_encoding (CT ct
)
452 CE ce
= &ct
->c_cefile
;
454 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
455 (unsigned int)(unsigned long) ce
->ce_fp
,
456 ce
->ce_file
? ce
->ce_file
: "");