Recognize mhn-compose-* profile components.
Showing
1 changed file
with
116 additions
and
18 deletions
... | @@ -595,6 +595,80 @@ _mhn_profile_get (char *prefix, char *type, char *subtype, char *defval) | ... | @@ -595,6 +595,80 @@ _mhn_profile_get (char *prefix, char *type, char *subtype, char *defval) |
595 | } | 595 | } |
596 | 596 | ||
597 | char * | 597 | char * |
598 | mhn_compose_command (char *typestr, int *flags, char *file) | ||
599 | { | ||
600 | char *p, *str; | ||
601 | char *type, *subtype, *typeargs; | ||
602 | struct obstack stk; | ||
603 | |||
604 | split_content (typestr, &type, &subtype); | ||
605 | str = _mhn_profile_get ("compose", type, subtype, NULL); | ||
606 | if (!str) | ||
607 | return NULL; | ||
608 | |||
609 | /* Expand macro-notations: | ||
610 | %a additional arguments | ||
611 | %f filename containing content | ||
612 | %F %f, and stdout is not redirected | ||
613 | %s subtype */ | ||
614 | |||
615 | obstack_init (&stk); | ||
616 | for (p = str; *p && isspace (*p); p++) | ||
617 | ; | ||
618 | |||
619 | if (*p == '|') | ||
620 | p++; | ||
621 | |||
622 | for ( ; *p; p++) | ||
623 | { | ||
624 | if (*p == '%') | ||
625 | { | ||
626 | switch (*++p) | ||
627 | { | ||
628 | case 'a': | ||
629 | /* additional arguments */ | ||
630 | obstack_grow (&stk, typeargs, strlen (typeargs)); | ||
631 | break; | ||
632 | |||
633 | case 'F': | ||
634 | /* %f, and stdout is not redirected */ | ||
635 | *flags |= MHN_STDIN; | ||
636 | /*FALLTHRU*/ | ||
637 | case 'f': | ||
638 | obstack_grow (&stk, file, strlen (file)); | ||
639 | break; | ||
640 | |||
641 | case 's': | ||
642 | /* subtype */ | ||
643 | obstack_grow (&stk, subtype, strlen (subtype)); | ||
644 | break; | ||
645 | |||
646 | default: | ||
647 | obstack_1grow (&stk, *p); | ||
648 | p++; | ||
649 | } | ||
650 | } | ||
651 | else | ||
652 | obstack_1grow (&stk, *p); | ||
653 | } | ||
654 | obstack_1grow (&stk, 0); | ||
655 | |||
656 | free (type); | ||
657 | free (subtype); | ||
658 | |||
659 | str = obstack_finish (&stk); | ||
660 | for (p = str; *p && isspace (*p); p++) | ||
661 | ; | ||
662 | if (!*p) | ||
663 | str = NULL; | ||
664 | else | ||
665 | str = strdup (str); | ||
666 | |||
667 | obstack_free (&stk, NULL); | ||
668 | return str; | ||
669 | } | ||
670 | |||
671 | char * | ||
598 | mhn_show_command (message_t msg, msg_part_t part, int *flags, char **tempfile) | 672 | mhn_show_command (message_t msg, msg_part_t part, int *flags, char **tempfile) |
599 | { | 673 | { |
600 | char *p, *str, *tmp; | 674 | char *p, *str, *tmp; |
... | @@ -720,7 +794,7 @@ mhn_store_command (message_t msg, msg_part_t part, char *name) | ... | @@ -720,7 +794,7 @@ mhn_store_command (message_t msg, msg_part_t part, char *name) |
720 | message_get_header (msg, &hdr); | 794 | message_get_header (msg, &hdr); |
721 | _get_content_type (hdr, &typestr, &typeargs); | 795 | _get_content_type (hdr, &typestr, &typeargs); |
722 | split_content (typestr, &type, &subtype); | 796 | split_content (typestr, &type, &subtype); |
723 | str = _mhn_profile_get ("show", type, subtype, "%m%P.%s"); | 797 | str = _mhn_profile_get ("store", type, subtype, "%m%P.%s"); |
724 | 798 | ||
725 | /* Expand macro-notations: | 799 | /* Expand macro-notations: |
726 | %m message number | 800 | %m message number |
... | @@ -1056,25 +1130,33 @@ show_internal (message_t msg, msg_part_t part, char *encoding, stream_t out) | ... | @@ -1056,25 +1130,33 @@ show_internal (message_t msg, msg_part_t part, char *encoding, stream_t out) |
1056 | } | 1130 | } |
1057 | 1131 | ||
1058 | int | 1132 | int |
1059 | exec_internal (message_t msg, msg_part_t part, char *encoding, char *cmd) | 1133 | mhn_exec (stream_t *str, char *cmd, int flags) |
1060 | { | 1134 | { |
1061 | int rc; | 1135 | int rc = prog_stream_create (str, cmd, MU_STREAM_WRITE); |
1062 | stream_t tmp; | ||
1063 | |||
1064 | rc = prog_stream_create (&tmp, cmd, MU_STREAM_WRITE); | ||
1065 | if (rc) | 1136 | if (rc) |
1066 | { | 1137 | { |
1067 | mh_error (_("can't create proc stream (command %s): %s"), | 1138 | mh_error (_("can't create proc stream (command %s): %s"), |
1068 | cmd, mu_strerror (rc)); | 1139 | cmd, mu_strerror (rc)); |
1069 | return rc; | ||
1070 | } | 1140 | } |
1071 | rc = stream_open (tmp); | 1141 | else |
1072 | if (rc) | ||
1073 | { | 1142 | { |
1143 | rc = stream_open (*str); | ||
1144 | if (rc) | ||
1074 | mh_error (_("can't open proc stream (command %s): %s"), | 1145 | mh_error (_("can't open proc stream (command %s): %s"), |
1075 | cmd, mu_strerror (rc)); | 1146 | cmd, mu_strerror (rc)); |
1076 | return rc; | ||
1077 | } | 1147 | } |
1148 | return rc; | ||
1149 | } | ||
1150 | |||
1151 | int | ||
1152 | exec_internal (message_t msg, msg_part_t part, char *encoding, char *cmd, | ||
1153 | int flags) | ||
1154 | { | ||
1155 | int rc; | ||
1156 | stream_t tmp; | ||
1157 | |||
1158 | if ((rc = mhn_exec (&tmp, cmd, flags))) | ||
1159 | return rc; | ||
1078 | show_internal (msg, part, encoding, tmp); | 1160 | show_internal (msg, part, encoding, tmp); |
1079 | stream_destroy (&tmp, stream_get_owner (tmp)); | 1161 | stream_destroy (&tmp, stream_get_owner (tmp)); |
1080 | return rc; | 1162 | return rc; |
... | @@ -1130,7 +1212,7 @@ mhn_run_command (message_t msg, msg_part_t part, | ... | @@ -1130,7 +1212,7 @@ mhn_run_command (message_t msg, msg_part_t part, |
1130 | argcv_free (argc, argv); | 1212 | argcv_free (argc, argv); |
1131 | } | 1213 | } |
1132 | else | 1214 | else |
1133 | rc = exec_internal (msg, part, encoding, cmd); | 1215 | rc = exec_internal (msg, part, encoding, cmd, flags); |
1134 | 1216 | ||
1135 | return rc; | 1217 | return rc; |
1136 | } | 1218 | } |
... | @@ -1190,7 +1272,7 @@ show_handler (message_t msg, msg_part_t part, char *type, char *encoding, | ... | @@ -1190,7 +1272,7 @@ show_handler (message_t msg, msg_part_t part, char *type, char *encoding, |
1190 | { | 1272 | { |
1191 | char *pager = mh_global_profile_get ("moreproc", getenv ("PAGER")); | 1273 | char *pager = mh_global_profile_get ("moreproc", getenv ("PAGER")); |
1192 | if (pager) | 1274 | if (pager) |
1193 | exec_internal (msg, part, encoding, pager); | 1275 | exec_internal (msg, part, encoding, pager, 0); |
1194 | else | 1276 | else |
1195 | show_internal (msg, part, encoding, out); | 1277 | show_internal (msg, part, encoding, out); |
1196 | } | 1278 | } |
... | @@ -1870,15 +1952,32 @@ edit_mime (char *cmd, struct compose_env *env, message_t *msg, int level) | ... | @@ -1870,15 +1952,32 @@ edit_mime (char *cmd, struct compose_env *env, message_t *msg, int level) |
1870 | body_t body; | 1952 | body_t body; |
1871 | stream_t in, out = NULL, fstr; | 1953 | stream_t in, out = NULL, fstr; |
1872 | char *encoding; | 1954 | char *encoding; |
1873 | char *p; | 1955 | char *p, *typestr; |
1956 | char *shell_cmd; | ||
1957 | int flags; | ||
1874 | 1958 | ||
1875 | if (!*msg) | 1959 | if (!*msg) |
1876 | message_create (msg, NULL); | 1960 | message_create (msg, NULL); |
1877 | message_get_header (*msg, &hdr); | 1961 | message_get_header (*msg, &hdr); |
1878 | rc = parse_type_command (&cmd, env, hdr); | 1962 | rc = parse_type_command (&cmd, env, hdr); |
1963 | if (rc) | ||
1964 | return 1; | ||
1965 | |||
1879 | for (p = cmd + strlen (cmd) - 1; p > cmd && isspace (*p); p--) | 1966 | for (p = cmd + strlen (cmd) - 1; p > cmd && isspace (*p); p--) |
1880 | ; | 1967 | ; |
1881 | if (p == cmd) | 1968 | p[1] = 0; |
1969 | |||
1970 | _get_content_type (hdr, &typestr, NULL); | ||
1971 | shell_cmd = mhn_compose_command (typestr, &flags, cmd); | ||
1972 | free (typestr); | ||
1973 | |||
1974 | /* Open the input stream, whatever it is */ | ||
1975 | if (shell_cmd) | ||
1976 | { | ||
1977 | if (mhn_exec (&in, cmd, flags)) | ||
1978 | return 1; | ||
1979 | } | ||
1980 | else if (p == cmd) | ||
1882 | { | 1981 | { |
1883 | mh_error (_("%s:%lu: missing filename"), | 1982 | mh_error (_("%s:%lu: missing filename"), |
1884 | input_file, | 1983 | input_file, |
... | @@ -1886,9 +1985,8 @@ edit_mime (char *cmd, struct compose_env *env, message_t *msg, int level) | ... | @@ -1886,9 +1985,8 @@ edit_mime (char *cmd, struct compose_env *env, message_t *msg, int level) |
1886 | finish_msg (env, msg); | 1985 | finish_msg (env, msg); |
1887 | return 1; | 1986 | return 1; |
1888 | } | 1987 | } |
1889 | p[1] = 0; | 1988 | else |
1890 | 1989 | { | |
1891 | /* Open input stream */ | ||
1892 | rc = file_stream_create (&in, cmd, MU_STREAM_READ); | 1990 | rc = file_stream_create (&in, cmd, MU_STREAM_READ); |
1893 | if (rc) | 1991 | if (rc) |
1894 | { | 1992 | { |
... | @@ -1904,6 +2002,7 @@ edit_mime (char *cmd, struct compose_env *env, message_t *msg, int level) | ... | @@ -1904,6 +2002,7 @@ edit_mime (char *cmd, struct compose_env *env, message_t *msg, int level) |
1904 | stream_destroy (&in, stream_get_owner (in)); | 2002 | stream_destroy (&in, stream_get_owner (in)); |
1905 | return rc; | 2003 | return rc; |
1906 | } | 2004 | } |
2005 | } | ||
1907 | 2006 | ||
1908 | /* Create filter */ | 2007 | /* Create filter */ |
1909 | 2008 | ||
... | @@ -2183,7 +2282,6 @@ mhn_compose () | ... | @@ -2183,7 +2282,6 @@ mhn_compose () |
2183 | rename (name, input_file); | 2282 | rename (name, input_file); |
2184 | 2283 | ||
2185 | free (name); | 2284 | free (name); |
2186 | free (input_file); | ||
2187 | 2285 | ||
2188 | return 0; | 2286 | return 0; |
2189 | } | 2287 | } | ... | ... |
-
Please register or sign in to post a comment