]>
diplodocus.org Git - nmh/blob - uip/mhshowsbr.c
fa449772c09d97140e6459f7c3338334f1dcc885
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 */
31 char *display_charset
= NULL
;
33 /* flags for moreproc/header display */
39 static sigjmp_buf intrenv
;
43 int part_ok (CT
, int);
44 int type_ok (CT
, int);
45 void content_error (char *, CT
, char *, ...);
46 void flush_errors (void);
49 int list_switch (CT
, int, int, int, int);
50 int list_content (CT
, int, int, int, int);
55 void show_all_messages (CT
*);
56 int show_content_aux (CT
, int, int, char *, char *);
61 static void show_single_message (CT
, char *);
62 static void DisplayMsgHeader (CT
, char *);
63 static int show_switch (CT
, int, int);
64 static int show_content (CT
, int, int);
65 static int show_content_aux2 (CT
, int, int, char *, char *, int, int, int, int, int);
66 static int show_text (CT
, int, int);
67 static int show_multi (CT
, int, int);
68 static int show_multi_internal (CT
, int, int);
69 static int show_multi_aux (CT
, int, int, char *);
70 static int show_message_rfc822 (CT
, int, int);
71 static int show_partial (CT
, int, int);
72 static int show_external (CT
, int, int);
73 static int convert_content_charset (CT
, char **);
74 static void intrser (int);
78 * Top level entry point to show/display a group of messages
82 show_all_messages (CT
*cts
)
87 * If form is not specified, then get default form
88 * for showing headers of MIME messages.
91 formsw
= getcpy (etcpath ("mhl.headers"));
94 * If form is "mhl.null", suppress display of header.
96 if (!strcmp (formsw
, "mhl.null"))
99 for (ctp
= cts
; *ctp
; ctp
++) {
102 /* if top-level type is ok, then display message */
104 show_single_message (ct
, formsw
);
110 * Entry point to show/display a single message
114 show_single_message (CT ct
, char *form
)
120 /* Allow user executable bit so that temporary directories created by
121 * the viewer (e.g., lynx) are going to be accessible */
122 umask (ct
->c_umask
& ~(0100));
125 * If you have a format file, then display
126 * the message headers.
129 DisplayMsgHeader(ct
, form
);
133 /* Show the body of the message */
134 show_switch (ct
, 1, 0);
140 if (ct
->c_ceclosefnx
)
141 (*ct
->c_ceclosefnx
) (ct
);
143 /* block a few signals */
145 sigaddset (&set
, SIGHUP
);
146 sigaddset (&set
, SIGINT
);
147 sigaddset (&set
, SIGQUIT
);
148 sigaddset (&set
, SIGTERM
);
149 sigprocmask (SIG_BLOCK
, &set
, &oset
);
151 while (wait (&status
) != NOTOK
) {
156 /* reset the signal mask */
157 sigprocmask (SIG_SETMASK
, &oset
, &set
);
165 * Use the mhlproc to show the header fields
169 DisplayMsgHeader (CT ct
, char *form
)
176 vec
= argsplit(mhlproc
, &file
, &vecp
);
177 vec
[vecp
++] = getcpy("-form");
178 vec
[vecp
++] = getcpy(form
);
179 vec
[vecp
++] = getcpy("-nobody");
180 vec
[vecp
++] = getcpy(ct
->c_file
);
183 * If we've specified -(no)moreproc,
184 * then just pass that along.
187 vec
[vecp
++] = getcpy("-nomoreproc");
189 vec
[vecp
++] = getcpy("-moreproc");
190 vec
[vecp
++] = getcpy(progsw
);
196 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
201 adios ("fork", "unable to");
206 fprintf (stderr
, "unable to exec ");
216 arglist_free(file
, vec
);
221 * Switching routine. Call the correct routine
222 * based on content type.
226 show_switch (CT ct
, int serial
, int alternate
)
228 switch (ct
->c_type
) {
230 return show_multi (ct
, serial
, alternate
);
233 switch (ct
->c_subtype
) {
234 case MESSAGE_PARTIAL
:
235 return show_partial (ct
, serial
, alternate
);
237 case MESSAGE_EXTERNAL
:
238 return show_external (ct
, serial
, alternate
);
242 return show_message_rfc822 (ct
, serial
, alternate
);
246 return show_text (ct
, serial
, alternate
);
252 return show_content (ct
, serial
, alternate
);
255 adios (NULL
, "unknown content type %d", ct
->c_type
);
258 return 0; /* NOT REACHED */
263 * Generic method for displaying content
267 show_content (CT ct
, int serial
, int alternate
)
269 char *cp
, buffer
[BUFSIZ
];
270 CI ci
= &ct
->c_ctinfo
;
272 /* Check for invo_name-show-type/subtype */
273 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
274 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
275 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
276 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
278 /* Check for invo_name-show-type */
279 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
280 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
281 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
283 if ((cp
= ct
->c_showproc
))
284 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
286 /* complain if we are not a part of a multipart/alternative */
288 content_error (NULL
, ct
, "don't know how to display content");
295 * Parse the display string for displaying generic content
299 show_content_aux (CT ct
, int serial
, int alternate
, char *cp
, char *cracked
)
301 int fd
, len
, buflen
, quoted
;
302 int xstdin
, xlist
, xpause
, xtty
;
303 char *bp
, *pp
, *file
, buffer
[BUFSIZ
];
304 CI ci
= &ct
->c_ctinfo
;
306 if (!ct
->c_ceopenfnx
) {
308 content_error (NULL
, ct
, "don't know how to decode content");
314 if ((fd
= (*ct
->c_ceopenfnx
) (ct
, &file
)) == NOTOK
)
316 if (ct
->c_showproc
&& !strcmp (ct
->c_showproc
, "true"))
317 return (alternate
? DONE
: OK
);
319 if (! strcmp(invo_name
, "mhshow") &&
320 ct
->c_type
== CT_TEXT
&& ct
->c_subtype
== TEXT_PLAIN
) {
321 /* This has to be done after calling c_ceopenfnx, so
322 unfortunately the type checks are necessary without
323 some code rearrangement. And to make this really ugly,
324 only do it in mhshow, not mhfixmsg, mhn, or mhstore. */
325 if (convert_content_charset (ct
, &file
) != OK
) {
336 strncpy (buffer
, cp
, sizeof(buffer
));
340 /* get buffer ready to go */
342 buflen
= sizeof(buffer
) - 1;
343 bp
[0] = bp
[buflen
] = '\0';
346 /* Now parse display string */
347 for ( ; *cp
&& buflen
> 0; cp
++) {
353 /* insert parameters from Content-Type field */
358 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++) {
359 snprintf (bp
, buflen
, "%s%s=\"%s\"", s
, *ap
, *ep
);
369 /* insert content description */
373 s
= trimcpy (ct
->c_descr
);
374 strncpy (bp
, s
, buflen
);
380 /* exclusive execution */
385 /* %e, %f, and stdin is terminal not content */
391 /* insert filename containing content */
392 snprintf (bp
, buflen
, "'%s'", file
);
393 /* since we've quoted the file argument, set things up
394 * to look past it, to avoid problems with the quoting
395 * logic below. (I know, I should figure out what's
396 * broken with the quoting logic, but..)
405 /* %l, and pause prior to displaying content */
410 /* display listing prior to displaying content */
415 /* insert subtype of content */
416 strncpy (bp
, ci
->ci_subtype
, buflen
);
420 /* insert character % */
433 /* Did we actually insert something? */
435 /* Insert single quote if not inside quotes already */
436 if (!quoted
&& buflen
) {
438 memmove (pp
+ 1, pp
, len
);
443 /* Escape existing quotes */
444 while ((pp
= strchr (pp
, '\'')) && buflen
> 3) {
446 memmove (pp
+ 3, pp
, len
);
453 /* If pp is still set, that means we ran out of space. */
456 if (!quoted
&& buflen
) {
474 (ct
->c_termproc
&& (size_t) buflen
<= strlen(ct
->c_termproc
))) {
475 /* content_error would provide a more useful error message
476 * here, except that if we got overrun, it probably would
479 fprintf(stderr
, "Buffer overflow constructing show command!\n");
483 /* use charset string to modify display method */
484 if (ct
->c_termproc
) {
487 strncpy (term
, buffer
, sizeof(term
));
488 snprintf (buffer
, sizeof(buffer
), ct
->c_termproc
, term
);
492 return show_content_aux2 (ct
, serial
, alternate
, cracked
, buffer
,
493 fd
, xlist
, xpause
, xstdin
, xtty
);
498 * Routine to actually display the content
502 show_content_aux2 (CT ct
, int serial
, int alternate
, char *cracked
, char *buffer
,
503 int fd
, int xlist
, int xpause
, int xstdin
, int xtty
)
507 char *vec
[4], exec
[BUFSIZ
+ sizeof "exec "];
509 if (debugsw
|| cracked
) {
512 fprintf (stderr
, "%s msg %s", cracked
? "storing" : "show",
515 fprintf (stderr
, " part %s", ct
->c_partno
);
517 fprintf (stderr
, " using command (cd %s; %s)\n", cracked
, buffer
);
519 fprintf (stderr
, " using command %s\n", buffer
);
522 if (xpid
< 0 || (xtty
&& xpid
)) {
525 pidcheck(pidwait (xpid
, NOTOK
));
532 if (ct
->c_type
== CT_MULTIPART
)
533 list_content (ct
, -1, 1, 0, 0);
535 list_switch (ct
, -1, 1, 0, 0);
537 if (xpause
&& isatty (fileno (stdout
))) {
539 SIGNAL_HANDLER istat
;
541 if (SOprintf ("Press <return> to show content..."))
542 printf ("Press <return> to show content...");
544 istat
= SIGNAL (SIGINT
, intrser
);
545 if ((intr
= sigsetjmp (intrenv
, 1)) == OK
) {
548 read (fileno (stdout
), prompt
, sizeof(prompt
));
550 SIGNAL (SIGINT
, istat
);
551 if (intr
!= OK
|| prompt
[0] == 'n') {
552 (*ct
->c_ceclosefnx
) (ct
);
553 return (alternate
? DONE
: NOTOK
);
555 if (prompt
[0] == 'q') done(OK
);
559 snprintf (exec
, sizeof(exec
), "exec %s", buffer
);
568 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
572 advise ("fork", "unable to");
573 (*ct
->c_ceclosefnx
) (ct
);
582 execvp ("/bin/sh", vec
);
583 fprintf (stderr
, "unable to exec ");
590 ct
->c_pid
= child_id
;
594 pidcheck (pidXwait (child_id
, NULL
));
598 (*ct
->c_ceclosefnx
) (ct
);
599 return (alternate
? DONE
: OK
);
605 * show content of type "text"
609 show_text (CT ct
, int serial
, int alternate
)
611 char *cp
, buffer
[BUFSIZ
];
612 CI ci
= &ct
->c_ctinfo
;
614 /* Check for invo_name-show-type/subtype */
615 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
616 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
617 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
618 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
620 /* Check for invo_name-show-type */
621 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
622 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
623 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
626 * Use default method if content is text/plain, or if
627 * if it is not a text part of a multipart/alternative
629 if (!alternate
|| ct
->c_subtype
== TEXT_PLAIN
) {
630 snprintf (buffer
, sizeof(buffer
), "%%p%s '%%F'", progsw
? progsw
:
631 moreproc
&& *moreproc
? moreproc
: DEFAULT_PAGER
);
632 cp
= (ct
->c_showproc
= add (buffer
, NULL
));
633 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
641 * show message body of type "multipart"
645 show_multi (CT ct
, int serial
, int alternate
)
647 char *cp
, buffer
[BUFSIZ
];
648 CI ci
= &ct
->c_ctinfo
;
650 /* Check for invo_name-show-type/subtype */
651 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
652 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
653 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
654 return show_multi_aux (ct
, serial
, alternate
, cp
);
656 /* Check for invo_name-show-type */
657 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
658 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
659 return show_multi_aux (ct
, serial
, alternate
, cp
);
661 if ((cp
= ct
->c_showproc
))
662 return show_multi_aux (ct
, serial
, alternate
, cp
);
665 * Use default method to display this multipart content. Even
666 * unknown types are displayable, since they're treated as mixed
669 return show_multi_internal (ct
, serial
, alternate
);
674 * show message body of subtypes of multipart that
675 * we understand directly (mixed, alternate, etc...)
679 show_multi_internal (CT ct
, int serial
, int alternate
)
681 int alternating
, nowalternate
, nowserial
, result
;
682 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
688 nowalternate
= alternate
;
690 if (ct
->c_subtype
== MULTI_PARALLEL
) {
691 nowserial
= serialsw
;
692 } else if (ct
->c_subtype
== MULTI_ALTERNATE
) {
700 * unknown subtypes of multipart (treat as mixed per rfc2046)
705 /* block a few signals */
708 sigaddset (&set
, SIGHUP
);
709 sigaddset (&set
, SIGINT
);
710 sigaddset (&set
, SIGQUIT
);
711 sigaddset (&set
, SIGTERM
);
712 sigprocmask (SIG_BLOCK
, &set
, &oset
);
716 * alternate -> we are a part inside an multipart/alternative
717 * alternating -> we are a multipart/alternative
720 result
= alternate
? NOTOK
: OK
;
722 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
725 if (part_ok (p
, 1) && type_ok (p
, 1)) {
728 inneresult
= show_switch (p
, nowserial
, nowalternate
);
729 switch (inneresult
) {
731 if (alternate
&& !alternating
) {
744 alternate
= nowalternate
= 0;
754 if (alternating
&& !part
) {
756 content_error (NULL
, ct
, "don't know how to display any of the contents");
761 if (serial
&& !nowserial
) {
767 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
771 if (kill (p
->c_pid
, 0) == NOTOK
)
778 while (kids
> 0 && (pid
= wait (&status
)) != NOTOK
) {
781 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
786 if (p
->c_pid
== pid
) {
797 /* reset the signal mask */
798 sigprocmask (SIG_SETMASK
, &oset
, &set
);
806 * Parse display string for multipart content
807 * and use external program to display it.
811 show_multi_aux (CT ct
, int serial
, int alternate
, char *cp
)
813 int len
, buflen
, quoted
;
814 int xlist
, xpause
, xtty
;
815 char *bp
, *pp
, *file
, buffer
[BUFSIZ
];
816 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
818 CI ci
= &ct
->c_ctinfo
;
821 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
824 if (!p
->c_ceopenfnx
) {
826 content_error (NULL
, p
, "don't know how to decode content");
830 if (p
->c_storage
== NULL
) {
832 if ((*p
->c_ceopenfnx
) (p
, &file
) == NOTOK
)
835 /* I'm not sure if this is necessary? */
836 p
->c_storage
= add (file
, NULL
);
838 if (p
->c_showproc
&& !strcmp (p
->c_showproc
, "true"))
839 return (alternate
? DONE
: OK
);
840 (*p
->c_ceclosefnx
) (p
);
848 /* get buffer ready to go */
850 buflen
= sizeof(buffer
) - 1;
851 bp
[0] = bp
[buflen
] = '\0';
854 /* Now parse display string */
855 for ( ; *cp
&& buflen
> 0; cp
++) {
860 /* insert parameters from Content-Type field */
865 for (ap
= ci
->ci_attrs
, ep
= ci
->ci_values
; *ap
; ap
++, ep
++) {
866 snprintf (bp
, buflen
, "%s%s=\"%s\"", s
, *ap
, *ep
);
876 /* insert content description */
880 s
= trimcpy (ct
->c_descr
);
881 strncpy (bp
, s
, buflen
);
887 /* exclusive execution */
897 /* insert filename(s) containing content */
901 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
904 snprintf (bp
, buflen
, "%s'%s'", s
, p
->c_storage
);
910 /* set our starting pointer back to bp, to avoid
911 * requoting the filenames we just added
918 /* %l, and pause prior to displaying content */
923 /* display listing prior to displaying content */
928 /* insert subtype of content */
929 strncpy (bp
, ci
->ci_subtype
, buflen
);
933 /* insert character % */
946 /* Did we actually insert something? */
948 /* Insert single quote if not inside quotes already */
949 if (!quoted
&& buflen
) {
951 memmove (pp
+ 1, pp
, len
);
956 /* Escape existing quotes */
957 while ((pp
= strchr (pp
, '\'')) && buflen
> 3) {
959 memmove (pp
+ 3, pp
, len
);
966 /* If pp is still set, that means we ran out of space. */
969 if (!quoted
&& buflen
) {
987 (ct
->c_termproc
&& buflen
<= (ssize_t
) strlen(ct
->c_termproc
))) {
988 /* content_error would provide a more useful error message
989 * here, except that if we got overrun, it probably would
992 fprintf(stderr
, "Buffer overflow constructing show command!\n");
996 /* use charset string to modify display method */
997 if (ct
->c_termproc
) {
1000 strncpy (term
, buffer
, sizeof(term
));
1001 snprintf (buffer
, sizeof(buffer
), ct
->c_termproc
, term
);
1004 return show_content_aux2 (ct
, serial
, alternate
, NULL
, buffer
,
1005 NOTOK
, xlist
, xpause
, 0, xtty
);
1010 * show content of type "message/rfc822"
1014 show_message_rfc822 (CT ct
, int serial
, int alternate
)
1016 char *cp
, buffer
[BUFSIZ
];
1017 CI ci
= &ct
->c_ctinfo
;
1019 /* Check for invo_name-show-type/subtype */
1020 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
1021 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
1022 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
1023 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
1025 /* Check for invo_name-show-type */
1026 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
1027 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
1028 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
1030 if ((cp
= ct
->c_showproc
))
1031 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
1033 /* default method for message/rfc822 */
1034 if (ct
->c_subtype
== MESSAGE_RFC822
) {
1035 cp
= (ct
->c_showproc
= add ("%pshow -file '%F'", NULL
));
1036 return show_content_aux (ct
, serial
, alternate
, cp
, NULL
);
1039 /* complain if we are not a part of a multipart/alternative */
1041 content_error (NULL
, ct
, "don't know how to display content");
1048 * Show content of type "message/partial".
1052 show_partial (CT ct
, int serial
, int alternate
)
1054 NMH_UNUSED (serial
);
1055 NMH_UNUSED (alternate
);
1057 content_error (NULL
, ct
,
1058 "in order to display this message, you must reassemble it");
1064 * Show content of type "message/external".
1066 * THE ERROR CHECKING IN THIS ONE IS NOT DONE YET.
1070 show_external (CT ct
, int serial
, int alternate
)
1072 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
1073 CT p
= e
->eb_content
;
1075 if (!type_ok (p
, 0))
1078 return show_switch (p
, serial
, alternate
);
1083 convert_charset (CT ct
, char *dest_charset
, int *message_mods
) {
1084 char *src_charset
= content_charset (ct
);
1087 /* norm_charmap() is case sensitive. */
1088 char *src_charset_u
= upcase (src_charset
);
1089 char *dest_charset_u
= upcase (dest_charset
);
1090 int different_charsets
=
1091 strcmp (norm_charmap (src_charset
), norm_charmap (dest_charset
));
1093 free (dest_charset_u
);
1094 free (src_charset_u
);
1096 if (different_charsets
) {
1098 iconv_t conv_desc
= NULL
;
1105 int opened_input_file
= 0;
1106 char src_buffer
[BUFSIZ
];
1110 if ((conv_desc
= iconv_open (dest_charset
, src_charset
)) ==
1112 advise (NULL
, "Can't convert %s to %s", src_charset
, dest_charset
);
1116 if ((tempfile
= m_mktemp2 (NULL
, invo_name
, &fd
, NULL
)) == NULL
) {
1117 adios (NULL
, "unable to create temporary file in %s",
1120 dest
= add (tempfile
, NULL
);
1122 if (ct
->c_cefile
.ce_file
) {
1123 file
= &ct
->c_cefile
.ce_file
;
1124 fp
= &ct
->c_cefile
.ce_fp
;
1126 } else if (ct
->c_file
) {
1129 begin
= (size_t) ct
->c_begin
;
1130 end
= (size_t) ct
->c_end
;
1131 } /* else no input file: shouldn't happen */
1133 if (file
&& *file
&& fp
) {
1135 if ((*fp
= fopen (*file
, "r")) == NULL
) {
1136 advise (*file
, "unable to open for reading");
1139 opened_input_file
= 1;
1146 size_t bytes_to_read
=
1147 end
> 0 && end
> begin
? end
- begin
: sizeof src_buffer
;
1149 fseeko (*fp
, begin
, SEEK_SET
);
1150 while ((inbytes
= fread (src_buffer
, 1,
1151 min (bytes_to_read
, sizeof src_buffer
),
1153 char dest_buffer
[BUFSIZ
];
1154 ICONV_CONST
char *ib
= src_buffer
;
1155 char *ob
= dest_buffer
;
1156 size_t outbytes
= sizeof dest_buffer
;
1157 size_t outbytes_before
= outbytes
;
1159 if (end
> 0) bytes_to_read
-= inbytes
;
1161 if (iconv (conv_desc
, &ib
, &inbytes
, &ob
, &outbytes
) ==
1166 write (fd
, dest_buffer
, outbytes_before
- outbytes
);
1170 if (opened_input_file
) {
1176 iconv_close (conv_desc
);
1180 /* Replace the decoded file with the converted one. */
1181 if (ct
->c_cefile
.ce_file
) {
1182 if (ct
->c_cefile
.ce_unlink
) {
1183 (void) m_unlink (ct
->c_cefile
.ce_file
);
1185 free (ct
->c_cefile
.ce_file
);
1187 ct
->c_cefile
.ce_file
= dest
;
1188 ct
->c_cefile
.ce_unlink
= 1;
1192 /* Update ci_attrs. */
1193 src_charset
= dest_charset
;
1195 /* Update ct->c_ctline. */
1198 update_attr (ct
->c_ctline
, "charset=", dest_charset
);
1200 free (ct
->c_ctline
);
1201 ct
->c_ctline
= ctline
;
1202 } /* else no CT line, which is odd */
1204 /* Update Content-Type header field. */
1205 for (hf
= ct
->c_first_hf
; hf
; hf
= hf
->next
) {
1206 if (! strcasecmp (TYPE_FIELD
, hf
->name
)) {
1207 char *ctline_less_newline
=
1208 update_attr (hf
->value
, "charset=", dest_charset
);
1209 char *ctline
= concat (ctline_less_newline
, "\n", NULL
);
1210 free (ctline_less_newline
);
1218 (void) m_unlink (dest
);
1220 #else /* ! HAVE_ICONV */
1221 NMH_UNUSED (message_mods
);
1223 advise (NULL
, "Can't convert %s to %s without iconv", src_charset
,
1226 #endif /* ! HAVE_ICONV */
1234 convert_content_charset (CT ct
, char **file
) {
1235 /* Convert character set if needed and if built with iconv. */
1237 if (display_charset
== NULL
) {
1238 /* The user did not specify a display charset, so use
1239 current setting and see if the content will need to be
1241 char *charset
= content_charset (ct
);
1243 if (! check_charset (charset
, strlen (charset
))) {
1245 if (convert_charset (ct
, get_charset (), &unused
) == 0) {
1246 *file
= ct
->c_cefile
.ce_file
;
1252 /* The user requested display with a specific charset. */
1254 if (convert_charset (ct
, display_charset
, &unused
) == 0) {
1255 *file
= ct
->c_cefile
.ce_file
;
1260 #endif /* ! HAVE_ICONV */
1272 siglongjmp (intrenv
, DONE
);