]>
diplodocus.org Git - nmh/blob - uip/mhshowsbr.c
720ba9bc0fbfaf801722c5aac51925969959ddbe
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 static void show_single_message (CT
, char *, int, int, int, struct format
*);
46 static void DisplayMsgHeader (CT
, char *, int);
47 static int show_switch (CT
, int, int, int, int, struct format
*);
48 static int show_content (CT
, int, int, int, struct format
*);
49 static int show_content_aux2 (CT
, int, char *, char *, int, int, int, struct format
*);
50 static int show_text (CT
, int, int, struct format
*);
51 static int show_multi (CT
, int, int, int, int, struct format
*);
52 static int show_multi_internal (CT
, int, int, int, int, struct format
*);
53 static int show_multi_aux (CT
, int, char *, struct format
*);
54 static int show_message_rfc822 (CT
, int, struct format
*);
55 static int show_partial (CT
, int);
56 static int show_external (CT
, int, int, int, int, struct format
*);
57 static int parse_display_string (CT
, char *, int *, int *, char *, char *,
58 size_t, int multipart
);
59 static int convert_content_charset (CT
, char **);
60 static struct format
*compile_marker(char *);
61 static void output_marker (CT
, struct format
*, int);
62 static void free_markercomps (void);
63 static int pidcheck(int);
66 * Components (and list of parameters/components) we care about for the
67 * content marker display.
70 static struct comp
*part_comp
= NULL
;
71 static struct comp
*ctype_comp
= NULL
;
72 static struct comp
*description_comp
= NULL
;
73 static struct comp
*dispo_comp
= NULL
;
75 struct param_comp_list
{
78 struct param_comp_list
*next
;
81 static struct param_comp_list
*ctype_pc_list
= NULL
;
82 static struct param_comp_list
*dispo_pc_list
= NULL
;
86 * Top level entry point to show/display a group of messages
90 show_all_messages (CT
*cts
, int concatsw
, int textonly
, int inlineonly
,
97 * If form is not specified, then get default form
98 * for showing headers of MIME messages.
101 formsw
= getcpy (etcpath ("mhl.headers"));
104 * Compile the content marker format line
106 fmt
= compile_marker(markerform
);
109 * If form is "mhl.null", suppress display of header.
111 if (!strcmp (formsw
, "mhl.null"))
114 for (ctp
= cts
; *ctp
; ctp
++) {
117 /* if top-level type is ok, then display message */
119 show_single_message (ct
, formsw
, concatsw
, textonly
, inlineonly
,
129 * Entry point to show/display a single message
133 show_single_message (CT ct
, char *form
, int concatsw
, int textonly
,
134 int inlineonly
, struct format
*fmt
)
140 /* Allow user executable bit so that temporary directories created by
141 * the viewer (e.g., lynx) are going to be accessible */
142 umask (ct
->c_umask
& ~(0100));
145 * If you have a format file, then display
146 * the message headers.
149 DisplayMsgHeader(ct
, form
, concatsw
);
151 /* Show the body of the message */
152 show_switch (ct
, 0, concatsw
, textonly
, inlineonly
, fmt
);
158 if (ct
->c_ceclosefnx
)
159 (*ct
->c_ceclosefnx
) (ct
);
161 /* block a few signals */
163 sigaddset (&set
, SIGHUP
);
164 sigaddset (&set
, SIGINT
);
165 sigaddset (&set
, SIGQUIT
);
166 sigaddset (&set
, SIGTERM
);
167 sigprocmask (SIG_BLOCK
, &set
, &oset
);
169 while (!concatsw
&& wait (&status
) != NOTOK
) {
174 /* reset the signal mask */
175 sigprocmask (SIG_SETMASK
, &oset
, &set
);
182 * Use the mhlproc to show the header fields
186 DisplayMsgHeader (CT ct
, char *form
, int concatsw
)
193 vec
= argsplit(mhlproc
, &file
, &vecp
);
194 vec
[vecp
++] = getcpy("-form");
195 vec
[vecp
++] = getcpy(form
);
196 vec
[vecp
++] = getcpy("-nobody");
197 vec
[vecp
++] = getcpy(ct
->c_file
);
200 * If we've specified -(no)moreproc,
201 * then just pass that along.
203 if (nomore
|| concatsw
) {
204 vec
[vecp
++] = getcpy("-nomoreproc");
206 vec
[vecp
++] = getcpy("-moreproc");
207 vec
[vecp
++] = getcpy(progsw
);
213 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
218 adios ("fork", "unable to");
223 fprintf (stderr
, "unable to exec ");
229 pidcheck(pidwait(child_id
, NOTOK
));
233 arglist_free(file
, vec
);
238 * Switching routine. Call the correct routine
239 * based on content type.
243 show_switch (CT ct
, int alternate
, int concatsw
, int textonly
, int inlineonly
,
246 switch (ct
->c_type
) {
248 return show_multi (ct
, alternate
, concatsw
, textonly
,
252 switch (ct
->c_subtype
) {
253 case MESSAGE_PARTIAL
:
254 return show_partial (ct
, alternate
);
256 case MESSAGE_EXTERNAL
:
257 return show_external (ct
, alternate
, concatsw
, textonly
,
261 return show_message_rfc822 (ct
, alternate
, fmt
);
264 * Treat unknown message types as equivalent to
265 * application/octet-stream for now
268 return show_content (ct
, alternate
, textonly
,
273 return show_text (ct
, alternate
, concatsw
, fmt
);
280 return show_content (ct
, alternate
, textonly
, inlineonly
, fmt
);
283 return 0; /* NOT REACHED */
288 * Generic method for displaying content
292 show_content (CT ct
, int alternate
, int textonly
, int inlineonly
,
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
, 1);
308 /* Check for invo_name-show-type[/subtype] */
309 if ((cp
= context_find_by_type ("show", ci
->ci_type
, ci
->ci_subtype
)))
310 return show_content_aux (ct
, alternate
, cp
, NULL
, fmt
);
312 if ((cp
= ct
->c_showproc
))
313 return show_content_aux (ct
, alternate
, cp
, NULL
, fmt
);
315 /* complain if we are not a part of a multipart/alternative */
317 content_error (NULL
, ct
, "don't know how to display content");
324 * Parse the display string for displaying generic content
328 show_content_aux (CT ct
, int alternate
, char *cp
, char *cracked
, struct format
*fmt
)
331 int xstdin
= 0, xlist
= 0;
332 char *file
= NULL
, buffer
[BUFSIZ
];
334 if (!ct
->c_ceopenfnx
) {
336 content_error (NULL
, ct
, "don't know how to decode content");
341 if ((fd
= (*ct
->c_ceopenfnx
) (ct
, &file
)) == NOTOK
)
343 if (ct
->c_showproc
&& !strcmp (ct
->c_showproc
, "true"))
344 return (alternate
? DONE
: OK
);
346 if (! strcmp(invo_name
, "mhshow") &&
347 ct
->c_type
== CT_TEXT
&& ct
->c_subtype
== TEXT_PLAIN
) {
348 /* This has to be done after calling c_ceopenfnx, so
349 unfortunately the type checks are necessary without
350 some code rearrangement. And to make this really ugly,
351 only do it in mhshow, not mhfixmsg, mhn, or mhstore. */
352 if (convert_content_charset (ct
, &file
) == OK
) {
353 (*ct
->c_ceclosefnx
) (ct
);
354 if ((fd
= (*ct
->c_ceopenfnx
) (ct
, &file
)) == NOTOK
)
357 admonish (NULL
, "unable to convert character set%s%s to %s",
358 ct
->c_partno
? " of part " : "",
359 ct
->c_partno
? ct
->c_partno
: "",
360 content_charset (ct
));
365 strncpy (buffer
, cp
, sizeof(buffer
));
369 if (parse_display_string (ct
, cp
, &xstdin
, &xlist
, file
, buffer
,
370 sizeof(buffer
) - 1, 0)) {
371 admonish (NULL
, "Buffer overflow constructing show command!\n");
376 return show_content_aux2 (ct
, alternate
, cracked
, buffer
,
377 fd
, xlist
, xstdin
, fmt
);
382 * Routine to actually display the content
386 show_content_aux2 (CT ct
, int alternate
, char *cracked
, char *buffer
,
387 int fd
, int xlist
, int xstdin
, struct format
*fmt
)
393 if (debugsw
|| cracked
) {
396 fprintf (stderr
, "%s msg %s", cracked
? "storing" : "show",
399 fprintf (stderr
, " part %s", ct
->c_partno
);
401 fprintf (stderr
, " using command (cd %s; %s)\n", cracked
, buffer
);
403 fprintf (stderr
, " using command %s\n", buffer
);
407 output_marker(ct
, fmt
, 0);
411 * If the command is a zero-length string, just write the output on
415 if (buffer
[0] == '\0') {
416 char readbuf
[BUFSIZ
];
418 char lastchar
= '\n';
421 advise(NULL
, "Cannot use NULL command to display content-type "
422 "%s/%s", ct
->c_ctinfo
.ci_type
, ct
->c_ctinfo
.ci_subtype
);
426 while ((cc
= read(fd
, readbuf
, sizeof(readbuf
))) > 0) {
427 fwrite(readbuf
, sizeof(char), cc
, stdout
);
428 lastchar
= readbuf
[cc
- 1];
432 advise("read", "while reading text content");
437 * The MIME standards allow content to not have a trailing newline.
438 * But because we are (presumably) sending this to stdout, include
439 * a newline for text content if the final character was not a
440 * newline. Only do this for mhshow.
443 if (strcmp(invo_name
, "mhshow") == 0 && ct
->c_type
== CT_TEXT
&&
444 ct
->c_subtype
== TEXT_PLAIN
&& lastchar
!= '\n') {
453 vec
= argsplit(buffer
, &file
, &vecp
);
458 for (i
= 0; (child_id
= fork()) == NOTOK
&& i
< 5; i
++)
462 advise ("fork", "unable to");
463 (*ct
->c_ceclosefnx
) (ct
);
468 if (chdir (cracked
) < 0) {
469 advise (cracked
, "chdir");
476 fprintf (stderr
, "unable to exec ");
482 arglist_free(file
, vec
);
484 pidcheck (pidXwait (child_id
, NULL
));
487 (*ct
->c_ceclosefnx
) (ct
);
488 return (alternate
? DONE
: OK
);
494 * show content of type "text"
498 show_text (CT ct
, int alternate
, int concatsw
, struct format
*fmt
)
500 char *cp
, buffer
[BUFSIZ
];
501 CI ci
= &ct
->c_ctinfo
;
503 /* Check for invo_name-show-type[/subtype] */
504 if ((cp
= context_find_by_type ("show", ci
->ci_type
, ci
->ci_subtype
)))
505 return show_content_aux (ct
, alternate
, cp
, NULL
, fmt
);
508 * Use default method if content is text/plain, or if
509 * if it is not a text part of a multipart/alternative
511 if (!alternate
|| ct
->c_subtype
== TEXT_PLAIN
) {
514 snprintf(buffer
, sizeof(buffer
), "%%lcat");
516 snprintf(buffer
, sizeof(buffer
), "%%l");
518 snprintf (buffer
, sizeof(buffer
), "%%l%s %%F", progsw
? progsw
:
519 moreproc
&& *moreproc
? moreproc
: DEFAULT_PAGER
);
520 cp
= (ct
->c_showproc
= add (buffer
, NULL
));
521 return show_content_aux (ct
, alternate
, cp
, NULL
, fmt
);
529 * show message body of type "multipart"
533 show_multi (CT ct
, int alternate
, int concatsw
, int textonly
, int inlineonly
,
537 CI ci
= &ct
->c_ctinfo
;
539 /* Check for invo_name-show-type[/subtype] */
540 if ((cp
= context_find_by_type ("show", ci
->ci_type
, ci
->ci_subtype
)))
541 return show_multi_aux (ct
, alternate
, cp
, fmt
);
543 if ((cp
= ct
->c_showproc
))
544 return show_multi_aux (ct
, alternate
, cp
, fmt
);
547 * Use default method to display this multipart content. Even
548 * unknown types are displayable, since they're treated as mixed
551 return show_multi_internal (ct
, alternate
, concatsw
, textonly
,
557 * show message body of subtypes of multipart that
558 * we understand directly (mixed, alternate, etc...)
562 show_multi_internal (CT ct
, int alternate
, int concatsw
, int textonly
,
563 int inlineonly
, struct format
*fmt
)
565 int alternating
, nowalternate
, result
;
566 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
572 nowalternate
= alternate
;
574 if (ct
->c_subtype
== MULTI_ALTERNATE
) {
580 * alternate -> we are a part inside an multipart/alternative
581 * alternating -> we are a multipart/alternative
584 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)) {
595 inneresult
= show_switch (p
, nowalternate
, concatsw
, textonly
,
597 switch (inneresult
) {
599 if (alternate
&& !alternating
) {
612 alternate
= nowalternate
= 0;
622 if (alternating
&& !part
&& any_part_ok
) {
624 content_error (NULL
, ct
, "don't know how to display any of the contents");
635 * Parse display string for multipart content
636 * and use external program to display it.
640 show_multi_aux (CT ct
, int alternate
, char *cp
, struct format
*fmt
)
642 /* xstdin is only used in the call to parse_display_string():
643 its value is ignored in the function. */
644 int xstdin
= 0, xlist
= 0;
645 char *file
= NULL
, buffer
[BUFSIZ
];
646 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
650 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
653 if (!p
->c_ceopenfnx
) {
655 content_error (NULL
, p
, "don't know how to decode content");
659 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, fmt
);
682 * show content of type "message/rfc822"
686 show_message_rfc822 (CT ct
, int alternate
, struct format
*fmt
)
689 CI ci
= &ct
->c_ctinfo
;
691 /* Check for invo_name-show-type[/subtype] */
692 if ((cp
= context_find_by_type ("show", ci
->ci_type
, ci
->ci_subtype
)))
693 return show_content_aux (ct
, alternate
, cp
, NULL
, fmt
);
695 if ((cp
= ct
->c_showproc
))
696 return show_content_aux (ct
, alternate
, cp
, NULL
, fmt
);
698 /* default method for message/rfc822 */
699 if (ct
->c_subtype
== MESSAGE_RFC822
) {
700 cp
= (ct
->c_showproc
= add ("%pshow -file %F", NULL
));
701 return show_content_aux (ct
, alternate
, cp
, NULL
, fmt
);
704 /* complain if we are not a part of a multipart/alternative */
706 content_error (NULL
, ct
, "don't know how to display content");
713 * Show content of type "message/partial".
717 show_partial (CT ct
, int alternate
)
719 NMH_UNUSED (alternate
);
721 content_error (NULL
, ct
,
722 "in order to display this message, you must reassemble it");
728 * Show content of type "message/external".
730 * THE ERROR CHECKING IN THIS ONE IS NOT DONE YET.
734 show_external (CT ct
, int alternate
, int concatsw
, int textonly
, int inlineonly
,
737 struct exbody
*e
= (struct exbody
*) ct
->c_ctparams
;
738 CT p
= e
->eb_content
;
743 return show_switch (p
, alternate
, concatsw
, textonly
, inlineonly
, fmt
);
748 parse_display_string (CT ct
, char *cp
, int *xstdin
, int *xlist
,
749 char *file
, char *buffer
, size_t buflen
,
752 char *bp
= buffer
, *pp
;
753 CI ci
= &ct
->c_ctinfo
;
755 bp
[0] = bp
[buflen
] = '\0';
757 for ( ; *cp
&& buflen
> 0; cp
++) {
763 /* insert parameters from Content-Type field */
768 for (pm
= ci
->ci_first_pm
; pm
; pm
= pm
->pm_next
) {
769 snprintf (bp
, buflen
, "%s%s=\"%s\"", s
, pm
->pm_name
,
770 get_param_value(pm
, '?'));
780 /* insert content description */
784 s
= trimcpy (ct
->c_descr
);
785 strncpy (bp
, s
, buflen
);
791 /* no longer implemented */
795 /* %f, and stdin is terminal not content */
801 /* insert filename(s) containing content */
802 struct multipart
*m
= (struct multipart
*) ct
->c_ctparams
;
807 for (part
= m
->mp_parts
; part
; part
= part
->mp_next
) {
810 snprintf (bp
, buflen
, "%s%s", s
, p
->c_storage
);
817 /* insert filename containing content */
818 snprintf (bp
, buflen
, "%s", file
);
821 * Old comments below are left here for posterity.
822 * This was/is tricky.
824 /* since we've quoted the file argument, set things up
825 * to look past it, to avoid problems with the quoting
826 * logic below. (I know, I should figure out what's
827 * broken with the quoting logic, but..)
830 * Here's the email that submitted the patch with
832 * https://www.mail-archive.com/nmh-workers@mhost.com/
834 * I can't tell from that exactly what was broken,
835 * beyond misquoting of the filename. The profile
836 * had appearances of %F both with and without quotes.
837 * The unquoted ones should have been quoted by the
839 * The fix was to always quote the filename. But
840 * that broke '%F' because it expanded to ''filename''.
843 * Old comments above are left here for posterity.
844 * The quoting below should work properly now.
850 /* No longer supported */
854 /* display listing prior to displaying content */
859 /* insert subtype of content */
860 strncpy (bp
, ci
->ci_subtype
, buflen
);
864 /* insert character % */
868 const char *closing_brace
= strchr(cp
, '}');
871 const size_t param_len
= closing_brace
- cp
- 1;
872 char *param
= mh_xmalloc(param_len
+ 1);
875 (void) strncpy(param
, cp
+ 1, param_len
);
876 param
[param_len
] = '\0';
877 value
= get_param(ci
->ci_first_pm
, param
, '?', 0);
880 cp
+= param_len
+ 1; /* Skip both braces, too. */
883 /* %{param} is set in the Content-Type header.
884 After the break below, quote it if necessary. */
885 (void) strncpy(bp
, value
, buflen
);
888 /* %{param} not found, so skip it completely. cp
889 was advanced above. */
893 /* This will get confused if there are multiple %{}'s,
894 but its real purpose is to avoid doing bad things
895 above if a closing brace wasn't found. */
897 "no closing brace for display string escape %s",
914 /* Did we actually insert something? */
916 /* Insert single quote if not inside quotes already */
917 if (!quoted
&& buflen
) {
919 memmove (pp
+ 1, pp
, len
+1);
925 /* Escape existing quotes */
926 while ((pp
= strchr (pp
, '\'')) && buflen
> 3) {
929 /* Quoted. Let this quote close that quoting.
930 Insert an escaped quote to replace it and
931 another quote to reopen quoting, which will be
933 memmove (pp
+ 2, pp
, len
);
940 /* Not quoted. This should not be reached with
941 the current code, but handle the condition
942 in case the code changes. Just escape the
944 memmove (pp
, pp
-1, len
+1);
950 /* If pp is still set, that means we ran out of space. */
954 if (quoted
&& buflen
) {
955 /* See if we need to close the quote by looking
956 for an odd number of unescaped close quotes in
957 the remainder of the display string. */
958 int found_quote
= 0, escaped
= 0;
961 for (c
= cp
+1; *c
; ++c
) {
969 found_quote
= ! found_quote
;
994 (ct
->c_termproc
&& buflen
<= strlen(ct
->c_termproc
))) {
995 /* content_error would provide a more useful error message
996 * here, except that if we got overrun, it probably would
1002 /* use charset string to modify display method */
1003 if (ct
->c_termproc
) {
1006 strncpy (term
, buffer
, sizeof(term
));
1007 snprintf (buffer
, buflen
, ct
->c_termproc
, term
);
1015 convert_charset (CT ct
, char *dest_charset
, int *message_mods
) {
1016 char *src_charset
= content_charset (ct
);
1019 if (strcasecmp (src_charset
, dest_charset
)) {
1021 iconv_t conv_desc
= NULL
;
1028 int opened_input_file
= 0;
1029 char src_buffer
[BUFSIZ
];
1030 size_t dest_buffer_size
= BUFSIZ
;
1031 char *dest_buffer
= mh_xmalloc(dest_buffer_size
);
1035 if ((conv_desc
= iconv_open (dest_charset
, src_charset
)) ==
1037 advise (NULL
, "Can't convert %s to %s", src_charset
, dest_charset
);
1041 if ((tempfile
= m_mktemp2 (NULL
, invo_name
, &fd
, NULL
)) == NULL
) {
1042 adios (NULL
, "unable to create temporary file in %s",
1045 dest
= add (tempfile
, NULL
);
1047 if (ct
->c_cefile
.ce_file
) {
1048 file
= &ct
->c_cefile
.ce_file
;
1049 fp
= &ct
->c_cefile
.ce_fp
;
1051 } else if (ct
->c_file
) {
1054 begin
= (size_t) ct
->c_begin
;
1055 end
= (size_t) ct
->c_end
;
1056 } /* else no input file: shouldn't happen */
1058 if (file
&& *file
&& fp
) {
1060 if ((*fp
= fopen (*file
, "r")) == NULL
) {
1061 advise (*file
, "unable to open for reading");
1064 opened_input_file
= 1;
1071 size_t bytes_to_read
=
1072 end
> 0 && end
> begin
? end
- begin
: sizeof src_buffer
;
1074 fseeko (*fp
, begin
, SEEK_SET
);
1075 while ((inbytes
= fread (src_buffer
, 1,
1076 min (bytes_to_read
, sizeof src_buffer
),
1078 ICONV_CONST
char *ib
= src_buffer
;
1079 char *ob
= dest_buffer
;
1080 size_t outbytes
= dest_buffer_size
;
1081 size_t outbytes_before
= outbytes
;
1083 if (end
> 0) bytes_to_read
-= inbytes
;
1086 if (iconv (conv_desc
, &ib
, &inbytes
, &ob
, &outbytes
) ==
1088 if (errno
== E2BIG
) {
1090 * Bump up the buffer by at least a factor of 2
1091 * over what we need.
1093 size_t bumpup
= inbytes
* 2, ob_off
= ob
- dest_buffer
;
1094 dest_buffer_size
+= bumpup
;
1095 dest_buffer
= mh_xrealloc(dest_buffer
,
1097 ob
= dest_buffer
+ ob_off
;
1099 outbytes_before
+= bumpup
;
1105 if (write (fd
, dest_buffer
, outbytes_before
- outbytes
)
1107 advise (dest
, "write");
1112 if (opened_input_file
) {
1118 iconv_close (conv_desc
);
1122 /* Replace the decoded file with the converted one. */
1123 if (ct
->c_cefile
.ce_file
) {
1124 if (ct
->c_cefile
.ce_unlink
) {
1125 (void) m_unlink (ct
->c_cefile
.ce_file
);
1127 free (ct
->c_cefile
.ce_file
);
1129 ct
->c_cefile
.ce_file
= dest
;
1130 ct
->c_cefile
.ce_unlink
= 1;
1134 /* Update ct->c_ctline. */
1136 char *ctline
= concat(" ", ct
->c_ctinfo
.ci_type
, "/",
1137 ct
->c_ctinfo
.ci_subtype
, NULL
);
1140 replace_param(&ct
->c_ctinfo
.ci_first_pm
,
1141 &ct
->c_ctinfo
.ci_last_pm
, "charset",
1143 outline
= output_params(strlen(TYPE_FIELD
) + 1 + strlen(ctline
),
1144 ct
->c_ctinfo
.ci_first_pm
, NULL
, 0);
1146 ctline
= add(outline
, ctline
);
1150 free (ct
->c_ctline
);
1151 ct
->c_ctline
= ctline
;
1152 } /* else no CT line, which is odd */
1154 /* Update Content-Type header field. */
1155 for (hf
= ct
->c_first_hf
; hf
; hf
= hf
->next
) {
1156 if (! strcasecmp (TYPE_FIELD
, hf
->name
)) {
1157 char *ctline
= concat (ct
->c_ctline
, "\n", NULL
);
1165 (void) m_unlink (dest
);
1168 #else /* ! HAVE_ICONV */
1169 NMH_UNUSED (message_mods
);
1171 advise (NULL
, "Can't convert %s to %s without iconv", src_charset
,
1175 #endif /* ! HAVE_ICONV */
1183 convert_content_charset (CT ct
, char **file
) {
1187 /* Using current locale, see if the content needs to be converted. */
1189 /* content_charset() cannot return NULL. */
1190 char *charset
= content_charset (ct
);
1192 if (! check_charset (charset
, strlen (charset
))) {
1195 char *charset
= getcpy (get_charset ());
1197 if (convert_charset (ct
, charset
, &unused
) == 0) {
1198 *file
= ct
->c_cefile
.ce_file
;
1205 #else /* ! HAVE_ICONV */
1208 #endif /* ! HAVE_ICONV */
1214 * Compile our format string and save any parameters we care about.
1217 #define DEFAULT_MARKER "[ part %{part} - %{content-type} - " \
1218 "%<{description}%{description}" \
1219 "%?{cdispo-filename}%{cdispo-filename}" \
1220 "%|%{ctype-name}%> " \
1221 "%(kilo(size))B %<(unseen)\\(suppressed\\)%> ]"
1223 static struct format
*
1224 compile_marker(char *markerform
)
1228 struct comp
*comp
= NULL
;
1229 unsigned int bucket
;
1230 struct param_comp_list
*pc_entry
;
1232 fmtstring
= new_fs(markerform
, NULL
, DEFAULT_MARKER
);
1234 (void) fmt_compile(fmtstring
, &fmt
, 1);
1238 * Things we care about:
1240 * part - Part name (e.g., 1.1)
1241 * content-type - Content-Type
1242 * description - Content-Description
1243 * disposition - Content-Disposition (inline, attachment)
1244 * ctype-<param> - Content-Type parameter
1245 * cdispo-<param> - Content-Disposition parameter
1248 while ((comp
= fmt_nextcomp(comp
, &bucket
)) != NULL
) {
1249 if (strcasecmp(comp
->c_name
, "part") == 0) {
1251 } else if (strcasecmp(comp
->c_name
, "content-type") == 0) {
1253 } else if (strcasecmp(comp
->c_name
, "description") == 0) {
1254 description_comp
= comp
;
1255 } else if (strcasecmp(comp
->c_name
, "disposition") == 0) {
1257 } else if (strncasecmp(comp
->c_name
, "ctype-", 6) == 0 &&
1258 strlen(comp
->c_name
) > 6) {
1259 pc_entry
= mh_xmalloc(sizeof(*pc_entry
));
1260 pc_entry
->param
= getcpy(comp
->c_name
+ 6);
1261 pc_entry
->comp
= comp
;
1262 pc_entry
->next
= ctype_pc_list
;
1263 ctype_pc_list
= pc_entry
;
1264 } else if (strncasecmp(comp
->c_name
, "cdispo-", 7) == 0 &&
1265 strlen(comp
->c_name
) > 7) {
1266 pc_entry
= mh_xmalloc(sizeof(*pc_entry
));
1267 pc_entry
->param
= getcpy(comp
->c_name
+ 7);
1268 pc_entry
->comp
= comp
;
1269 pc_entry
->next
= dispo_pc_list
;
1270 dispo_pc_list
= pc_entry
;
1278 * Output on stdout an appropriate marker for this content, using mh-format
1282 output_marker(CT ct
, struct format
*fmt
, int hidden
)
1284 charstring_t outbuf
= charstring_create (BUFSIZ
);
1285 struct param_comp_list
*pcentry
;
1290 * Grab any items we care about.
1293 if (ctype_comp
&& ct
->c_ctinfo
.ci_type
) {
1294 ctype_comp
->c_text
= concat(ct
->c_ctinfo
.ci_type
, "/",
1295 ct
->c_ctinfo
.ci_subtype
, NULL
);
1298 if (part_comp
&& ct
->c_partno
) {
1299 part_comp
->c_text
= getcpy(ct
->c_partno
);
1302 if (description_comp
&& ct
->c_descr
) {
1303 description_comp
->c_text
= getcpy(ct
->c_descr
);
1306 if (dispo_comp
&& ct
->c_dispo_type
) {
1307 dispo_comp
->c_text
= getcpy(ct
->c_dispo_type
);
1310 for (pcentry
= ctype_pc_list
; pcentry
!= NULL
; pcentry
= pcentry
->next
) {
1311 pcentry
->comp
->c_text
= get_param(ct
->c_ctinfo
.ci_first_pm
,
1312 pcentry
->param
, '?', 0);
1315 for (pcentry
= dispo_pc_list
; pcentry
!= NULL
; pcentry
= pcentry
->next
) {
1316 pcentry
->comp
->c_text
= get_param(ct
->c_dispo_first
,
1317 pcentry
->param
, '?', 0);
1320 if (ct
->c_cesizefnx
)
1321 partsize
= (*ct
->c_cesizefnx
) (ct
);
1323 partsize
= ct
->c_end
- ct
->c_begin
;
1325 /* make the part's hidden aspect available by overloading the
1326 * %(unseen) function. make the part's size available via %(size).
1327 * see comments in h/fmt_scan.h.
1331 dat
[0] = dat
[1] = dat
[3] = 0;
1333 fmt_scan(fmt
, outbuf
, BUFSIZ
, dat
, NULL
);
1335 fputs(charstring_buffer (outbuf
), stdout
);
1336 charstring_free (outbuf
);
1342 * Reset (and free) any of the saved marker text
1346 free_markercomps(void)
1348 struct param_comp_list
*pc_entry
, *pc2
;
1352 description_comp
= NULL
;
1355 for (pc_entry
= ctype_pc_list
; pc_entry
!= NULL
; ) {
1356 free(pc_entry
->param
);
1357 pc2
= pc_entry
->next
;
1362 for (pc_entry
= dispo_pc_list
; pc_entry
!= NULL
; ) {
1363 free(pc_entry
->param
);
1364 pc2
= pc_entry
->next
;
1371 * Exit if the display process returned with a nonzero exit code, or terminated
1372 * with a SIGQUIT signal.
1376 pidcheck (int status
)
1378 if ((status
& 0xff00) == 0xff00 || (status
& 0x007f) != SIGQUIT
)