summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mailutils/mutil.h7
-rw-r--r--mailbox/mutil.c52
2 files changed, 59 insertions, 0 deletions
diff --git a/include/mailutils/mutil.h b/include/mailutils/mutil.h
index eef2edfb7..b7c073d94 100644
--- a/include/mailutils/mutil.h
+++ b/include/mailutils/mutil.h
@@ -130,6 +130,13 @@ extern int mu_true_answer_p __P((const char *p));
extern int mu_scheme_autodetect_p __P((const char *scheme, const char **path));
extern int mu_fd_wait __P((int fd, int *pflags, struct timeval *tvp));
+
+extern int mu_decode_filter __P((stream_t *pfilter, stream_t input,
+ char *filter_type,
+ char *fromcode, char *tocode));
+
+extern enum mu_iconv_fallback_mode mu_default_fallback_mode;
+extern int mu_set_default_fallback __P((const char *str));
#ifdef __cplusplus
}
diff --git a/mailbox/mutil.c b/mailbox/mutil.c
index 1830f7a9e..5536b8d86 100644
--- a/mailbox/mutil.c
+++ b/mailbox/mutil.c
@@ -51,6 +51,7 @@
#include <mailutils/envelope.h>
#include <mailutils/nls.h>
#include <mailutils/stream.h>
+#include <mailutils/filter.h>
#include <registrar0.h>
@@ -1216,3 +1217,54 @@ mu_fd_wait (int fd, int *pflags, struct timeval *tvp)
}
return 0;
}
+
+enum mu_iconv_fallback_mode mu_default_fallback_mode = mu_fallback_copy_octal;
+
+int
+mu_set_default_fallback (const char *str)
+{
+ if (strcmp (str, "none") == 0)
+ mu_default_fallback_mode = mu_fallback_none;
+ else if (strcmp (str, "copy-pass") == 0)
+ mu_default_fallback_mode = mu_fallback_copy_pass;
+ else if (strcmp (str, "copy-octal") == 0)
+ mu_default_fallback_mode = mu_fallback_copy_octal;
+ else
+ return EINVAL;
+ return 0;
+}
+
+int
+mu_decode_filter (stream_t *pfilter, stream_t input, char *filter_type,
+ char *fromcode, char *tocode)
+{
+ stream_t filter;
+
+ int status = filter_create (&filter, input, filter_type,
+ MU_FILTER_DECODE, MU_STREAM_READ);
+ if (status)
+ return status;
+
+ if (fromcode && tocode && strcasecmp (fromcode, tocode))
+ {
+ stream_t cvt;
+ status = filter_iconv_create (&cvt, filter, fromcode, tocode,
+ MU_STREAM_NO_CLOSE,
+ mu_default_fallback_mode);
+ if (status == 0)
+ {
+ if (stream_open (cvt))
+ stream_destroy (&cvt, stream_get_owner (cvt));
+ else
+ {
+ int flags;
+ stream_get_flags (cvt, &flags);
+ flags &= ~MU_STREAM_NO_CLOSE;
+ stream_set_flags (cvt, flags);
+ filter = cvt;
+ }
+ }
+ }
+ *pfilter = filter;
+ return 0;
+}

Return to:

Send suggestions and report system problems to the System administrator.