]>
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>
22 #endif /* ! HAVE_ICONV */
32 /* flags for moreproc/header display */
38 static sigjmp_buf intrenv
;
42 int part_ok (CT
, int);
43 int type_ok (CT
, int);
44 void content_error (char *, CT
, char *, ...);
45 void flush_errors (void);
50 void show_all_messages (CT
*);
51 int show_content_aux (CT
, int, int, char *, char *);
56 static void show_single_message (CT
, char *);
57 static void DisplayMsgHeader (CT
, char *);
58 static int show_switch (CT
, int, int);
59 static int show_content (CT
, int, int);
60 static int show_content_aux2 (CT
, int, int, char *, char *, int, int, int, int,
62 static int show_text (CT
, int, int);
63 static int show_multi (CT
, int, int);
64 static int show_multi_internal (CT
, int, int);
65 static int show_multi_aux (CT
, int, int, char *);
66 static int show_message_rfc822 (CT
, int, int);
67 static int show_partial (CT
, int, int);
68 static int show_external (CT
, int, int);
69 static int parse_display_string (CT
, char *, int *, int *, int *, int *, char *,
70 char *, size_t, int multipart
);
71 static int convert_content_charset (CT
, char **);
72 static void intrser (int);
76 * Top level entry point to show/display a group of messages
80 show_all_messages (CT
*cts
)
85 * If form is not specified, then get default form
86 * for showing headers of MIME messages.
89 formsw
= getcpy (etcpath ("mhl.headers"));
92 * If form is "mhl.null", suppress display of header.
94 if (!strcmp (formsw
, "mhl.null"))
97 for (ctp
= cts
; *ctp
; ctp
++) {
100 /* if top-level type is ok, then display message */
102 show_single_message (ct
, formsw
);
108 * Entry point to show/display a single message
112 show_single_message (CT ct
, char *form
)
118 /* Allow user executable bit so that temporary directories created by
119 * the viewer (e.g., lynx) are going to be accessible */
120 umask (ct
->c_umask
& ~(0100));
123 * If you have a format file, then display
124 * the message headers.
127 DisplayMsgHeader(ct
, form
);
131 /* Show the body of the message */
132 show_switch (ct
, 1, 0);
138 if (ct
->c_ceclosefnx
)
139 (*ct
->c_ceclosefnx
) (ct
);
141 /* block a few signals */
143 sigaddset (&set
, SIGHUP
);
144 sigaddset (&set
, SIGINT
);
145 sigaddset (&set
, SIGQUIT
);
146 sigaddset (&set
, SIGTERM
);
147 sigprocmask (SIG_BLOCK
, &set
, &oset
);
149 while (wait (&status
) != NOTOK
) {
154 /* reset the signal mask */
155 sigprocmask (SIG_SETMASK
, &oset
, &set
);
163 * Use the mhlproc to show the header fields
167 DisplayMsgHeader (CT ct
, char *form
)
174 vec
= argsplit(mhlproc
, &file
, &vecp
);
175 vec
[vecp
++] = getcpy("-form");
176 vec
[vecp
++] = getcpy(form
);
177 vec
[vecp
++] = getcpy("-nobody");
178 vec
[vecp
++] = getcpy(ct
->c_file
);
181 * If we've specified -(no)moreproc,
182 * then just pass that along.
185 vec
[vecp
++] = getcpy("-nomoreproc");
187 vec
[vecp
++] = getcpy("-moreproc");
188 vec
[vecp
++] = getcpy(progsw
);
194 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
199 adios ("fork", "unable to");
204 fprintf (stderr
, "unable to exec ");
214 arglist_free(file
, vec
);
219 * Switching routine. Call the correct routine
220 * based on content type.
224 show_switch (CT ct
, int serial
, int alternate
)
226 switch (ct
->c_type
) {
228 return show_multi (ct
, serial
, alternate
);
231 switch (ct
->c_subtype
) {
232 case MESSAGE_PARTIAL
:
233 return show_partial (ct
, serial
, alternate
);
235 case MESSAGE_EXTERNAL
:
236 return show_external (ct
, serial
, alternate
);
240 return show_message_rfc822 (ct
, serial
, alternate
);
244 return show_text (ct
, serial
, alternate
);
250 return show_content (ct
, serial
, alternate
);
253 adios (NULL
, "unknown content type %d", ct
->c_type
);
256 return 0; /* NOT REACHED */
261 * Generic method for displaying content
265 show_content (CT ct
, int serial
, int alternate
)
267 char *cp
, buffer
[BUFSIZ
];
268 CI ci
= &ct
->c_ctinfo
;
270 /* Check for invo_name-show-type/subtype */
271 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
272 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
273 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
274 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
276 /* Check for invo_name-show-type */
277 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
278 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
279 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
281 if ((cp
= ct
->c_showproc
))
282 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
284 /* complain if we are not a part of a multipart/alternative */
286 content_error (NULL
, ct
, "don't know how to display content");
293 * Parse the display string for displaying generic content
297 show_content_aux (CT ct
, int serial
, int alternate
, char *cp
, char *cracked
)
300 int xstdin
= 0, xlist
= 0, xpause
= 0, xtty
= 0;
301 char *file
, buffer
[BUFSIZ
];
303 if (!ct
->c_ceopenfnx
) {
305 content_error (NULL
, ct
, "don't know how to decode content");
311 if ((fd
= (*ct
->c_ceopenfnx
) (ct
, &file
)) == NOTOK
)
313 if (ct
->c_showproc
&& !strcmp (ct
->c_showproc
, "true"))
314 return (alternate
? DONE
: OK
);
316 if (! strcmp(invo_name
, "mhshow") &&
317 ct
->c_type
== CT_TEXT
&& ct
->c_subtype
== TEXT_PLAIN
) {
318 /* This has to be done after calling c_ceopenfnx, so
319 unfortunately the type checks are necessary without
320 some code rearrangement. And to make this really ugly,
321 only do it in mhshow, not mhfixmsg, mhn, or mhstore. */
322 if (convert_content_charset (ct
, &file
) != OK
) {
323 admonish (NULL
, "unable to convert character set%s to %s",
324 ct
->c_partno
? "of part " : "",
325 ct
->c_partno
? ct
->c_partno
: "",
326 content_charset (ct
));
331 strncpy (buffer
, cp
, sizeof(buffer
));
335 if (parse_display_string (ct
, cp
, &xstdin
, &xlist
, &xpause
, &xtty
, file
,
336 buffer
, sizeof(buffer
) - 1, 0)) {
337 admonish (NULL
, "Buffer overflow constructing show command!\n");
342 return show_content_aux2 (ct
, serial
, alternate
, cracked
, buffer
,
343 fd
, xlist
, xpause
, xstdin
, xtty
);
348 * Routine to actually display the content
352 show_content_aux2 (CT ct
, int serial
, int alternate
, char *cracked
, char *buffer
,
353 int fd
, int xlist
, int xpause
, int xstdin
, int xtty
)
359 if (debugsw
|| cracked
) {
362 fprintf (stderr
, "%s msg %s", cracked
? "storing" : "show",
365 fprintf (stderr
, " part %s", ct
->c_partno
);
367 fprintf (stderr
, " using command (cd %s; %s)\n", cracked
, buffer
);
369 fprintf (stderr
, " using command %s\n", buffer
);
372 if (xpid
< 0 || (xtty
&& xpid
)) {
375 pidcheck(pidwait (xpid
, NOTOK
));
382 if (ct
->c_type
== CT_MULTIPART
)
383 list_content (ct
, -1, 1, 0, 0, 0);
385 list_switch (ct
, -1, 1, 0, 0, 0);
387 if (xpause
&& isatty (fileno (stdout
))) {
389 SIGNAL_HANDLER istat
;
391 if (SOprintf ("Press <return> to show content..."))
392 printf ("Press <return> to show content...");
394 istat
= SIGNAL (SIGINT
, intrser
);
395 if ((intr
= sigsetjmp (intrenv
, 1)) == OK
) {
398 read (fileno (stdout
), prompt
, sizeof(prompt
));
400 SIGNAL (SIGINT
, istat
);
401 if (intr
!= OK
|| prompt
[0] == 'n') {
402 (*ct
->c_ceclosefnx
) (ct
);
403 return (alternate
? DONE
: NOTOK
);
405 if (prompt
[0] == 'q') done(OK
);
409 vec
= argsplit(buffer
, &file
, &vecp
);
414 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
418 advise ("fork", "unable to");
419 (*ct
->c_ceclosefnx
) (ct
);
429 fprintf (stderr
, "unable to exec ");
435 arglist_free(file
, vec
);
438 ct
->c_pid
= child_id
;
442 pidcheck (pidXwait (child_id
, NULL
));
446 (*ct
->c_ceclosefnx
) (ct
);
447 return (alternate
? DONE
: OK
);
453 * show content of type "text"
457 show_text (CT ct
, int serial
, int alternate
)
459 char *cp
, buffer
[BUFSIZ
];
460 CI ci
= &ct
->c_ctinfo
;
462 /* Check for invo_name-show-type/subtype */
463 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
464 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
465 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
466 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
468 /* Check for invo_name-show-type */
469 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
470 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
471 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
474 * Use default method if content is text/plain, or if
475 * if it is not a text part of a multipart/alternative
477 if (!alternate
|| ct
->c_subtype
== TEXT_PLAIN
) {
478 snprintf (buffer
, sizeof(buffer
), "%%p%s %%F", progsw
? progsw
:
479 moreproc
&& *moreproc
? moreproc
: DEFAULT_PAGER
);
480 cp
= (ct
->c_showproc
= add (buffer
, NULL
));
481 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
489 * show message body of type "multipart"
493 show_multi (CT ct
, int serial
, int alternate
)
495 char *cp
, buffer
[BUFSIZ
];
496 CI ci
= &ct
->c_ctinfo
;
498 /* Check for invo_name-show-type/subtype */
499 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
500 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
501 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
502 return show_multi_aux (ct
, serial
, alternate
, cp
);
504 /* Check for invo_name-show-type */
505 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
506 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
507 return show_multi_aux (ct
, serial
, alternate
, cp
);
509 if ((cp
= ct
->c_showproc
))
510 return show_multi_aux (ct
, serial
, alternate
, cp
);
513 * Use default method to display this multipart content. Even
514 * unknown types are displayable, since they're treated as mixed
517 return show_multi_internal (ct
, serial
, alternate
);
522 * show message body of subtypes of multipart that
523 * we understand directly (mixed, alternate, etc...)
527 show_multi_internal (CT ct
, int serial
, int alternate
)
529 int alternating
, nowalternate
, nowserial
, result
;
530 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
536 nowalternate
= alternate
;
538 if (ct
->c_subtype
== MULTI_PARALLEL
) {
539 nowserial
= serialsw
;
540 } else if (ct
->c_subtype
== MULTI_ALTERNATE
) {
548 * unknown subtypes of multipart (treat as mixed per rfc2046)
553 /* block a few signals */
556 sigaddset (&set
, SIGHUP
);
557 sigaddset (&set
, SIGINT
);
558 sigaddset (&set
, SIGQUIT
);
559 sigaddset (&set
, SIGTERM
);
560 sigprocmask (SIG_BLOCK
, &set
, &oset
);
564 * alternate -> we are a part inside an multipart/alternative
565 * alternating -> we are a multipart/alternative
568 result
= alternate
? NOTOK
: OK
;
570 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
573 if (part_ok (p
, 1) && type_ok (p
, 1)) {
576 inneresult
= show_switch (p
, nowserial
, nowalternate
);
577 switch (inneresult
) {
579 if (alternate
&& !alternating
) {
592 alternate
= nowalternate
= 0;
602 if (alternating
&& !part
) {
604 content_error (NULL
, ct
, "don't know how to display any of the contents");
609 if (serial
&& !nowserial
) {
615 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
619 if (kill (p
->c_pid
, 0) == NOTOK
)
626 while (kids
> 0 && (pid
= wait (&status
)) != NOTOK
) {
629 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
634 if (p
->c_pid
== pid
) {
645 /* reset the signal mask */
646 sigprocmask (SIG_SETMASK
, &oset
, &set
);
654 * Parse display string for multipart content
655 * and use external program to display it.
659 show_multi_aux (CT ct
, int serial
, int alternate
, char *cp
)
661 /* xstdin is only used in the call to parse_display_string():
662 its value is ignored in the function. */
663 int xstdin
= 0, xlist
= 0, xpause
= 0, xtty
= 0;
664 char *file
, buffer
[BUFSIZ
];
665 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
669 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
672 if (!p
->c_ceopenfnx
) {
674 content_error (NULL
, p
, "don't know how to decode content");
678 if (p
->c_storage
== NULL
) {
680 if ((*p
->c_ceopenfnx
) (p
, &file
) == NOTOK
)
683 p
->c_storage
= add (file
, NULL
);
685 if (p
->c_showproc
&& !strcmp (p
->c_showproc
, "true"))
686 return (alternate
? DONE
: OK
);
687 (*p
->c_ceclosefnx
) (p
);
691 if (parse_display_string (ct
, cp
, &xstdin
, &xlist
, &xpause
, &xtty
, file
,
692 buffer
, sizeof(buffer
) - 1, 1)) {
693 admonish (NULL
, "Buffer overflow constructing show command!\n");
697 return show_content_aux2 (ct
, serial
, alternate
, NULL
, buffer
,
698 NOTOK
, xlist
, xpause
, 0, xtty
);
703 * show content of type "message/rfc822"
707 show_message_rfc822 (CT ct
, int serial
, int alternate
)
709 char *cp
, buffer
[BUFSIZ
];
710 CI ci
= &ct
->c_ctinfo
;
712 /* Check for invo_name-show-type/subtype */
713 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
714 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
715 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
716 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
718 /* Check for invo_name-show-type */
719 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
720 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
721 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
723 if ((cp
= ct
->c_showproc
))
724 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
726 /* default method for message/rfc822 */
727 if (ct
->c_subtype
== MESSAGE_RFC822
) {
728 cp
= (ct
->c_showproc
= add ("%pecho -file %F", NULL
));
729 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
732 /* complain if we are not a part of a multipart/alternative */
734 content_error (NULL
, ct
, "don't know how to display content");
741 * Show content of type "message/partial".
745 show_partial (CT ct
, int serial
, int alternate
)
748 NMH_UNUSED (alternate
);
750 content_error (NULL
, ct
,
751 "in order to display this message, you must reassemble it");
757 * Show content of type "message/external".
759 * THE ERROR CHECKING IN THIS ONE IS NOT DONE YET.
763 show_external (CT ct
, int serial
, int alternate
)
765 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
766 CT p
= e
->eb_content
;
771 return show_switch (p
, serial
, alternate
);
776 parse_display_string (CT ct
, char *cp
, int *xstdin
, int *xlist
, int *xpause
,
777 int *xtty
, char *file
, char *buffer
, size_t buflen
,
780 char *bp
= buffer
, *pp
;
781 CI ci
= &ct
->c_ctinfo
;
783 bp
[0] = bp
[buflen
] = '\0';
785 for ( ; *cp
&& buflen
> 0; cp
++) {
791 /* insert parameters from Content-Type field */
796 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
797 snprintf (bp
, buflen
, "%s%s=\"%s\"", s
, pm
->pm_name
,
798 get_param_value(pm
, '?'));
808 /* insert content description */
812 s
= trimcpy (ct
->c_descr
);
813 strncpy (bp
, s
, buflen
);
819 /* exclusive execution */
824 /* %e, %f, and stdin is terminal not content */
831 /* insert filename(s) containing content */
832 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
837 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
840 snprintf (bp
, buflen
, "%s%s", s
, p
->c_storage
);
847 /* insert filename containing content */
848 snprintf (bp
, buflen
, "%s", file
);
851 * Old comments below are left here for posterity.
852 * This was/is tricky.
854 /* since we've quoted the file argument, set things up
855 * to look past it, to avoid problems with the quoting
856 * logic below. (I know, I should figure out what's
857 * broken with the quoting logic, but..)
860 * Here's the email that submitted the patch with
862 * https://www.mail-archive.com/nmh-workers@mhost.com/
864 * I can't tell from that exactly what was broken,
865 * beyond misquoting of the filename. The profile
866 * had appearances of %F both with and without quotes.
867 * The unquoted ones should have been quoted by the
869 * The fix was to always quote the filename. But
870 * that broke '%F' because it expanded to ''filename''.
873 * Old comments above are left here for posterity.
874 * The quoting below should work properly now.
880 /* %l, and pause prior to displaying content */
885 /* display listing prior to displaying content */
890 /* insert subtype of content */
891 strncpy (bp
, ci
->ci_subtype
, buflen
);
895 /* insert character % */
899 const char *closing_brace
= strchr(cp
, '}');
902 const size_t param_len
= closing_brace
- cp
- 1;
903 char *param
= mh_xmalloc(param_len
+ 1);
906 (void) strncpy(param
, cp
+ 1, param_len
);
907 param
[param_len
] = '\0';
908 value
= get_param(ci
->ci_first_pm
, param
, '?', 0);
911 cp
+= param_len
+ 1; /* Skip both braces, too. */
914 /* %{param} is set in the Content-Type header.
915 After the break below, quote it if necessary. */
916 (void) strncpy(bp
, value
, buflen
);
919 /* %{param} not found, so skip it completely. cp
920 was advanced above. */
924 /* This will get confused if there are multiple %{}'s,
925 but its real purpose is to avoid doing bad things
926 above if a closing brace wasn't found. */
928 "no closing brace for display string escape %s",
945 /* Did we actually insert something? */
947 /* Insert single quote if not inside quotes already */
948 if (!quoted
&& buflen
) {
950 memmove (pp
+ 1, pp
, len
+1);
956 /* Escape existing quotes */
957 while ((pp
= strchr (pp
, '\'')) && buflen
> 3) {
960 /* Quoted. Let this quote close that quoting.
961 Insert an escaped quote to replace it and
962 another quote to reopen quoting, which will be
964 memmove (pp
+ 2, pp
, len
);
971 /* Not quoted. This should not be reached with
972 the current code, but handle the condition
973 in case the code changes. Just escape the
975 memmove (pp
, pp
-1, len
+1);
981 /* If pp is still set, that means we ran out of space. */
985 if (quoted
&& buflen
) {
986 /* See if we need to close the quote by looking
987 for an odd number of unescaped close quotes in
988 the remainder of the display string. */
989 int found_quote
= 0, escaped
= 0;
992 for (c
= cp
+1; *c
; ++c
) {
1000 found_quote
= ! found_quote
;
1005 if (! found_quote
) {
1025 (ct
->c_termproc
&& buflen
<= strlen(ct
->c_termproc
))) {
1026 /* content_error would provide a more useful error message
1027 * here, except that if we got overrun, it probably would
1033 /* use charset string to modify display method */
1034 if (ct
->c_termproc
) {
1037 strncpy (term
, buffer
, sizeof(term
));
1038 snprintf (buffer
, buflen
, ct
->c_termproc
, term
);
1046 convert_charset (CT ct
, char *dest_charset
, int *message_mods
) {
1047 char *src_charset
= content_charset (ct
);
1050 /* norm_charmap() is case sensitive. */
1051 char *src_charset_u
= upcase (src_charset
);
1052 char *dest_charset_u
= upcase (dest_charset
);
1053 int different_charsets
=
1054 strcmp (norm_charmap (src_charset
), norm_charmap (dest_charset
));
1056 free (dest_charset_u
);
1057 free (src_charset_u
);
1059 if (different_charsets
) {
1061 iconv_t conv_desc
= NULL
;
1068 int opened_input_file
= 0;
1069 char src_buffer
[BUFSIZ
];
1073 if ((conv_desc
= iconv_open (dest_charset
, src_charset
)) ==
1075 advise (NULL
, "Can't convert %s to %s", src_charset
, dest_charset
);
1079 if ((tempfile
= m_mktemp2 (NULL
, invo_name
, &fd
, NULL
)) == NULL
) {
1080 adios (NULL
, "unable to create temporary file in %s",
1083 dest
= add (tempfile
, NULL
);
1085 if (ct
->c_cefile
.ce_file
) {
1086 file
= &ct
->c_cefile
.ce_file
;
1087 fp
= &ct
->c_cefile
.ce_fp
;
1089 } else if (ct
->c_file
) {
1092 begin
= (size_t) ct
->c_begin
;
1093 end
= (size_t) ct
->c_end
;
1094 } /* else no input file: shouldn't happen */
1096 if (file
&& *file
&& fp
) {
1098 if ((*fp
= fopen (*file
, "r")) == NULL
) {
1099 advise (*file
, "unable to open for reading");
1102 opened_input_file
= 1;
1109 size_t bytes_to_read
=
1110 end
> 0 && end
> begin
? end
- begin
: sizeof src_buffer
;
1112 fseeko (*fp
, begin
, SEEK_SET
);
1113 while ((inbytes
= fread (src_buffer
, 1,
1114 min (bytes_to_read
, sizeof src_buffer
),
1116 char dest_buffer
[BUFSIZ
];
1117 ICONV_CONST
char *ib
= src_buffer
;
1118 char *ob
= dest_buffer
;
1119 size_t outbytes
= sizeof dest_buffer
;
1120 size_t outbytes_before
= outbytes
;
1122 if (end
> 0) bytes_to_read
-= inbytes
;
1124 if (iconv (conv_desc
, &ib
, &inbytes
, &ob
, &outbytes
) ==
1129 write (fd
, dest_buffer
, outbytes_before
- outbytes
);
1133 if (opened_input_file
) {
1139 iconv_close (conv_desc
);
1143 /* Replace the decoded file with the converted one. */
1144 if (ct
->c_cefile
.ce_file
) {
1145 if (ct
->c_cefile
.ce_unlink
) {
1146 (void) m_unlink (ct
->c_cefile
.ce_file
);
1148 free (ct
->c_cefile
.ce_file
);
1150 ct
->c_cefile
.ce_file
= dest
;
1151 ct
->c_cefile
.ce_unlink
= 1;
1155 /* Update ct->c_ctline. */
1157 char *ctline
= concat(" ", ct
->c_ctinfo
.ci_type
, "/",
1158 ct
->c_ctinfo
.ci_subtype
, NULL
);
1161 replace_param(&ct
->c_ctinfo
.ci_first_pm
,
1162 &ct
->c_ctinfo
.ci_last_pm
, "charset",
1164 outline
= output_params(strlen(TYPE_FIELD
) + 1 + strlen(ctline
),
1165 ct
->c_ctinfo
.ci_first_pm
, NULL
, 0);
1167 ctline
= add(outline
, ctline
);
1171 free (ct
->c_ctline
);
1172 ct
->c_ctline
= ctline
;
1173 } /* else no CT line, which is odd */
1175 /* Update Content-Type header field. */
1176 for (hf
= ct
->c_first_hf
; hf
; hf
= hf
->next
) {
1177 if (! strcasecmp (TYPE_FIELD
, hf
->name
)) {
1178 char *ctline
= concat (ct
->c_ctline
, "\n", NULL
);
1186 (void) m_unlink (dest
);
1188 #else /* ! HAVE_ICONV */
1189 NMH_UNUSED (message_mods
);
1191 advise (NULL
, "Can't convert %s to %s without iconv", src_charset
,
1194 #endif /* ! HAVE_ICONV */
1202 convert_content_charset (CT ct
, char **file
) {
1204 /* Using current locale, see if the content needs to be converted. */
1206 /* content_charset() cannot return NULL. */
1207 char *charset
= content_charset (ct
);
1209 if (! check_charset (charset
, strlen (charset
))) {
1212 if (convert_charset (ct
, get_charset (), &unused
) == 0) {
1213 *file
= ct
->c_cefile
.ce_file
;
1218 #else /* ! HAVE_ICONV */
1221 #endif /* ! HAVE_ICONV */
1233 siglongjmp (intrenv
, DONE
);