]>
diplodocus.org Git - nmh/blob - uip/mhshowsbr.c
3 * mhshowsbr.c -- routines to display the contents of MIME messages
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
12 #include <h/signals.h>
18 #include <h/mhparse.h>
19 #include <h/fmt_scan.h>
23 #endif /* ! HAVE_ICONV */
31 /* flags for moreproc/header display */
37 int part_ok (CT
, int);
38 int type_ok (CT
, int);
39 void content_error (char *, CT
, char *, ...);
40 void flush_errors (void);
45 int show_content_aux (CT
, int, char *, char *);
50 static void show_single_message (CT
, char *, int, int, int, struct format
*);
51 static void DisplayMsgHeader (CT
, char *, int);
52 static int show_switch (CT
, int, int, int, int, struct format
*);
53 static int show_content (CT
, int, int, int, struct format
*fmt
);
54 static int show_content_aux2 (CT
, int, char *, char *, int, int, int);
55 static int show_text (CT
, int, int);
56 static int show_multi (CT
, int, int, int, int, struct format
*);
57 static int show_multi_internal (CT
, int, int, int, int, struct format
*fmt
);
58 static int show_multi_aux (CT
, int, char *);
59 static int show_message_rfc822 (CT
, int);
60 static int show_partial (CT
, int);
61 static int show_external (CT
, int, int, int, int, struct format
*);
62 static int parse_display_string (CT
, char *, int *, int *, char *, char *,
63 size_t, int multipart
);
64 static int convert_content_charset (CT
, char **);
65 static struct format
*compile_marker(char *);
66 static void output_marker (CT
, struct format
*);
67 static void free_markercomps (void);
68 static int pidcheck(int);
71 * Components (and list of parameters/components) we care about for the
72 * content marker display.
75 static struct comp
*part_comp
= NULL
;
76 static struct comp
*ctype_comp
= NULL
;
77 static struct comp
*description_comp
= NULL
;
78 static struct comp
*dispo_comp
= NULL
;
80 struct param_comp_list
{
83 struct param_comp_list
*next
;
86 static struct param_comp_list
*ctype_pc_list
= NULL
;
87 static struct param_comp_list
*dispo_pc_list
= NULL
;
91 * Top level entry point to show/display a group of messages
95 show_all_messages (CT
*cts
, int concatsw
, int textonly
, int inlineonly
,
102 * If form is not specified, then get default form
103 * for showing headers of MIME messages.
106 formsw
= getcpy (etcpath ("mhl.headers"));
109 * Compile the content marker format line
111 fmt
= compile_marker(markerform
);
114 * If form is "mhl.null", suppress display of header.
116 if (!strcmp (formsw
, "mhl.null"))
119 for (ctp
= cts
; *ctp
; ctp
++) {
122 /* if top-level type is ok, then display message */
124 show_single_message (ct
, formsw
, concatsw
, textonly
, inlineonly
,
134 * Entry point to show/display a single message
138 show_single_message (CT ct
, char *form
, int concatsw
, int textonly
,
139 int inlineonly
, struct format
*fmt
)
145 /* Allow user executable bit so that temporary directories created by
146 * the viewer (e.g., lynx) are going to be accessible */
147 umask (ct
->c_umask
& ~(0100));
150 * If you have a format file, then display
151 * the message headers.
154 DisplayMsgHeader(ct
, form
, concatsw
);
156 /* Show the body of the message */
157 show_switch (ct
, 0, concatsw
, textonly
, inlineonly
, fmt
);
163 if (ct
->c_ceclosefnx
)
164 (*ct
->c_ceclosefnx
) (ct
);
166 /* block a few signals */
168 sigaddset (&set
, SIGHUP
);
169 sigaddset (&set
, SIGINT
);
170 sigaddset (&set
, SIGQUIT
);
171 sigaddset (&set
, SIGTERM
);
172 sigprocmask (SIG_BLOCK
, &set
, &oset
);
174 while (!concatsw
&& wait (&status
) != NOTOK
) {
179 /* reset the signal mask */
180 sigprocmask (SIG_SETMASK
, &oset
, &set
);
187 * Use the mhlproc to show the header fields
191 DisplayMsgHeader (CT ct
, char *form
, int concatsw
)
198 vec
= argsplit(mhlproc
, &file
, &vecp
);
199 vec
[vecp
++] = getcpy("-form");
200 vec
[vecp
++] = getcpy(form
);
201 vec
[vecp
++] = getcpy("-nobody");
202 vec
[vecp
++] = getcpy(ct
->c_file
);
205 * If we've specified -(no)moreproc,
206 * then just pass that along.
208 if (nomore
|| concatsw
) {
209 vec
[vecp
++] = getcpy("-nomoreproc");
211 vec
[vecp
++] = getcpy("-moreproc");
212 vec
[vecp
++] = getcpy(progsw
);
218 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
223 adios ("fork", "unable to");
228 fprintf (stderr
, "unable to exec ");
234 pidcheck(pidwait(child_id
, NOTOK
));
238 arglist_free(file
, vec
);
243 * Switching routine. Call the correct routine
244 * based on content type.
248 show_switch (CT ct
, int alternate
, int concatsw
, int textonly
, int inlineonly
,
251 switch (ct
->c_type
) {
253 return show_multi (ct
, alternate
, concatsw
, textonly
,
257 switch (ct
->c_subtype
) {
258 case MESSAGE_PARTIAL
:
259 return show_partial (ct
, alternate
);
261 case MESSAGE_EXTERNAL
:
262 return show_external (ct
, alternate
, concatsw
, textonly
,
267 return show_message_rfc822 (ct
, alternate
);
271 return show_text (ct
, alternate
, concatsw
);
277 return show_content (ct
, alternate
, textonly
, inlineonly
, fmt
);
280 adios (NULL
, "unknown content type %d", ct
->c_type
);
283 return 0; /* NOT REACHED */
288 * Generic method for displaying content
292 show_content (CT ct
, int alternate
, int textonly
, int inlineonly
,
295 char *cp
, buffer
[BUFSIZ
];
296 CI ci
= &ct
->c_ctinfo
;
299 * If we're here, we are not a text type. So we don't need to check
303 if (textonly
|| (inlineonly
&& is_inline(ct
))) {
304 output_marker(ct
, fmt
);
308 /* Check for invo_name-show-type/subtype */
309 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
310 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
311 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
312 return show_content_aux (ct
, alternate
, cp
, NULL
);
314 /* Check for invo_name-show-type */
315 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
316 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
317 return show_content_aux (ct
, alternate
, cp
, NULL
);
319 if ((cp
= ct
->c_showproc
))
320 return show_content_aux (ct
, alternate
, cp
, NULL
);
322 /* complain if we are not a part of a multipart/alternative */
324 content_error (NULL
, ct
, "don't know how to display content");
331 * Parse the display string for displaying generic content
335 show_content_aux (CT ct
, int alternate
, char *cp
, char *cracked
)
338 int xstdin
= 0, xlist
= 0;
339 char *file
, buffer
[BUFSIZ
];
341 if (!ct
->c_ceopenfnx
) {
343 content_error (NULL
, ct
, "don't know how to decode content");
349 if ((fd
= (*ct
->c_ceopenfnx
) (ct
, &file
)) == NOTOK
)
351 if (ct
->c_showproc
&& !strcmp (ct
->c_showproc
, "true"))
352 return (alternate
? DONE
: OK
);
354 if (! strcmp(invo_name
, "mhshow") &&
355 ct
->c_type
== CT_TEXT
&& ct
->c_subtype
== TEXT_PLAIN
) {
356 /* This has to be done after calling c_ceopenfnx, so
357 unfortunately the type checks are necessary without
358 some code rearrangement. And to make this really ugly,
359 only do it in mhshow, not mhfixmsg, mhn, or mhstore. */
360 if (convert_content_charset (ct
, &file
) == OK
) {
361 (*ct
->c_ceclosefnx
) (ct
);
362 if ((fd
= (*ct
->c_ceopenfnx
) (ct
, &file
)) == NOTOK
)
365 admonish (NULL
, "unable to convert character set%s to %s",
366 ct
->c_partno
? "of part " : "",
367 ct
->c_partno
? ct
->c_partno
: "",
368 content_charset (ct
));
373 strncpy (buffer
, cp
, sizeof(buffer
));
377 if (parse_display_string (ct
, cp
, &xstdin
, &xlist
, file
, buffer
,
378 sizeof(buffer
) - 1, 0)) {
379 admonish (NULL
, "Buffer overflow constructing show command!\n");
384 return show_content_aux2 (ct
, alternate
, cracked
, buffer
,
390 * Routine to actually display the content
394 show_content_aux2 (CT ct
, int alternate
, char *cracked
, char *buffer
,
395 int fd
, int xlist
, int xstdin
)
401 if (debugsw
|| cracked
) {
404 fprintf (stderr
, "%s msg %s", cracked
? "storing" : "show",
407 fprintf (stderr
, " part %s", ct
->c_partno
);
409 fprintf (stderr
, " using command (cd %s; %s)\n", cracked
, buffer
);
411 fprintf (stderr
, " using command %s\n", buffer
);
415 if (ct
->c_type
== CT_MULTIPART
)
416 list_content (ct
, -1, 1, 0, 0, 0);
418 list_switch (ct
, -1, 1, 0, 0, 0);
422 * If the command is a zero-length string, just write the output on
426 if (buffer
[0] == '\0') {
427 char readbuf
[BUFSIZ
];
431 advise(NULL
, "Cannot use NULL command to display content-type "
432 "%s/%s", ct
->c_ctinfo
.ci_type
, ct
->c_ctinfo
.ci_subtype
);
436 while ((cc
= read(fd
, readbuf
, sizeof(readbuf
))) > 0) {
437 fwrite(readbuf
, sizeof(char), cc
, stdout
);
441 advise("read", "while reading text content");
448 vec
= argsplit(buffer
, &file
, &vecp
);
453 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
457 advise ("fork", "unable to");
458 (*ct
->c_ceclosefnx
) (ct
);
468 fprintf (stderr
, "unable to exec ");
474 arglist_free(file
, vec
);
476 pidcheck (pidXwait (child_id
, NULL
));
479 (*ct
->c_ceclosefnx
) (ct
);
480 return (alternate
? DONE
: OK
);
486 * show content of type "text"
490 show_text (CT ct
, int alternate
, int concatsw
)
492 char *cp
, buffer
[BUFSIZ
];
493 CI ci
= &ct
->c_ctinfo
;
495 /* Check for invo_name-show-type/subtype */
496 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
497 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
498 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
499 return show_content_aux (ct
, alternate
, cp
, NULL
);
501 /* Check for invo_name-show-type */
502 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
503 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
504 return show_content_aux (ct
, alternate
, cp
, NULL
);
507 * Use default method if content is text/plain, or if
508 * if it is not a text part of a multipart/alternative
510 if (!alternate
|| ct
->c_subtype
== TEXT_PLAIN
) {
512 snprintf(buffer
, sizeof(buffer
), "%%l");
514 snprintf (buffer
, sizeof(buffer
), "%%l%s %%F", progsw
? progsw
:
515 moreproc
&& *moreproc
? moreproc
: DEFAULT_PAGER
);
516 cp
= (ct
->c_showproc
= add (buffer
, NULL
));
517 return show_content_aux (ct
, alternate
, cp
, NULL
);
525 * show message body of type "multipart"
529 show_multi (CT ct
, int alternate
, int concatsw
, int textonly
, int inlineonly
,
532 char *cp
, buffer
[BUFSIZ
];
533 CI ci
= &ct
->c_ctinfo
;
535 /* Check for invo_name-show-type/subtype */
536 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
537 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
538 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
539 return show_multi_aux (ct
, alternate
, cp
);
541 /* Check for invo_name-show-type */
542 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
543 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
544 return show_multi_aux (ct
, alternate
, cp
);
546 if ((cp
= ct
->c_showproc
))
547 return show_multi_aux (ct
, alternate
, cp
);
550 * Use default method to display this multipart content. Even
551 * unknown types are displayable, since they're treated as mixed
554 return show_multi_internal (ct
, alternate
, concatsw
, textonly
,
560 * show message body of subtypes of multipart that
561 * we understand directly (mixed, alternate, etc...)
565 show_multi_internal (CT ct
, int alternate
, int concatsw
, int textonly
,
566 int inlineonly
, struct format
*fmt
)
568 int alternating
, nowalternate
, result
;
569 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
574 nowalternate
= alternate
;
576 if (ct
->c_subtype
== MULTI_ALTERNATE
) {
582 * alternate -> we are a part inside an multipart/alternative
583 * alternating -> we are a multipart/alternative
586 result
= alternate
? NOTOK
: OK
;
588 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
591 if (part_ok (p
, 1) && type_ok (p
, 1)) {
594 inneresult
= show_switch (p
, nowalternate
, concatsw
, textonly
,
596 switch (inneresult
) {
598 if (alternate
&& !alternating
) {
611 alternate
= nowalternate
= 0;
621 if (alternating
&& !part
) {
623 content_error (NULL
, ct
, "don't know how to display any of the contents");
634 * Parse display string for multipart content
635 * and use external program to display it.
639 show_multi_aux (CT ct
, int alternate
, char *cp
)
641 /* xstdin is only used in the call to parse_display_string():
642 its value is ignored in the function. */
643 int xstdin
= 0, xlist
= 0;
644 char *file
, buffer
[BUFSIZ
];
645 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
649 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
652 if (!p
->c_ceopenfnx
) {
654 content_error (NULL
, p
, "don't know how to decode content");
658 if (p
->c_storage
== NULL
) {
660 if ((*p
->c_ceopenfnx
) (p
, &file
) == NOTOK
)
663 p
->c_storage
= add (file
, NULL
);
665 if (p
->c_showproc
&& !strcmp (p
->c_showproc
, "true"))
666 return (alternate
? DONE
: OK
);
667 (*p
->c_ceclosefnx
) (p
);
671 if (parse_display_string (ct
, cp
, &xstdin
, &xlist
, file
,
672 buffer
, sizeof(buffer
) - 1, 1)) {
673 admonish (NULL
, "Buffer overflow constructing show command!\n");
677 return show_content_aux2 (ct
, alternate
, NULL
, buffer
, NOTOK
, xlist
, 0);
682 * show content of type "message/rfc822"
686 show_message_rfc822 (CT ct
, int alternate
)
688 char *cp
, buffer
[BUFSIZ
];
689 CI ci
= &ct
->c_ctinfo
;
691 /* Check for invo_name-show-type/subtype */
692 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
693 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
694 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
695 return show_content_aux (ct
, alternate
, cp
, NULL
);
697 /* Check for invo_name-show-type */
698 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
699 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
700 return show_content_aux (ct
, alternate
, cp
, NULL
);
702 if ((cp
= ct
->c_showproc
))
703 return show_content_aux (ct
, alternate
, cp
, NULL
);
705 /* default method for message/rfc822 */
706 if (ct
->c_subtype
== MESSAGE_RFC822
) {
707 cp
= (ct
->c_showproc
= add ("%pecho -file %F", NULL
));
708 return show_content_aux (ct
, alternate
, cp
, NULL
);
711 /* complain if we are not a part of a multipart/alternative */
713 content_error (NULL
, ct
, "don't know how to display content");
720 * Show content of type "message/partial".
724 show_partial (CT ct
, int alternate
)
726 NMH_UNUSED (alternate
);
728 content_error (NULL
, ct
,
729 "in order to display this message, you must reassemble it");
735 * Show content of type "message/external".
737 * THE ERROR CHECKING IN THIS ONE IS NOT DONE YET.
741 show_external (CT ct
, int alternate
, int concatsw
, int textonly
, int inlineonly
,
744 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
745 CT p
= e
->eb_content
;
750 return show_switch (p
, alternate
, concatsw
, textonly
, inlineonly
, fmt
);
755 parse_display_string (CT ct
, char *cp
, int *xstdin
, int *xlist
,
756 char *file
, char *buffer
, size_t buflen
,
759 char *bp
= buffer
, *pp
;
760 CI ci
= &ct
->c_ctinfo
;
762 bp
[0] = bp
[buflen
] = '\0';
764 for ( ; *cp
&& buflen
> 0; cp
++) {
770 /* insert parameters from Content-Type field */
775 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
776 snprintf (bp
, buflen
, "%s%s=\"%s\"", s
, pm
->pm_name
,
777 get_param_value(pm
, '?'));
787 /* insert content description */
791 s
= trimcpy (ct
->c_descr
);
792 strncpy (bp
, s
, buflen
);
798 /* no longer implemented */
802 /* %f, and stdin is terminal not content */
808 /* insert filename(s) containing content */
809 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
814 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
817 snprintf (bp
, buflen
, "%s%s", s
, p
->c_storage
);
824 /* insert filename containing content */
825 snprintf (bp
, buflen
, "%s", file
);
828 * Old comments below are left here for posterity.
829 * This was/is tricky.
831 /* since we've quoted the file argument, set things up
832 * to look past it, to avoid problems with the quoting
833 * logic below. (I know, I should figure out what's
834 * broken with the quoting logic, but..)
837 * Here's the email that submitted the patch with
839 * https://www.mail-archive.com/nmh-workers@mhost.com/
841 * I can't tell from that exactly what was broken,
842 * beyond misquoting of the filename. The profile
843 * had appearances of %F both with and without quotes.
844 * The unquoted ones should have been quoted by the
846 * The fix was to always quote the filename. But
847 * that broke '%F' because it expanded to ''filename''.
850 * Old comments above are left here for posterity.
851 * The quoting below should work properly now.
857 /* No longer supported */
861 /* display listing prior to displaying content */
866 /* insert subtype of content */
867 strncpy (bp
, ci
->ci_subtype
, buflen
);
871 /* insert character % */
875 const char *closing_brace
= strchr(cp
, '}');
878 const size_t param_len
= closing_brace
- cp
- 1;
879 char *param
= mh_xmalloc(param_len
+ 1);
882 (void) strncpy(param
, cp
+ 1, param_len
);
883 param
[param_len
] = '\0';
884 value
= get_param(ci
->ci_first_pm
, param
, '?', 0);
887 cp
+= param_len
+ 1; /* Skip both braces, too. */
890 /* %{param} is set in the Content-Type header.
891 After the break below, quote it if necessary. */
892 (void) strncpy(bp
, value
, buflen
);
895 /* %{param} not found, so skip it completely. cp
896 was advanced above. */
900 /* This will get confused if there are multiple %{}'s,
901 but its real purpose is to avoid doing bad things
902 above if a closing brace wasn't found. */
904 "no closing brace for display string escape %s",
921 /* Did we actually insert something? */
923 /* Insert single quote if not inside quotes already */
924 if (!quoted
&& buflen
) {
926 memmove (pp
+ 1, pp
, len
+1);
932 /* Escape existing quotes */
933 while ((pp
= strchr (pp
, '\'')) && buflen
> 3) {
936 /* Quoted. Let this quote close that quoting.
937 Insert an escaped quote to replace it and
938 another quote to reopen quoting, which will be
940 memmove (pp
+ 2, pp
, len
);
947 /* Not quoted. This should not be reached with
948 the current code, but handle the condition
949 in case the code changes. Just escape the
951 memmove (pp
, pp
-1, len
+1);
957 /* If pp is still set, that means we ran out of space. */
961 if (quoted
&& buflen
) {
962 /* See if we need to close the quote by looking
963 for an odd number of unescaped close quotes in
964 the remainder of the display string. */
965 int found_quote
= 0, escaped
= 0;
968 for (c
= cp
+1; *c
; ++c
) {
976 found_quote
= ! found_quote
;
1001 (ct
->c_termproc
&& buflen
<= strlen(ct
->c_termproc
))) {
1002 /* content_error would provide a more useful error message
1003 * here, except that if we got overrun, it probably would
1009 /* use charset string to modify display method */
1010 if (ct
->c_termproc
) {
1013 strncpy (term
, buffer
, sizeof(term
));
1014 snprintf (buffer
, buflen
, ct
->c_termproc
, term
);
1022 convert_charset (CT ct
, char *dest_charset
, int *message_mods
) {
1023 char *src_charset
= content_charset (ct
);
1026 /* norm_charmap() is case sensitive. */
1027 char *src_charset_u
= upcase (src_charset
);
1028 char *dest_charset_u
= upcase (dest_charset
);
1029 int different_charsets
=
1030 strcmp (norm_charmap (src_charset
), norm_charmap (dest_charset
));
1032 free (dest_charset_u
);
1033 free (src_charset_u
);
1035 if (different_charsets
) {
1037 iconv_t conv_desc
= NULL
;
1044 int opened_input_file
= 0;
1045 char src_buffer
[BUFSIZ
];
1049 if ((conv_desc
= iconv_open (dest_charset
, src_charset
)) ==
1051 advise (NULL
, "Can't convert %s to %s", src_charset
, dest_charset
);
1055 if ((tempfile
= m_mktemp2 (NULL
, invo_name
, &fd
, NULL
)) == NULL
) {
1056 adios (NULL
, "unable to create temporary file in %s",
1059 dest
= add (tempfile
, NULL
);
1061 if (ct
->c_cefile
.ce_file
) {
1062 file
= &ct
->c_cefile
.ce_file
;
1063 fp
= &ct
->c_cefile
.ce_fp
;
1065 } else if (ct
->c_file
) {
1068 begin
= (size_t) ct
->c_begin
;
1069 end
= (size_t) ct
->c_end
;
1070 } /* else no input file: shouldn't happen */
1072 if (file
&& *file
&& fp
) {
1074 if ((*fp
= fopen (*file
, "r")) == NULL
) {
1075 advise (*file
, "unable to open for reading");
1078 opened_input_file
= 1;
1085 size_t bytes_to_read
=
1086 end
> 0 && end
> begin
? end
- begin
: sizeof src_buffer
;
1088 fseeko (*fp
, begin
, SEEK_SET
);
1089 while ((inbytes
= fread (src_buffer
, 1,
1090 min (bytes_to_read
, sizeof src_buffer
),
1092 char dest_buffer
[BUFSIZ
];
1093 ICONV_CONST
char *ib
= src_buffer
;
1094 char *ob
= dest_buffer
;
1095 size_t outbytes
= sizeof dest_buffer
;
1096 size_t outbytes_before
= outbytes
;
1098 if (end
> 0) bytes_to_read
-= inbytes
;
1100 if (iconv (conv_desc
, &ib
, &inbytes
, &ob
, &outbytes
) ==
1105 write (fd
, dest_buffer
, outbytes_before
- outbytes
);
1109 if (opened_input_file
) {
1115 iconv_close (conv_desc
);
1119 /* Replace the decoded file with the converted one. */
1120 if (ct
->c_cefile
.ce_file
) {
1121 if (ct
->c_cefile
.ce_unlink
) {
1122 (void) m_unlink (ct
->c_cefile
.ce_file
);
1124 free (ct
->c_cefile
.ce_file
);
1126 ct
->c_cefile
.ce_file
= dest
;
1127 ct
->c_cefile
.ce_unlink
= 1;
1131 /* Update ct->c_ctline. */
1133 char *ctline
= concat(" ", ct
->c_ctinfo
.ci_type
, "/",
1134 ct
->c_ctinfo
.ci_subtype
, NULL
);
1137 replace_param(&ct
->c_ctinfo
.ci_first_pm
,
1138 &ct
->c_ctinfo
.ci_last_pm
, "charset",
1140 outline
= output_params(strlen(TYPE_FIELD
) + 1 + strlen(ctline
),
1141 ct
->c_ctinfo
.ci_first_pm
, NULL
, 0);
1143 ctline
= add(outline
, ctline
);
1147 free (ct
->c_ctline
);
1148 ct
->c_ctline
= ctline
;
1149 } /* else no CT line, which is odd */
1151 /* Update Content-Type header field. */
1152 for (hf
= ct
->c_first_hf
; hf
; hf
= hf
->next
) {
1153 if (! strcasecmp (TYPE_FIELD
, hf
->name
)) {
1154 char *ctline
= concat (ct
->c_ctline
, "\n", NULL
);
1162 (void) m_unlink (dest
);
1164 #else /* ! HAVE_ICONV */
1165 NMH_UNUSED (message_mods
);
1167 advise (NULL
, "Can't convert %s to %s without iconv", src_charset
,
1170 #endif /* ! HAVE_ICONV */
1178 convert_content_charset (CT ct
, char **file
) {
1180 /* Using current locale, see if the content needs to be converted. */
1182 /* content_charset() cannot return NULL. */
1183 char *charset
= content_charset (ct
);
1185 if (! check_charset (charset
, strlen (charset
))) {
1188 if (convert_charset (ct
, get_charset (), &unused
) == 0) {
1189 *file
= ct
->c_cefile
.ce_file
;
1194 #else /* ! HAVE_ICONV */
1197 #endif /* ! HAVE_ICONV */
1203 * Compile our format string and save any parameters we care about.
1206 #define DEFAULT_MARKER "[ part %{part} - %{content-type} - %<{description}" \
1207 "%{description}%?{cdispo-filename}%{cdispo-filename}" \
1208 "%|%{ctype-name}%> ]"
1210 static struct format
*
1211 compile_marker(char *markerform
)
1215 struct comp
*comp
= NULL
;
1216 unsigned int bucket
;
1217 struct param_comp_list
*pc_entry
;
1219 fmtstring
= new_fs(markerform
, NULL
, DEFAULT_MARKER
);
1221 (void) fmt_compile(fmtstring
, &fmt
, 1);
1225 * Things we care about:
1227 * part - Part name (e.g., 1.1)
1228 * content-type - Content-Type
1229 * description - Content-Description
1230 * disposition - Content-Disposition (inline, attachment)
1231 * ctype-<param> - Content-Type parameter
1232 * cdispo-<param> - Content-Disposition parameter
1235 while ((comp
= fmt_nextcomp(comp
, &bucket
)) != NULL
) {
1236 if (strcasecmp(comp
->c_name
, "part") == 0) {
1238 } else if (strcasecmp(comp
->c_name
, "content-type") == 0) {
1240 } else if (strcasecmp(comp
->c_name
, "description") == 0) {
1241 description_comp
= comp
;
1242 } else if (strcasecmp(comp
->c_name
, "disposition") == 0) {
1244 } else if (strncasecmp(comp
->c_name
, "ctype-", 6) == 0 &&
1245 strlen(comp
->c_name
) > 6) {
1246 pc_entry
= mh_xmalloc(sizeof(*pc_entry
));
1247 pc_entry
->param
= getcpy(comp
->c_name
+ 6);
1248 pc_entry
->comp
= comp
;
1249 pc_entry
->next
= ctype_pc_list
;
1250 ctype_pc_list
= pc_entry
;
1251 } else if (strncasecmp(comp
->c_name
, "cdispo-", 7) == 0 &&
1252 strlen(comp
->c_name
) > 7) {
1253 pc_entry
= mh_xmalloc(sizeof(*pc_entry
));
1254 pc_entry
->param
= getcpy(comp
->c_name
+ 7);
1255 pc_entry
->comp
= comp
;
1256 pc_entry
->next
= dispo_pc_list
;
1257 dispo_pc_list
= pc_entry
;
1265 * Output on stdout an appropriate marker for this content, using mh-format
1269 output_marker(CT ct
, struct format
*fmt
)
1271 char outbuf
[BUFSIZ
];
1272 struct param_comp_list
*pcentry
;
1276 * Grab any items we care about.
1279 if (ctype_comp
&& ct
->c_ctinfo
.ci_type
) {
1280 ctype_comp
->c_text
= concat(ct
->c_ctinfo
.ci_type
, "/",
1281 ct
->c_ctinfo
.ci_subtype
, NULL
);
1284 if (part_comp
&& ct
->c_partno
) {
1285 part_comp
->c_text
= getcpy(ct
->c_partno
);
1288 if (description_comp
&& ct
->c_descr
) {
1289 description_comp
->c_text
= getcpy(ct
->c_descr
);
1292 if (dispo_comp
&& ct
->c_dispo_type
) {
1293 dispo_comp
->c_text
= getcpy(ct
->c_dispo_type
);
1296 for (pcentry
= ctype_pc_list
; pcentry
!= NULL
; pcentry
= pcentry
->next
) {
1297 pcentry
->comp
->c_text
= get_param(ct
->c_ctinfo
.ci_first_pm
,
1298 pcentry
->param
, '?', 0);
1301 for (pcentry
= dispo_pc_list
; pcentry
!= NULL
; pcentry
= pcentry
->next
) {
1302 pcentry
->comp
->c_text
= get_param(ct
->c_dispo_first
,
1303 pcentry
->param
, '?', 0);
1306 fmt_scan(fmt
, outbuf
, sizeof(outbuf
), sizeof(outbuf
), dat
, NULL
);
1308 fputs(outbuf
, stdout
);
1314 * Reset (and free) any of the saved marker text
1318 free_markercomps(void)
1320 struct param_comp_list
*pc_entry
, *pc2
;
1324 description_comp
= NULL
;
1327 for (pc_entry
= ctype_pc_list
; pc_entry
!= NULL
; ) {
1328 free(pc_entry
->param
);
1329 pc2
= pc_entry
->next
;
1334 for (pc_entry
= dispo_pc_list
; pc_entry
!= NULL
; ) {
1335 free(pc_entry
->param
);
1336 pc2
= pc_entry
->next
;
1343 * Exit if the display process returned with a nonzero exit code, or terminated
1344 * with a SIGQUIT signal.
1348 pidcheck (int status
)
1350 if ((status
& 0xff00) == 0xff00 || (status
& 0x007f) != SIGQUIT
)