]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
3 * mhlistsbr.c -- routines to list information about the
4 * -- contents of MIME messages
6 * This code is Copyright (c) 2002, by the authors of nmh. See the
7 * COPYRIGHT file in the root directory of the nmh distribution for
8 * complete copyright information.
13 #include <h/signals.h>
17 #include <h/mhparse.h>
22 int type_ok (CT
, int);
23 void flush_errors (void);
28 static void list_single_message (CT
, int, int, int, int);
29 static int list_debug (CT
);
30 static int list_multi (CT
, int, int, int, int, int);
31 static int list_partial (CT
, int, int, int, int, int);
32 static int list_external (CT
, int, int, int, int, int);
33 static int list_application (CT
, int, int, int, int, int);
34 static int list_encoding (CT
);
38 * various formats for -list option
40 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
41 #define LSTFMT2a "%4d "
42 #define LSTFMT2b "%-5s %-24.24s "
43 #define LSTFMT2bv "%-5s %-24s "
44 #define LSTFMT2c1 "%5lu"
45 #define LSTFMT2c2 "%4lu%c"
46 #define LSTFMT2c3 "huge "
48 #define LSTFMT2d1 " %.36s"
49 #define LSTFMT2d1v " %s"
50 #define LSTFMT2d2 "\t %-65s\n"
54 * Top level entry point to list group of messages
58 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
,
64 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
66 for (ctp
= cts
; *ctp
; ctp
++) {
68 list_single_message (ct
, realsize
, verbose
, debug
, dispo
);
76 * Entry point to list a single message
80 list_single_message (CT ct
, int realsize
, int verbose
, int debug
, int dispo
)
82 if (type_ok (ct
, 1)) {
84 list_switch (ct
, 1, realsize
, verbose
, debug
, dispo
);
90 (*ct
->c_ceclosefnx
) (ct
);
96 * Primary switching routine to list information about a content
100 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
103 switch (ct
->c_type
) {
105 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
108 switch (ct
->c_subtype
) {
109 case MESSAGE_PARTIAL
:
110 return list_partial (ct
, toplevel
, realsize
, verbose
,
113 case MESSAGE_EXTERNAL
:
114 return list_external (ct
, toplevel
, realsize
, verbose
,
119 return list_content (ct
, toplevel
, realsize
, verbose
,
127 return list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
131 return list_application (ct
, toplevel
, realsize
, verbose
, debug
,
135 return 0; /* NOT REACHED */
139 #define empty(s) ((s) ? (s) : "")
142 * Method for listing information about a simple/generic content
146 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
150 char *cp
, buffer
[BUFSIZ
];
151 CI ci
= &ct
->c_ctinfo
;
155 printf (LSTFMT2a
, atoi (r1bindex (empty (ct
->c_file
), '/')));
157 printf(toplevel
< 0 ? "part " : " ");
159 snprintf (buffer
, sizeof(buffer
), "%s/%s", empty (ci
->ci_type
),
160 empty (ci
->ci_subtype
));
162 printf (LSTFMT2bv
, empty (ct
->c_partno
), buffer
);
164 printf (LSTFMT2b
, empty (ct
->c_partno
), buffer
);
166 if (ct
->c_cesizefnx
&& realsize
)
167 size
= (*ct
->c_cesizefnx
) (ct
);
169 size
= ct
->c_end
- ct
->c_begin
;
171 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
172 for (cp
= " KMGT"; size
> 9999; size
/= 1000)
176 /* print size of this body part */
179 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
180 printf (LSTFMT2c1
, size
);
186 printf (LSTFMT2c2
, size
, *cp
);
193 /* print Content-Description */
197 dp
= cpytrim (ct
->c_descr
);
199 printf (LSTFMT2d1v
, dp
);
201 printf (LSTFMT2d1
, dp
);
208 CI ci
= &ct
->c_ctinfo
;
210 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
211 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
212 get_param_value(pm
, '?'));
216 * If verbose, print any RFC-822 comments in the
219 if (ci
->ci_comment
) {
222 dp
= cpytrim (ci
->ci_comment
);
223 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
225 printf (LSTFMT2d2
, buffer
);
229 if (dispo
&& ct
->c_dispo_type
) {
230 printf ("\t disposition \"%s\"\n", ct
->c_dispo_type
);
233 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
) {
234 printf ("\t %s=\"%s\"\n", pm
->pm_name
,
235 get_param_value(pm
, '?'));
248 * Print debugging information about a content
254 CI ci
= &ct
->c_ctinfo
;
258 fprintf (stderr
, " partno \"%s\"\n", empty (ct
->c_partno
));
260 /* print MIME-Version line */
262 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
264 /* print Content-Type line */
266 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
268 /* print parsed elements of content type */
269 fprintf (stderr
, " type \"%s\"\n", empty (ci
->ci_type
));
270 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
271 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
272 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
274 /* print parsed parameters attached to content type */
275 fprintf (stderr
, " parameters\n");
276 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
)
277 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
278 get_param_value(pm
, '?'));
280 /* print internal flags for type/subtype */
281 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
282 ct
->c_type
, ct
->c_subtype
,
283 (unsigned int)(unsigned long) ct
->c_ctparams
);
285 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
286 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
287 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
289 /* print transfer encoding information */
291 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
293 /* print internal flags for transfer encoding */
294 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
295 ct
->c_encoding
, (unsigned int)(unsigned long) &ct
->c_cefile
);
297 /* print Content-ID */
299 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
301 /* print Content-Description */
303 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
305 /* print Content-Disposition */
307 fprintf (stderr
, " %s:%s", DISPO_FIELD
, ct
->c_dispo
);
309 fprintf(stderr
, " disposition \"%s\"\n", empty (ct
->c_dispo_type
));
310 fprintf(stderr
, " disposition parameters\n");
311 for (pm
= ct
->c_dispo_first
; pm
; pm
= pm
->pm_next
)
312 fprintf (stderr
, " %s=\"%s\"\n", pm
->pm_name
,
313 get_param_value(pm
, '?'));
315 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
316 (unsigned int)(unsigned long) ct
->c_fp
, empty (ct
->c_file
),
317 ct
->c_begin
, ct
->c_end
);
319 /* print more information about transfer encoding */
329 * list content information for type "multipart"
333 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
336 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
339 /* list the content for toplevel of this multipart */
340 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
342 /* now list for all the subparts */
343 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
344 CT p
= part
->mp_part
;
346 if (part_ok (p
) && type_ok (p
, 1))
347 list_switch (p
, 0, realsize
, verbose
, debug
, dispo
);
355 * list content information for type "message/partial"
359 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
362 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
364 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
366 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
368 printf (" of %d", p
->pm_maxno
);
377 * list content information for type "message/external"
381 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
384 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
387 * First list the information for the
388 * message/external content itself.
390 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
394 printf ("\t name=\"%s\"\n", e
->eb_name
);
396 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
398 printf ("\t site=\"%s\"\n", e
->eb_site
);
400 printf ("\t server=\"%s\"\n", e
->eb_server
);
402 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
404 printf ("\t url=\"%s\"\n", e
->eb_url
);
406 /* This must be defined */
407 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
410 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
411 if (e
->eb_permission
)
412 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
414 if (e
->eb_flags
== NOTOK
)
415 printf ("\t [service unavailable]\n");
420 * Now list the information for the external content
421 * to which this content points.
423 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
, dispo
);
430 * list content information for type "application"
431 * This no longer needs to be a separate function. It used to
432 * produce some output with verbose enabled, but that has been
433 * moved to list_content ().
437 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
,
440 list_content (ct
, toplevel
, realsize
, verbose
, debug
, dispo
);
447 * list information about the Content-Transfer-Encoding
452 list_encoding (CT ct
)
454 CE ce
= &ct
->c_cefile
;
456 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
457 (unsigned int)(unsigned long) ce
->ce_fp
,
458 ce
->ce_file
? ce
->ce_file
: "");