]>
diplodocus.org Git - nmh/blob - uip/mhshowsbr.c
84c79f46492589a26978d7ea34b635088e444180
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 concat
, 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
, concat
, textonly
, inlineonly
, fmt
);
133 * Entry point to show/display a single message
137 show_single_message (CT ct
, char *form
, int concat
, int textonly
,
138 int inlineonly
, struct format
*fmt
)
144 /* Allow user executable bit so that temporary directories created by
145 * the viewer (e.g., lynx) are going to be accessible */
146 umask (ct
->c_umask
& ~(0100));
149 * If you have a format file, then display
150 * the message headers.
153 DisplayMsgHeader(ct
, form
, concat
);
155 /* Show the body of the message */
156 show_switch (ct
, 0, concat
, textonly
, inlineonly
, fmt
);
162 if (ct
->c_ceclosefnx
)
163 (*ct
->c_ceclosefnx
) (ct
);
165 /* block a few signals */
167 sigaddset (&set
, SIGHUP
);
168 sigaddset (&set
, SIGINT
);
169 sigaddset (&set
, SIGQUIT
);
170 sigaddset (&set
, SIGTERM
);
171 sigprocmask (SIG_BLOCK
, &set
, &oset
);
173 while (!concat
&& wait (&status
) != NOTOK
) {
178 /* reset the signal mask */
179 sigprocmask (SIG_SETMASK
, &oset
, &set
);
186 * Use the mhlproc to show the header fields
190 DisplayMsgHeader (CT ct
, char *form
, int concat
)
197 vec
= argsplit(mhlproc
, &file
, &vecp
);
198 vec
[vecp
++] = getcpy("-form");
199 vec
[vecp
++] = getcpy(form
);
200 vec
[vecp
++] = getcpy("-nobody");
201 vec
[vecp
++] = getcpy(ct
->c_file
);
204 * If we've specified -(no)moreproc,
205 * then just pass that along.
207 if (nomore
|| concat
) {
208 vec
[vecp
++] = getcpy("-nomoreproc");
210 vec
[vecp
++] = getcpy("-moreproc");
211 vec
[vecp
++] = getcpy(progsw
);
217 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
222 adios ("fork", "unable to");
227 fprintf (stderr
, "unable to exec ");
233 pidcheck(pidwait(child_id
, NOTOK
));
237 arglist_free(file
, vec
);
242 * Switching routine. Call the correct routine
243 * based on content type.
247 show_switch (CT ct
, int alternate
, int concat
, int textonly
, int inlineonly
,
250 switch (ct
->c_type
) {
252 return show_multi (ct
, alternate
, concat
, textonly
,
256 switch (ct
->c_subtype
) {
257 case MESSAGE_PARTIAL
:
258 return show_partial (ct
, alternate
);
260 case MESSAGE_EXTERNAL
:
261 return show_external (ct
, alternate
, concat
, textonly
,
266 return show_message_rfc822 (ct
, alternate
);
270 return show_text (ct
, alternate
, concat
);
276 return show_content (ct
, alternate
, textonly
, inlineonly
, fmt
);
279 adios (NULL
, "unknown content type %d", ct
->c_type
);
282 return 0; /* NOT REACHED */
287 * Generic method for displaying content
291 show_content (CT ct
, int alternate
, int textonly
, int inlineonly
,
294 char *cp
, buffer
[BUFSIZ
];
295 CI ci
= &ct
->c_ctinfo
;
298 * If we're here, we are not a text type. So we don't need to check
302 if (textonly
|| (inlineonly
&& is_inline(ct
))) {
303 output_marker(ct
, fmt
);
307 /* Check for invo_name-show-type/subtype */
308 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
309 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
310 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
311 return show_content_aux (ct
, alternate
, cp
, NULL
);
313 /* Check for invo_name-show-type */
314 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
315 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
316 return show_content_aux (ct
, alternate
, cp
, NULL
);
318 if ((cp
= ct
->c_showproc
))
319 return show_content_aux (ct
, alternate
, cp
, NULL
);
321 /* complain if we are not a part of a multipart/alternative */
323 content_error (NULL
, ct
, "don't know how to display content");
330 * Parse the display string for displaying generic content
334 show_content_aux (CT ct
, int alternate
, char *cp
, char *cracked
)
337 int xstdin
= 0, xlist
= 0;
338 char *file
, buffer
[BUFSIZ
];
340 if (!ct
->c_ceopenfnx
) {
342 content_error (NULL
, ct
, "don't know how to decode content");
348 if ((fd
= (*ct
->c_ceopenfnx
) (ct
, &file
)) == NOTOK
)
350 if (ct
->c_showproc
&& !strcmp (ct
->c_showproc
, "true"))
351 return (alternate
? DONE
: OK
);
353 if (! strcmp(invo_name
, "mhshow") &&
354 ct
->c_type
== CT_TEXT
&& ct
->c_subtype
== TEXT_PLAIN
) {
355 /* This has to be done after calling c_ceopenfnx, so
356 unfortunately the type checks are necessary without
357 some code rearrangement. And to make this really ugly,
358 only do it in mhshow, not mhfixmsg, mhn, or mhstore. */
359 if (convert_content_charset (ct
, &file
) == OK
) {
361 if ((fd
= (*ct
->c_ceopenfnx
) (ct
, &file
)) == NOTOK
)
364 admonish (NULL
, "unable to convert character set%s to %s",
365 ct
->c_partno
? "of part " : "",
366 ct
->c_partno
? ct
->c_partno
: "",
367 content_charset (ct
));
372 strncpy (buffer
, cp
, sizeof(buffer
));
376 if (parse_display_string (ct
, cp
, &xstdin
, &xlist
, file
, buffer
,
377 sizeof(buffer
) - 1, 0)) {
378 admonish (NULL
, "Buffer overflow constructing show command!\n");
383 return show_content_aux2 (ct
, alternate
, cracked
, buffer
,
389 * Routine to actually display the content
393 show_content_aux2 (CT ct
, int alternate
, char *cracked
, char *buffer
,
394 int fd
, int xlist
, int xstdin
)
400 if (debugsw
|| cracked
) {
403 fprintf (stderr
, "%s msg %s", cracked
? "storing" : "show",
406 fprintf (stderr
, " part %s", ct
->c_partno
);
408 fprintf (stderr
, " using command (cd %s; %s)\n", cracked
, buffer
);
410 fprintf (stderr
, " using command %s\n", buffer
);
414 if (ct
->c_type
== CT_MULTIPART
)
415 list_content (ct
, -1, 1, 0, 0, 0);
417 list_switch (ct
, -1, 1, 0, 0, 0);
421 * If the command is a zero-length string, just write the output on
425 if (buffer
[0] == '\0') {
426 char readbuf
[BUFSIZ
];
430 advise(NULL
, "Cannot use NULL command to display content-type "
431 "%s/%s", ct
->c_ctinfo
.ci_type
, ct
->c_ctinfo
.ci_subtype
);
435 while ((cc
= read(fd
, readbuf
, sizeof(readbuf
))) > 0) {
436 fwrite(readbuf
, sizeof(char), cc
, stdout
);
440 advise("read", "while reading text content");
447 vec
= argsplit(buffer
, &file
, &vecp
);
452 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
456 advise ("fork", "unable to");
457 (*ct
->c_ceclosefnx
) (ct
);
467 fprintf (stderr
, "unable to exec ");
473 arglist_free(file
, vec
);
475 pidcheck (pidXwait (child_id
, NULL
));
478 (*ct
->c_ceclosefnx
) (ct
);
479 return (alternate
? DONE
: OK
);
485 * show content of type "text"
489 show_text (CT ct
, int alternate
, int concat
)
491 char *cp
, buffer
[BUFSIZ
];
492 CI ci
= &ct
->c_ctinfo
;
494 /* Check for invo_name-show-type/subtype */
495 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
496 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
497 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
498 return show_content_aux (ct
, alternate
, cp
, NULL
);
500 /* Check for invo_name-show-type */
501 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
502 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
503 return show_content_aux (ct
, alternate
, cp
, NULL
);
506 * Use default method if content is text/plain, or if
507 * if it is not a text part of a multipart/alternative
509 if (!alternate
|| ct
->c_subtype
== TEXT_PLAIN
) {
511 snprintf(buffer
, sizeof(buffer
), "%%l");
513 snprintf (buffer
, sizeof(buffer
), "%%l%s %%F", progsw
? progsw
:
514 moreproc
&& *moreproc
? moreproc
: DEFAULT_PAGER
);
515 cp
= (ct
->c_showproc
= add (buffer
, NULL
));
516 return show_content_aux (ct
, alternate
, cp
, NULL
);
524 * show message body of type "multipart"
528 show_multi (CT ct
, int alternate
, int concat
, int textonly
, int inlineonly
,
531 char *cp
, buffer
[BUFSIZ
];
532 CI ci
= &ct
->c_ctinfo
;
534 /* Check for invo_name-show-type/subtype */
535 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
536 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
537 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
538 return show_multi_aux (ct
, alternate
, cp
);
540 /* Check for invo_name-show-type */
541 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
542 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
543 return show_multi_aux (ct
, alternate
, cp
);
545 if ((cp
= ct
->c_showproc
))
546 return show_multi_aux (ct
, alternate
, cp
);
549 * Use default method to display this multipart content. Even
550 * unknown types are displayable, since they're treated as mixed
553 return show_multi_internal (ct
, alternate
, concat
, textonly
,
559 * show message body of subtypes of multipart that
560 * we understand directly (mixed, alternate, etc...)
564 show_multi_internal (CT ct
, int alternate
, int concat
, int textonly
,
565 int inlineonly
, struct format
*fmt
)
567 int alternating
, nowalternate
, result
;
568 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
573 nowalternate
= alternate
;
575 if (ct
->c_subtype
== MULTI_ALTERNATE
) {
581 * alternate -> we are a part inside an multipart/alternative
582 * alternating -> we are a multipart/alternative
585 result
= alternate
? NOTOK
: OK
;
587 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
590 if (part_ok (p
, 1) && type_ok (p
, 1)) {
593 inneresult
= show_switch (p
, nowalternate
, concat
, textonly
,
595 switch (inneresult
) {
597 if (alternate
&& !alternating
) {
610 alternate
= nowalternate
= 0;
620 if (alternating
&& !part
) {
622 content_error (NULL
, ct
, "don't know how to display any of the contents");
633 * Parse display string for multipart content
634 * and use external program to display it.
638 show_multi_aux (CT ct
, int alternate
, char *cp
)
640 /* xstdin is only used in the call to parse_display_string():
641 its value is ignored in the function. */
642 int xstdin
= 0, xlist
= 0;
643 char *file
, buffer
[BUFSIZ
];
644 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
648 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
651 if (!p
->c_ceopenfnx
) {
653 content_error (NULL
, p
, "don't know how to decode content");
657 if (p
->c_storage
== NULL
) {
659 if ((*p
->c_ceopenfnx
) (p
, &file
) == NOTOK
)
662 p
->c_storage
= add (file
, NULL
);
664 if (p
->c_showproc
&& !strcmp (p
->c_showproc
, "true"))
665 return (alternate
? DONE
: OK
);
666 (*p
->c_ceclosefnx
) (p
);
670 if (parse_display_string (ct
, cp
, &xstdin
, &xlist
, file
,
671 buffer
, sizeof(buffer
) - 1, 1)) {
672 admonish (NULL
, "Buffer overflow constructing show command!\n");
676 return show_content_aux2 (ct
, alternate
, NULL
, buffer
, NOTOK
, xlist
, 0);
681 * show content of type "message/rfc822"
685 show_message_rfc822 (CT ct
, int alternate
)
687 char *cp
, buffer
[BUFSIZ
];
688 CI ci
= &ct
->c_ctinfo
;
690 /* Check for invo_name-show-type/subtype */
691 snprintf (buffer
, sizeof(buffer
), "%s-show-%s/%s",
692 invo_name
, ci
->ci_type
, ci
->ci_subtype
);
693 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
694 return show_content_aux (ct
, alternate
, cp
, NULL
);
696 /* Check for invo_name-show-type */
697 snprintf (buffer
, sizeof(buffer
), "%s-show-%s", invo_name
, ci
->ci_type
);
698 if ((cp
= context_find (buffer
)) && *cp
!= '\0')
699 return show_content_aux (ct
, alternate
, cp
, NULL
);
701 if ((cp
= ct
->c_showproc
))
702 return show_content_aux (ct
, alternate
, cp
, NULL
);
704 /* default method for message/rfc822 */
705 if (ct
->c_subtype
== MESSAGE_RFC822
) {
706 cp
= (ct
->c_showproc
= add ("%pecho -file %F", NULL
));
707 return show_content_aux (ct
, alternate
, cp
, NULL
);
710 /* complain if we are not a part of a multipart/alternative */
712 content_error (NULL
, ct
, "don't know how to display content");
719 * Show content of type "message/partial".
723 show_partial (CT ct
, int alternate
)
725 NMH_UNUSED (alternate
);
727 content_error (NULL
, ct
,
728 "in order to display this message, you must reassemble it");
734 * Show content of type "message/external".
736 * THE ERROR CHECKING IN THIS ONE IS NOT DONE YET.
740 show_external (CT ct
, int alternate
, int concat
, int textonly
, int inlineonly
,
743 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
744 CT p
= e
->eb_content
;
749 return show_switch (p
, alternate
, concat
, textonly
, inlineonly
, fmt
);
754 parse_display_string (CT ct
, char *cp
, int *xstdin
, int *xlist
,
755 char *file
, char *buffer
, size_t buflen
,
758 char *bp
= buffer
, *pp
;
759 CI ci
= &ct
->c_ctinfo
;
761 bp
[0] = bp
[buflen
] = '\0';
763 for ( ; *cp
&& buflen
> 0; cp
++) {
769 /* insert parameters from Content-Type field */
774 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
775 snprintf (bp
, buflen
, "%s%s=\"%s\"", s
, pm
->pm_name
,
776 get_param_value(pm
, '?'));
786 /* insert content description */
790 s
= trimcpy (ct
->c_descr
);
791 strncpy (bp
, s
, buflen
);
797 /* no longer implemented */
801 /* %f, and stdin is terminal not content */
807 /* insert filename(s) containing content */
808 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
813 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
816 snprintf (bp
, buflen
, "%s%s", s
, p
->c_storage
);
823 /* insert filename containing content */
824 snprintf (bp
, buflen
, "%s", file
);
827 * Old comments below are left here for posterity.
828 * This was/is tricky.
830 /* since we've quoted the file argument, set things up
831 * to look past it, to avoid problems with the quoting
832 * logic below. (I know, I should figure out what's
833 * broken with the quoting logic, but..)
836 * Here's the email that submitted the patch with
838 * https://www.mail-archive.com/nmh-workers@mhost.com/
840 * I can't tell from that exactly what was broken,
841 * beyond misquoting of the filename. The profile
842 * had appearances of %F both with and without quotes.
843 * The unquoted ones should have been quoted by the
845 * The fix was to always quote the filename. But
846 * that broke '%F' because it expanded to ''filename''.
849 * Old comments above are left here for posterity.
850 * The quoting below should work properly now.
856 /* No longer supported */
860 /* display listing prior to displaying content */
865 /* insert subtype of content */
866 strncpy (bp
, ci
->ci_subtype
, buflen
);
870 /* insert character % */
874 const char *closing_brace
= strchr(cp
, '}');
877 const size_t param_len
= closing_brace
- cp
- 1;
878 char *param
= mh_xmalloc(param_len
+ 1);
881 (void) strncpy(param
, cp
+ 1, param_len
);
882 param
[param_len
] = '\0';
883 value
= get_param(ci
->ci_first_pm
, param
, '?', 0);
886 cp
+= param_len
+ 1; /* Skip both braces, too. */
889 /* %{param} is set in the Content-Type header.
890 After the break below, quote it if necessary. */
891 (void) strncpy(bp
, value
, buflen
);
894 /* %{param} not found, so skip it completely. cp
895 was advanced above. */
899 /* This will get confused if there are multiple %{}'s,
900 but its real purpose is to avoid doing bad things
901 above if a closing brace wasn't found. */
903 "no closing brace for display string escape %s",
920 /* Did we actually insert something? */
922 /* Insert single quote if not inside quotes already */
923 if (!quoted
&& buflen
) {
925 memmove (pp
+ 1, pp
, len
+1);
931 /* Escape existing quotes */
932 while ((pp
= strchr (pp
, '\'')) && buflen
> 3) {
935 /* Quoted. Let this quote close that quoting.
936 Insert an escaped quote to replace it and
937 another quote to reopen quoting, which will be
939 memmove (pp
+ 2, pp
, len
);
946 /* Not quoted. This should not be reached with
947 the current code, but handle the condition
948 in case the code changes. Just escape the
950 memmove (pp
, pp
-1, len
+1);
956 /* If pp is still set, that means we ran out of space. */
960 if (quoted
&& buflen
) {
961 /* See if we need to close the quote by looking
962 for an odd number of unescaped close quotes in
963 the remainder of the display string. */
964 int found_quote
= 0, escaped
= 0;
967 for (c
= cp
+1; *c
; ++c
) {
975 found_quote
= ! found_quote
;
1000 (ct
->c_termproc
&& buflen
<= strlen(ct
->c_termproc
))) {
1001 /* content_error would provide a more useful error message
1002 * here, except that if we got overrun, it probably would
1008 /* use charset string to modify display method */
1009 if (ct
->c_termproc
) {
1012 strncpy (term
, buffer
, sizeof(term
));
1013 snprintf (buffer
, buflen
, ct
->c_termproc
, term
);
1021 convert_charset (CT ct
, char *dest_charset
, int *message_mods
) {
1022 char *src_charset
= content_charset (ct
);
1025 /* norm_charmap() is case sensitive. */
1026 char *src_charset_u
= upcase (src_charset
);
1027 char *dest_charset_u
= upcase (dest_charset
);
1028 int different_charsets
=
1029 strcmp (norm_charmap (src_charset
), norm_charmap (dest_charset
));
1031 free (dest_charset_u
);
1032 free (src_charset_u
);
1034 if (different_charsets
) {
1036 iconv_t conv_desc
= NULL
;
1043 int opened_input_file
= 0;
1044 char src_buffer
[BUFSIZ
];
1048 if ((conv_desc
= iconv_open (dest_charset
, src_charset
)) ==
1050 advise (NULL
, "Can't convert %s to %s", src_charset
, dest_charset
);
1054 if ((tempfile
= m_mktemp2 (NULL
, invo_name
, &fd
, NULL
)) == NULL
) {
1055 adios (NULL
, "unable to create temporary file in %s",
1058 dest
= add (tempfile
, NULL
);
1060 if (ct
->c_cefile
.ce_file
) {
1061 file
= &ct
->c_cefile
.ce_file
;
1062 fp
= &ct
->c_cefile
.ce_fp
;
1064 } else if (ct
->c_file
) {
1067 begin
= (size_t) ct
->c_begin
;
1068 end
= (size_t) ct
->c_end
;
1069 } /* else no input file: shouldn't happen */
1071 if (file
&& *file
&& fp
) {
1073 if ((*fp
= fopen (*file
, "r")) == NULL
) {
1074 advise (*file
, "unable to open for reading");
1077 opened_input_file
= 1;
1084 size_t bytes_to_read
=
1085 end
> 0 && end
> begin
? end
- begin
: sizeof src_buffer
;
1087 fseeko (*fp
, begin
, SEEK_SET
);
1088 while ((inbytes
= fread (src_buffer
, 1,
1089 min (bytes_to_read
, sizeof src_buffer
),
1091 char dest_buffer
[BUFSIZ
];
1092 ICONV_CONST
char *ib
= src_buffer
;
1093 char *ob
= dest_buffer
;
1094 size_t outbytes
= sizeof dest_buffer
;
1095 size_t outbytes_before
= outbytes
;
1097 if (end
> 0) bytes_to_read
-= inbytes
;
1099 if (iconv (conv_desc
, &ib
, &inbytes
, &ob
, &outbytes
) ==
1104 write (fd
, dest_buffer
, outbytes_before
- outbytes
);
1108 if (opened_input_file
) {
1114 iconv_close (conv_desc
);
1118 /* Replace the decoded file with the converted one. */
1119 if (ct
->c_cefile
.ce_file
) {
1120 if (ct
->c_cefile
.ce_unlink
) {
1121 (void) m_unlink (ct
->c_cefile
.ce_file
);
1123 free (ct
->c_cefile
.ce_file
);
1125 ct
->c_cefile
.ce_file
= dest
;
1126 ct
->c_cefile
.ce_unlink
= 1;
1130 /* Update ct->c_ctline. */
1132 char *ctline
= concat(" ", ct
->c_ctinfo
.ci_type
, "/",
1133 ct
->c_ctinfo
.ci_subtype
, NULL
);
1136 replace_param(&ct
->c_ctinfo
.ci_first_pm
,
1137 &ct
->c_ctinfo
.ci_last_pm
, "charset",
1139 outline
= output_params(strlen(TYPE_FIELD
) + 1 + strlen(ctline
),
1140 ct
->c_ctinfo
.ci_first_pm
, NULL
, 0);
1142 ctline
= add(outline
, ctline
);
1146 free (ct
->c_ctline
);
1147 ct
->c_ctline
= ctline
;
1148 } /* else no CT line, which is odd */
1150 /* Update Content-Type header field. */
1151 for (hf
= ct
->c_first_hf
; hf
; hf
= hf
->next
) {
1152 if (! strcasecmp (TYPE_FIELD
, hf
->name
)) {
1153 char *ctline
= concat (ct
->c_ctline
, "\n", NULL
);
1161 (void) m_unlink (dest
);
1163 #else /* ! HAVE_ICONV */
1164 NMH_UNUSED (message_mods
);
1166 advise (NULL
, "Can't convert %s to %s without iconv", src_charset
,
1169 #endif /* ! HAVE_ICONV */
1177 convert_content_charset (CT ct
, char **file
) {
1179 /* Using current locale, see if the content needs to be converted. */
1181 /* content_charset() cannot return NULL. */
1182 char *charset
= content_charset (ct
);
1184 if (! check_charset (charset
, strlen (charset
))) {
1187 if (convert_charset (ct
, get_charset (), &unused
) == 0) {
1188 *file
= ct
->c_cefile
.ce_file
;
1193 #else /* ! HAVE_ICONV */
1196 #endif /* ! HAVE_ICONV */
1202 * Compile our format string and save any parameters we care about.
1205 #define DEFAULT_MARKER "[ part %{part} - %{content-type} - %<{description}" \
1206 "%{description}%?{cdispo-filename}%{cdispo-filename}" \
1207 "%|%{ctype-name}%> ]"
1209 static struct format
*
1210 compile_marker(char *markerform
)
1214 struct comp
*comp
= NULL
;
1215 unsigned int bucket
;
1216 struct param_comp_list
*pc_entry
;
1218 fmtstring
= new_fs(markerform
, NULL
, DEFAULT_MARKER
);
1220 (void) fmt_compile(fmtstring
, &fmt
, 1);
1224 * Things we care about:
1226 * part - Part name (e.g., 1.1)
1227 * content-type - Content-Type
1228 * description - Content-Description
1229 * disposition - Content-Disposition (inline, attachment)
1230 * ctype-<param> - Content-Type parameter
1231 * cdispo-<param> - Content-Disposition parameter
1234 while ((comp
= fmt_nextcomp(comp
, &bucket
)) != NULL
) {
1235 if (strcasecmp(comp
->c_name
, "part") == 0) {
1237 } else if (strcasecmp(comp
->c_name
, "content-type") == 0) {
1239 } else if (strcasecmp(comp
->c_name
, "description") == 0) {
1240 description_comp
= comp
;
1241 } else if (strcasecmp(comp
->c_name
, "disposition") == 0) {
1243 } else if (strncasecmp(comp
->c_name
, "ctype-", 6) == 0 &&
1244 strlen(comp
->c_name
) > 6) {
1245 pc_entry
= mh_xmalloc(sizeof(*pc_entry
));
1246 pc_entry
->param
= getcpy(comp
->c_name
+ 6);
1247 pc_entry
->comp
= comp
;
1248 pc_entry
->next
= ctype_pc_list
;
1249 ctype_pc_list
= pc_entry
;
1250 } else if (strncasecmp(comp
->c_name
, "cdispo-", 7) == 0 &&
1251 strlen(comp
->c_name
) > 7) {
1252 pc_entry
= mh_xmalloc(sizeof(*pc_entry
));
1253 pc_entry
->param
= getcpy(comp
->c_name
+ 7);
1254 pc_entry
->comp
= comp
;
1255 pc_entry
->next
= dispo_pc_list
;
1256 dispo_pc_list
= pc_entry
;
1264 * Output on stdout an appropriate marker for this content, using mh-format
1268 output_marker(CT ct
, struct format
*fmt
)
1270 char outbuf
[BUFSIZ
];
1271 struct param_comp_list
*pcentry
;
1275 * Grab any items we care about.
1278 if (ctype_comp
&& ct
->c_ctinfo
.ci_type
) {
1279 ctype_comp
->c_text
= concat(ct
->c_ctinfo
.ci_type
, "/",
1280 ct
->c_ctinfo
.ci_subtype
, NULL
);
1283 if (part_comp
&& ct
->c_partno
) {
1284 part_comp
->c_text
= getcpy(ct
->c_partno
);
1287 if (description_comp
&& ct
->c_descr
) {
1288 description_comp
->c_text
= getcpy(ct
->c_descr
);
1291 if (dispo_comp
&& ct
->c_dispo_type
) {
1292 dispo_comp
->c_text
= getcpy(ct
->c_dispo_type
);
1295 for (pcentry
= ctype_pc_list
; pcentry
!= NULL
; pcentry
= pcentry
->next
) {
1296 pcentry
->comp
->c_text
= get_param(ct
->c_ctinfo
.ci_first_pm
,
1297 pcentry
->param
, '?', 0);
1300 for (pcentry
= dispo_pc_list
; pcentry
!= NULL
; pcentry
= pcentry
->next
) {
1301 pcentry
->comp
->c_text
= get_param(ct
->c_dispo_first
,
1302 pcentry
->param
, '?', 0);
1305 fmt_scan(fmt
, outbuf
, sizeof(outbuf
), sizeof(outbuf
), dat
, NULL
);
1307 fputs(outbuf
, stdout
);
1313 * Reset (and free) any of the saved marker text
1317 free_markercomps(void)
1319 struct param_comp_list
*pc_entry
, *pc2
;
1323 description_comp
= NULL
;
1326 for (pc_entry
= ctype_pc_list
; pc_entry
!= NULL
; ) {
1327 free(pc_entry
->param
);
1328 pc2
= pc_entry
->next
;
1333 for (pc_entry
= dispo_pc_list
; pc_entry
!= NULL
; ) {
1334 free(pc_entry
->param
);
1335 pc2
= pc_entry
->next
;
1342 * Exit if the display process returned with a nonzero exit code, or terminated
1343 * with a SIGQUIT signal.
1347 pidcheck (int status
)
1349 if ((status
& 0xff00) == 0xff00 || (status
& 0x007f) != SIGQUIT
)