]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
8e25c1645fd3d06bcaacfe8da31fb7abd2d0e54c
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>
18 #include <h/mhparse.h>
22 int part_ok (CT
, int);
23 int type_ok (CT
, int);
24 void flush_errors (void);
29 void list_all_messages (CT
*, int, int, int, int);
30 int list_switch (CT
, int, int, int, int);
31 int list_content (CT
, int, int, int, int);
36 static void list_single_message (CT
, int, int, int);
37 static int list_debug (CT
);
38 static int list_multi (CT
, int, int, int, int);
39 static int list_partial (CT
, int, int, int, int);
40 static int list_external (CT
, int, int, int, int);
41 static int list_application (CT
, int, int, int, int);
42 static int list_encoding (CT
);
46 * various formats for -list option
48 #define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n"
49 #define LSTFMT2a "%4d "
50 #define LSTFMT2b "%-5s %-24.24s "
51 #define LSTFMT2c1 "%5lu"
52 #define LSTFMT2c2 "%4lu%c"
53 #define LSTFMT2c3 "huge "
55 #define LSTFMT2d1 " %-36.36s"
56 #define LSTFMT2d2 "\t %-65.65s\n"
60 * Top level entry point to list group of messages
64 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
)
69 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
71 for (ctp
= cts
; *ctp
; ctp
++) {
73 list_single_message (ct
, realsize
, verbose
, debug
);
81 * Entry point to list a single message
85 list_single_message (CT ct
, int realsize
, int verbose
, int debug
)
87 if (type_ok (ct
, 1)) {
89 list_switch (ct
, 1, realsize
, verbose
, debug
);
95 (*ct
->c_ceclosefnx
) (ct
);
101 * Primary switching routine to list information about a content
105 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
107 switch (ct
->c_type
) {
109 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
);
113 switch (ct
->c_subtype
) {
114 case MESSAGE_PARTIAL
:
115 return list_partial (ct
, toplevel
, realsize
, verbose
, debug
);
118 case MESSAGE_EXTERNAL
:
119 return list_external (ct
, toplevel
, realsize
, verbose
, debug
);
124 return list_content (ct
, toplevel
, realsize
, verbose
, debug
);
133 return list_content (ct
, toplevel
, realsize
, verbose
, debug
);
137 return list_application (ct
, toplevel
, realsize
, verbose
, debug
);
141 /* list_debug (ct); */
142 adios (NULL
, "unknown content type %d", ct
->c_type
);
146 return 0; /* NOT REACHED */
150 #define empty(s) ((s) ? (s) : "")
153 * Method for listing information about a simple/generic content
157 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
160 char *cp
, buffer
[BUFSIZ
];
161 CI ci
= &ct
->c_ctinfo
;
163 printf (toplevel
> 0 ? LSTFMT2a
: toplevel
< 0 ? "part " : " ",
164 atoi (r1bindex (empty (ct
->c_file
), '/')));
165 snprintf (buffer
, sizeof(buffer
), "%s/%s", empty (ci
->ci_type
),
166 empty (ci
->ci_subtype
));
167 printf (LSTFMT2b
, empty (ct
->c_partno
), buffer
);
169 if (ct
->c_cesizefnx
&& realsize
)
170 size
= (*ct
->c_cesizefnx
) (ct
);
172 size
= ct
->c_end
- ct
->c_begin
;
174 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
175 for (cp
= " KMGT"; size
> 9999; size
>>= 10)
179 /* print size of this body part */
182 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
183 printf (LSTFMT2c1
, size
);
189 printf (LSTFMT2c2
, size
, *cp
);
196 /* print Content-Description */
200 dp
= cpytrim (ct
->c_descr
);
201 printf (LSTFMT2d1
, dp
);
209 CI ci
= &ct
->c_ctinfo
;
211 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++)
212 printf ("\t %s=\"%s\"\n", *ap
, *ep
);
215 * If verbose, print any RFC-822 comments in the
218 if (ci
->ci_comment
) {
221 dp
= cpytrim (ci
->ci_comment
);
222 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
224 printf (LSTFMT2d2
, buffer
);
236 * Print debugging information about a content
243 CI ci
= &ct
->c_ctinfo
;
246 fprintf (stderr
, " partno \"%s\"\n", empty (ct
->c_partno
));
248 /* print MIME-Version line */
250 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
252 /* print Content-Type line */
254 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
256 /* print parsed elements of content type */
257 fprintf (stderr
, " type \"%s\"\n", empty (ci
->ci_type
));
258 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
259 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
260 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
262 /* print parsed parameters attached to content type */
263 fprintf (stderr
, " parameters\n");
264 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++)
265 fprintf (stderr
, " %s=\"%s\"\n", *ap
, *ep
);
267 /* print internal flags for type/subtype */
268 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
269 ct
->c_type
, ct
->c_subtype
,
270 (unsigned int)(unsigned long) ct
->c_ctparams
);
272 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
273 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
274 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
276 /* print transfer encoding information */
278 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
280 /* print internal flags for transfer encoding */
281 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
282 ct
->c_encoding
, (unsigned int)(unsigned long) &ct
->c_cefile
);
284 /* print Content-ID */
286 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
288 /* print Content-Description */
290 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
292 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
293 (unsigned int)(unsigned long) ct
->c_fp
, empty (ct
->c_file
),
294 ct
->c_begin
, ct
->c_end
);
296 /* print more information about transfer encoding */
306 * list content information for type "multipart"
310 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
312 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
315 /* list the content for toplevel of this multipart */
316 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
318 /* now list for all the subparts */
319 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
320 CT p
= part
->mp_part
;
322 if (part_ok (p
, 1) && type_ok (p
, 1))
323 list_switch (p
, 0, realsize
, verbose
, debug
);
331 * list content information for type "message/partial"
335 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
337 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
339 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
341 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
343 printf (" of %d", p
->pm_maxno
);
352 * list content information for type "message/external"
356 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
358 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
361 * First list the information for the
362 * message/external content itself.
364 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
368 printf ("\t name=\"%s\"\n", e
->eb_name
);
370 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
372 printf ("\t site=\"%s\"\n", e
->eb_site
);
374 printf ("\t server=\"%s\"\n", e
->eb_server
);
376 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
378 /* This must be defined */
379 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
382 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
383 if (e
->eb_permission
)
384 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
386 if (e
->eb_flags
== NOTOK
)
387 printf ("\t [service unavailable]\n");
391 * Now list the information for the external content
392 * to which this content points.
394 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
);
401 * list content information for type "application"
402 * This no longer needs to be a separate function. It used to
403 * produce some output with verbose enabled, but that has been
404 * moved to list_content ().
408 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
410 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
417 * list information about the Content-Transfer-Encoding
422 list_encoding (CT ct
)
424 CE ce
= &ct
->c_cefile
;
426 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
427 (unsigned int)(unsigned long) ce
->ce_fp
,
428 ce
->ce_file
? ce
->ce_file
: "");