(mu_decode_filter): New function
(mu_default_fallback_mode): New variable. (mu_set_default_fallback): New function.
Showing
2 changed files
with
59 additions
and
0 deletions
... | @@ -130,6 +130,13 @@ extern int mu_true_answer_p __P((const char *p)); | ... | @@ -130,6 +130,13 @@ extern int mu_true_answer_p __P((const char *p)); |
130 | extern int mu_scheme_autodetect_p __P((const char *scheme, const char **path)); | 130 | extern int mu_scheme_autodetect_p __P((const char *scheme, const char **path)); |
131 | 131 | ||
132 | extern int mu_fd_wait __P((int fd, int *pflags, struct timeval *tvp)); | 132 | extern int mu_fd_wait __P((int fd, int *pflags, struct timeval *tvp)); |
133 | |||
134 | extern int mu_decode_filter __P((stream_t *pfilter, stream_t input, | ||
135 | char *filter_type, | ||
136 | char *fromcode, char *tocode)); | ||
137 | |||
138 | extern enum mu_iconv_fallback_mode mu_default_fallback_mode; | ||
139 | extern int mu_set_default_fallback __P((const char *str)); | ||
133 | 140 | ||
134 | #ifdef __cplusplus | 141 | #ifdef __cplusplus |
135 | } | 142 | } | ... | ... |
... | @@ -51,6 +51,7 @@ | ... | @@ -51,6 +51,7 @@ |
51 | #include <mailutils/envelope.h> | 51 | #include <mailutils/envelope.h> |
52 | #include <mailutils/nls.h> | 52 | #include <mailutils/nls.h> |
53 | #include <mailutils/stream.h> | 53 | #include <mailutils/stream.h> |
54 | #include <mailutils/filter.h> | ||
54 | 55 | ||
55 | #include <registrar0.h> | 56 | #include <registrar0.h> |
56 | 57 | ||
... | @@ -1216,3 +1217,54 @@ mu_fd_wait (int fd, int *pflags, struct timeval *tvp) | ... | @@ -1216,3 +1217,54 @@ mu_fd_wait (int fd, int *pflags, struct timeval *tvp) |
1216 | } | 1217 | } |
1217 | return 0; | 1218 | return 0; |
1218 | } | 1219 | } |
1220 | |||
1221 | enum mu_iconv_fallback_mode mu_default_fallback_mode = mu_fallback_copy_octal; | ||
1222 | |||
1223 | int | ||
1224 | mu_set_default_fallback (const char *str) | ||
1225 | { | ||
1226 | if (strcmp (str, "none") == 0) | ||
1227 | mu_default_fallback_mode = mu_fallback_none; | ||
1228 | else if (strcmp (str, "copy-pass") == 0) | ||
1229 | mu_default_fallback_mode = mu_fallback_copy_pass; | ||
1230 | else if (strcmp (str, "copy-octal") == 0) | ||
1231 | mu_default_fallback_mode = mu_fallback_copy_octal; | ||
1232 | else | ||
1233 | return EINVAL; | ||
1234 | return 0; | ||
1235 | } | ||
1236 | |||
1237 | int | ||
1238 | mu_decode_filter (stream_t *pfilter, stream_t input, char *filter_type, | ||
1239 | char *fromcode, char *tocode) | ||
1240 | { | ||
1241 | stream_t filter; | ||
1242 | |||
1243 | int status = filter_create (&filter, input, filter_type, | ||
1244 | MU_FILTER_DECODE, MU_STREAM_READ); | ||
1245 | if (status) | ||
1246 | return status; | ||
1247 | |||
1248 | if (fromcode && tocode && strcasecmp (fromcode, tocode)) | ||
1249 | { | ||
1250 | stream_t cvt; | ||
1251 | status = filter_iconv_create (&cvt, filter, fromcode, tocode, | ||
1252 | MU_STREAM_NO_CLOSE, | ||
1253 | mu_default_fallback_mode); | ||
1254 | if (status == 0) | ||
1255 | { | ||
1256 | if (stream_open (cvt)) | ||
1257 | stream_destroy (&cvt, stream_get_owner (cvt)); | ||
1258 | else | ||
1259 | { | ||
1260 | int flags; | ||
1261 | stream_get_flags (cvt, &flags); | ||
1262 | flags &= ~MU_STREAM_NO_CLOSE; | ||
1263 | stream_set_flags (cvt, flags); | ||
1264 | filter = cvt; | ||
1265 | } | ||
1266 | } | ||
1267 | } | ||
1268 | *pfilter = filter; | ||
1269 | return 0; | ||
1270 | } | ... | ... |
-
Please register or sign in to post a comment