Commit e7e4b273 e7e4b273a9494405434f7153371dc885647c9525 by Sergey Poznyakoff

(mu_decode_filter): New function

(mu_default_fallback_mode): New variable.
(mu_set_default_fallback): New function.
1 parent 3ad41770
......@@ -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
}
......
......@@ -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;
}
......