]>
diplodocus.org Git - nmh/blob - uip/mhlistsbr.c
3 * mhlistsbr.c -- routines to list information about the
4 * -- contents of MIME messages
8 * This code is Copyright (c) 2002, by the authors of nmh. See the
9 * COPYRIGHT file in the root directory of the nmh distribution for
10 * complete copyright information.
15 #include <h/signals.h>
21 #include <h/mhparse.h>
26 int part_ok (CT
, int);
27 int type_ok (CT
, int);
28 void flush_errors (void);
33 void list_all_messages (CT
*, int, int, int, int);
34 int list_switch (CT
, int, int, int, int);
35 int list_content (CT
, int, int, int, int);
40 static void list_single_message (CT
, int, int, int);
41 static int list_debug (CT
);
42 static int list_multi (CT
, int, int, int, int);
43 static int list_partial (CT
, int, int, int, int);
44 static int list_external (CT
, int, int, int, int);
45 static int list_application (CT
, int, int, int, int);
46 static int list_encoding (CT
);
50 * various formats for -list option
52 #define LSTFMT1 "%4s %-5s %-24s %5s %-36s\n"
53 #define LSTFMT2a "%4d "
54 #define LSTFMT2b "%-5s %-24.24s "
55 #define LSTFMT2c1 "%5lu"
56 #define LSTFMT2c2 "%4lu%c"
57 #define LSTFMT2c3 "huge "
59 #define LSTFMT2d1 " %-36.36s"
60 #define LSTFMT2d2 "\t %-65.65s\n"
64 * Top level entry point to list group of messages
68 list_all_messages (CT
*cts
, int headers
, int realsize
, int verbose
, int debug
)
73 printf (LSTFMT1
, "msg", "part", "type/subtype", "size", "description");
75 for (ctp
= cts
; *ctp
; ctp
++) {
77 list_single_message (ct
, realsize
, verbose
, debug
);
85 * Entry point to list a single message
89 list_single_message (CT ct
, int realsize
, int verbose
, int debug
)
91 if (type_ok (ct
, 1)) {
93 list_switch (ct
, 1, realsize
, verbose
, debug
);
99 (*ct
->c_ceclosefnx
) (ct
);
105 * Primary switching routine to list information about a content
109 list_switch (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
111 switch (ct
->c_type
) {
113 return list_multi (ct
, toplevel
, realsize
, verbose
, debug
);
117 switch (ct
->c_subtype
) {
118 case MESSAGE_PARTIAL
:
119 return list_partial (ct
, toplevel
, realsize
, verbose
, debug
);
122 case MESSAGE_EXTERNAL
:
123 return list_external (ct
, toplevel
, realsize
, verbose
, debug
);
128 return list_content (ct
, toplevel
, realsize
, verbose
, debug
);
137 return list_content (ct
, toplevel
, realsize
, verbose
, debug
);
141 return list_application (ct
, toplevel
, realsize
, verbose
, debug
);
145 /* list_debug (ct); */
146 adios (NULL
, "unknown content type %d", ct
->c_type
);
150 return 0; /* NOT REACHED */
154 #define empty(s) ((s) ? (s) : "")
157 * Method for listing information about a simple/generic content
161 list_content (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
164 char *cp
, buffer
[BUFSIZ
];
165 CI ci
= &ct
->c_ctinfo
;
167 printf (toplevel
> 0 ? LSTFMT2a
: toplevel
< 0 ? "part " : " ",
168 atoi (r1bindex (empty (ct
->c_file
), '/')));
169 snprintf (buffer
, sizeof(buffer
), "%s/%s", empty (ci
->ci_type
),
170 empty (ci
->ci_subtype
));
171 printf (LSTFMT2b
, empty (ct
->c_partno
), buffer
);
173 if (ct
->c_cesizefnx
&& realsize
)
174 size
= (*ct
->c_cesizefnx
) (ct
);
176 size
= ct
->c_end
- ct
->c_begin
;
178 /* find correct scale for size (Kilo/Mega/Giga/Tera) */
179 for (cp
= " KMGT"; size
> 9999; size
>>= 10)
183 /* print size of this body part */
186 if (size
> 0 || ct
->c_encoding
!= CE_EXTERNAL
)
187 printf (LSTFMT2c1
, size
);
193 printf (LSTFMT2c2
, size
, *cp
);
200 /* print Content-Description */
204 dp
= trimcpy (cp
= add (ct
->c_descr
, NULL
));
206 printf (LSTFMT2d1
, dp
);
213 * If verbose, print any RFC-822 comments in the
216 if (verbose
&& ci
->ci_comment
) {
219 dp
= trimcpy (cp
= add (ci
->ci_comment
, NULL
));
221 snprintf (buffer
, sizeof(buffer
), "(%s)", dp
);
223 printf (LSTFMT2d2
, buffer
);
234 * Print debugging information about a content
241 CI ci
= &ct
->c_ctinfo
;
244 fprintf (stderr
, " partno \"%s\"\n", empty (ct
->c_partno
));
246 /* print MIME-Version line */
248 fprintf (stderr
, " %s:%s\n", VRSN_FIELD
, ct
->c_vrsn
);
250 /* print Content-Type line */
252 fprintf (stderr
, " %s:%s\n", TYPE_FIELD
, ct
->c_ctline
);
254 /* print parsed elements of content type */
255 fprintf (stderr
, " type \"%s\"\n", empty (ci
->ci_type
));
256 fprintf (stderr
, " subtype \"%s\"\n", empty (ci
->ci_subtype
));
257 fprintf (stderr
, " comment \"%s\"\n", empty (ci
->ci_comment
));
258 fprintf (stderr
, " magic \"%s\"\n", empty (ci
->ci_magic
));
260 /* print parsed parameters attached to content type */
261 fprintf (stderr
, " parameters\n");
262 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++)
263 fprintf (stderr
, " %s=\"%s\"\n", *ap
, *ep
);
265 /* print internal flags for type/subtype */
266 fprintf (stderr
, " type 0x%x subtype 0x%x params 0x%x\n",
267 ct
->c_type
, ct
->c_subtype
, (unsigned int) ct
->c_ctparams
);
269 fprintf (stderr
, " showproc \"%s\"\n", empty (ct
->c_showproc
));
270 fprintf (stderr
, " termproc \"%s\"\n", empty (ct
->c_termproc
));
271 fprintf (stderr
, " storeproc \"%s\"\n", empty (ct
->c_storeproc
));
273 /* print transfer encoding information */
275 fprintf (stderr
, " %s:%s", ENCODING_FIELD
, ct
->c_celine
);
277 /* print internal flags for transfer encoding */
278 fprintf (stderr
, " transfer encoding 0x%x params 0x%x\n",
279 ct
->c_encoding
, (unsigned int) ct
->c_cefile
);
281 /* print Content-ID */
283 fprintf (stderr
, " %s:%s", ID_FIELD
, ct
->c_id
);
285 /* print Content-Description */
287 fprintf (stderr
, " %s:%s", DESCR_FIELD
, ct
->c_descr
);
289 fprintf (stderr
, " read fp 0x%x file \"%s\" begin %ld end %ld\n",
290 (unsigned int) ct
->c_fp
, empty (ct
->c_file
),
291 ct
->c_begin
, ct
->c_end
);
293 /* print more information about transfer encoding */
303 * list content information for type "multipart"
307 list_multi (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
309 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
312 /* list the content for toplevel of this multipart */
313 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
315 /* now list for all the subparts */
316 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
317 CT p
= part
->mp_part
;
319 if (part_ok (p
, 1) && type_ok (p
, 1))
320 list_switch (p
, 0, realsize
, verbose
, debug
);
328 * list content information for type "message/partial"
332 list_partial (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
334 struct partial
*p
= (struct partial
*) ct
->c_ctparams
;
336 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
338 printf ("\t [message %s, part %d", p
->pm_partid
, p
->pm_partno
);
340 printf (" of %d", p
->pm_maxno
);
349 * list content information for type "message/external"
353 list_external (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
355 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
358 * First list the information for the
359 * message/external content itself.
361 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
365 printf ("\t name=\"%s\"\n", e
->eb_name
);
367 printf ("\t directory=\"%s\"\n", e
->eb_dir
);
369 printf ("\t site=\"%s\"\n", e
->eb_site
);
371 printf ("\t server=\"%s\"\n", e
->eb_server
);
373 printf ("\t subject=\"%s\"\n", e
->eb_subject
);
375 /* This must be defined */
376 printf ("\t access-type=\"%s\"\n", e
->eb_access
);
379 printf ("\t mode=\"%s\"\n", e
->eb_mode
);
380 if (e
->eb_permission
)
381 printf ("\t permission=\"%s\"\n", e
->eb_permission
);
383 if (e
->eb_flags
== NOTOK
)
384 printf ("\t [service unavailable]\n");
388 * Now list the information for the external content
389 * to which this content points.
391 list_content (e
->eb_content
, 0, realsize
, verbose
, debug
);
398 * list content information for type "application"
402 list_application (CT ct
, int toplevel
, int realsize
, int verbose
, int debug
)
404 list_content (ct
, toplevel
, realsize
, verbose
, debug
);
407 CI ci
= &ct
->c_ctinfo
;
409 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++)
410 printf ("\t %s=\"%s\"\n", *ap
, *ep
);
418 * list information about the Content-Transfer-Encoding
423 list_encoding (CT ct
)
427 if ((ce
= ct
->c_cefile
))
428 fprintf (stderr
, " decoded fp 0x%x file \"%s\"\n",
429 (unsigned int) ce
->ce_fp
, ce
->ce_file
? ce
->ce_file
: "");