]>
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>
19 #include <h/mhparse.h>
23 int part_ok (CT
, int);
24 int type_ok (CT
, int);
25 void flush_errors (void);
30 void list_all_messages (CT
*, int, int, int, int);
31 int list_switch (CT
, int, int, int, int);
32 int list_content (CT
, int, int, int, int);
37 static void list_single_message (CT
, int, int, int);
38 static int list_debug (CT
);
39 static int list_multi (CT
, int, int, int, int);
40 static int list_partial (CT
, int, int, int, int);
41 static int list_external (CT
, int, int, int, int);
42 static int list_application (CT
, int, int, int, int);
43 static int list_encoding (CT
);
47 * various formats for -list option
49 #define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n"
50 #define LSTFMT2a "%4d "
51 #define LSTFMT2b "%-5s %-24.24s "
52 #define LSTFMT2c1 "%5lu"
53 #define LSTFMT2c2 "%4lu%c"
54 #define LSTFMT2c3 "huge "
56 #define LSTFMT2d1 " %-36.36s"
57 #define LSTFMT2d2 "\t %-65.65s\n"
61 * Top level entry point to list group of messages
65 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
)
70 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
72 for (ctp
= cts
; *ctp
; ctp
++) {
74 list_single_message (ct
, realsize
, verbose
, debug
);
82 * Entry point to list a single message
86 list_single_message (CT ct
, int realsize
, int verbose
, int debug
)
88 if (type_ok (ct
, 1)) {
90 list_switch (ct
, 1, realsize
, verbose
, debug
);
96 (*ct
->c_ceclosefnx
) (ct
);
102 * Primary switching routine to list information about a content
106 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
108 switch (ct
->c_type
) {
110 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
);
114 switch (ct
->c_subtype
) {
115 case MESSAGE_PARTIAL
:
116 return list_partial (ct
, toplevel
, realsize
, verbose
, debug
);
119 case MESSAGE_EXTERNAL
:
120 return list_external (ct
, toplevel
, realsize
, verbose
, debug
);
125 return list_content (ct
, toplevel
, realsize
, verbose
, debug
);
134 return list_content (ct
, toplevel
, realsize
, verbose
, debug
);
138 return list_application (ct
, toplevel
, realsize
, verbose
, debug
);
142 /* list_debug (ct); */
143 adios (NULL
, "unknown content type %d", ct
->c_type
);
147 return 0; /* NOT REACHED */
151 #define empty(s) ((s) ? (s) : "")
154 * Method for listing information about a simple/generic content
158 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
161 char *cp
, buffer
[BUFSIZ
];
162 CI ci
= &ct
->c_ctinfo
;
164 printf (toplevel
> 0 ? LSTFMT2a
: toplevel
< 0 ? "part " : " ",
165 atoi (r1bindex (empty (ct
->c_file
), '/')));
166 snprintf (buffer
, sizeof(buffer
), "%s/%s", empty (ci
->ci_type
),
167 empty (ci
->ci_subtype
));
168 printf (LSTFMT2b
, empty (ct
->c_partno
), buffer
);
170 if (ct
->c_cesizefnx
&& realsize
)
171 size
= (*ct
->c_cesizefnx
) (ct
);
173 size
= ct
->c_end
- ct
->c_begin
;
175 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
176 for (cp
= " KMGT"; size
> 9999; size
>>= 10)
180 /* print size of this body part */
183 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
184 printf (LSTFMT2c1
, size
);
190 printf (LSTFMT2c2
, size
, *cp
);
197 /* print Content-Description */
201 dp
= trimcpy (cp
= add (ct
->c_descr
, NULL
));
203 printf (LSTFMT2d1
, dp
);
211 CI ci
= &ct
->c_ctinfo
;
213 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++)
214 printf ("\t %s=\"%s\"\n", *ap
, *ep
);
217 * If verbose, print any RFC-822 comments in the
220 if (ci
->ci_comment
) {
223 dp
= trimcpy (cp
= add (ci
->ci_comment
, NULL
));
225 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
227 printf (LSTFMT2d2
, buffer
);
239 * Print debugging information about a content
246 CI ci
= &ct
->c_ctinfo
;
249 fprintf (stderr
, " partno \"%s\"\n", empty (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", empty (ci
->ci_type
));
261 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
262 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
263 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
265 /* print parsed parameters attached to content type */
266 fprintf (stderr
, " parameters\n");
267 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++)
268 fprintf (stderr
, " %s=\"%s\"\n", *ap
, *ep
);
270 /* print internal flags for type/subtype */
271 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
272 ct
->c_type
, ct
->c_subtype
,
273 (unsigned int)(unsigned long) ct
->c_ctparams
);
275 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
276 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
277 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
279 /* print transfer encoding information */
281 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
283 /* print internal flags for transfer encoding */
284 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
285 ct
->c_encoding
, (unsigned int)(unsigned long) ct
->c_cefile
);
287 /* print Content-ID */
289 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
291 /* print Content-Description */
293 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
295 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
296 (unsigned int)(unsigned long) ct
->c_fp
, empty (ct
->c_file
),
297 ct
->c_begin
, ct
->c_end
);
299 /* 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
)
315 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
318 /* list the content for toplevel of this multipart */
319 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
321 /* now list for all the subparts */
322 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
323 CT p
= part
->mp_part
;
325 if (part_ok (p
, 1) && type_ok (p
, 1))
326 list_switch (p
, 0, realsize
, verbose
, debug
);
334 * list content information for type "message/partial"
338 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
340 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
342 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
344 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
346 printf (" of %d", p
->pm_maxno
);
355 * list content information for type "message/external"
359 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
361 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
364 * First list the information for the
365 * message/external content itself.
367 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
371 printf ("\t name=\"%s\"\n", e
->eb_name
);
373 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
375 printf ("\t site=\"%s\"\n", e
->eb_site
);
377 printf ("\t server=\"%s\"\n", e
->eb_server
);
379 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
381 /* This must be defined */
382 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
385 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
386 if (e
->eb_permission
)
387 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
389 if (e
->eb_flags
== NOTOK
)
390 printf ("\t [service unavailable]\n");
394 * Now list the information for the external content
395 * to which this content points.
397 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
);
404 * list content information for type "application"
405 * This no longer needs to be a separate function. It used to
406 * produce some output with verbose enabled, but that has been
407 * moved to list_content ().
411 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
413 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
420 * list information about the Content-Transfer-Encoding
425 list_encoding (CT ct
)
429 if ((ce
= ct
->c_cefile
))
430 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
431 (unsigned int)(unsigned long) ce
->ce_fp
,
432 ce
->ce_file
? ce
->ce_file
: "");