]>
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>
21 int part_ok (CT
, int);
22 int type_ok (CT
, int);
23 void flush_errors (void);
28 void list_all_messages (CT
*, int, int, int, int);
29 int list_switch (CT
, int, int, int, int);
30 int list_content (CT
, int, int, int, int);
35 static void list_single_message (CT
, int, int, int);
36 static int list_debug (CT
);
37 static int list_multi (CT
, int, int, int, int);
38 static int list_partial (CT
, int, int, int, int);
39 static int list_external (CT
, int, int, int, int);
40 static int list_application (CT
, int, int, int, int);
41 static int list_encoding (CT
);
45 * various formats for -list option
47 #define LSTFMT1 "%4s %-5s %-24s %5s %s\n"
48 #define LSTFMT2a "%4d "
49 #define LSTFMT2b "%-5s %-24.24s "
50 #define LSTFMT2c1 "%5lu"
51 #define LSTFMT2c2 "%4lu%c"
52 #define LSTFMT2c3 "huge "
54 #define LSTFMT2d1 " %.36s"
55 #define LSTFMT2d2 "\t %-65.65s\n"
59 * Top level entry point to list group of messages
63 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
)
68 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
70 for (ctp
= cts
; *ctp
; ctp
++) {
72 list_single_message (ct
, realsize
, verbose
, debug
);
80 * Entry point to list a single message
84 list_single_message (CT ct
, int realsize
, int verbose
, int debug
)
86 if (type_ok (ct
, 1)) {
88 list_switch (ct
, 1, realsize
, verbose
, debug
);
94 (*ct
->c_ceclosefnx
) (ct
);
100 * Primary switching routine to list information about a content
104 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
106 switch (ct
->c_type
) {
108 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
);
111 switch (ct
->c_subtype
) {
112 case MESSAGE_PARTIAL
:
113 return list_partial (ct
, toplevel
, realsize
, verbose
, debug
);
115 case MESSAGE_EXTERNAL
:
116 return list_external (ct
, toplevel
, realsize
, verbose
, debug
);
120 return list_content (ct
, toplevel
, realsize
, verbose
, debug
);
127 return list_content (ct
, toplevel
, realsize
, verbose
, debug
);
130 return list_application (ct
, toplevel
, realsize
, verbose
, debug
);
133 /* list_debug (ct); */
134 adios (NULL
, "unknown content type %d", ct
->c_type
);
137 return 0; /* NOT REACHED */
141 #define empty(s) ((s) ? (s) : "")
144 * Method for listing information about a simple/generic content
148 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
151 char *cp
, buffer
[BUFSIZ
];
152 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
));
161 printf (LSTFMT2b
, empty (ct
->c_partno
), buffer
);
163 if (ct
->c_cesizefnx
&& realsize
)
164 size
= (*ct
->c_cesizefnx
) (ct
);
166 size
= ct
->c_end
- ct
->c_begin
;
168 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
169 for (cp
= " KMGT"; size
> 9999; size
>>= 10)
173 /* print size of this body part */
176 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
177 printf (LSTFMT2c1
, size
);
183 printf (LSTFMT2c2
, size
, *cp
);
190 /* print Content-Description */
194 dp
= cpytrim (ct
->c_descr
);
195 printf (LSTFMT2d1
, dp
);
203 CI ci
= &ct
->c_ctinfo
;
205 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++)
206 printf ("\t %s=\"%s\"\n", *ap
, *ep
);
209 * If verbose, print any RFC-822 comments in the
212 if (ci
->ci_comment
) {
215 dp
= cpytrim (ci
->ci_comment
);
216 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
218 printf (LSTFMT2d2
, buffer
);
230 * Print debugging information about a content
237 CI ci
= &ct
->c_ctinfo
;
240 fprintf (stderr
, " partno \"%s\"\n", empty (ct
->c_partno
));
242 /* print MIME-Version line */
244 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
246 /* print Content-Type line */
248 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
250 /* print parsed elements of content type */
251 fprintf (stderr
, " type \"%s\"\n", empty (ci
->ci_type
));
252 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
253 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
254 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
256 /* print parsed parameters attached to content type */
257 fprintf (stderr
, " parameters\n");
258 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++)
259 fprintf (stderr
, " %s=\"%s\"\n", *ap
, *ep
);
261 /* print internal flags for type/subtype */
262 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
263 ct
->c_type
, ct
->c_subtype
,
264 (unsigned int)(unsigned long) ct
->c_ctparams
);
266 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
267 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
268 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
270 /* print transfer encoding information */
272 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
274 /* print internal flags for transfer encoding */
275 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
276 ct
->c_encoding
, (unsigned int)(unsigned long) &ct
->c_cefile
);
278 /* print Content-ID */
280 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
282 /* print Content-Description */
284 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
286 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
287 (unsigned int)(unsigned long) ct
->c_fp
, empty (ct
->c_file
),
288 ct
->c_begin
, ct
->c_end
);
290 /* print more information about transfer encoding */
300 * list content information for type "multipart"
304 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
306 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
309 /* list the content for toplevel of this multipart */
310 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
312 /* now list for all the subparts */
313 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
314 CT p
= part
->mp_part
;
316 if (part_ok (p
, 1) && type_ok (p
, 1))
317 list_switch (p
, 0, realsize
, verbose
, debug
);
325 * list content information for type "message/partial"
329 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
331 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
333 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
335 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
337 printf (" of %d", p
->pm_maxno
);
346 * list content information for type "message/external"
350 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
352 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
355 * First list the information for the
356 * message/external content itself.
358 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
362 printf ("\t name=\"%s\"\n", e
->eb_name
);
364 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
366 printf ("\t site=\"%s\"\n", e
->eb_site
);
368 printf ("\t server=\"%s\"\n", e
->eb_server
);
370 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
372 /* This must be defined */
373 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
376 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
377 if (e
->eb_permission
)
378 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
380 if (e
->eb_flags
== NOTOK
)
381 printf ("\t [service unavailable]\n");
385 * Now list the information for the external content
386 * to which this content points.
388 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
);
395 * list content information for type "application"
396 * This no longer needs to be a separate function. It used to
397 * produce some output with verbose enabled, but that has been
398 * moved to list_content ().
402 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
404 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
411 * list information about the Content-Transfer-Encoding
416 list_encoding (CT ct
)
418 CE ce
= &ct
->c_cefile
;
420 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
421 (unsigned int)(unsigned long) ce
->ce_fp
,
422 ce
->ce_file
? ce
->ce_file
: "");