summaryrefslogtreecommitdiffstats
path: root/rfc2045/rfc2045decodemimesectionu.c
diff options
context:
space:
mode:
Diffstat (limited to 'rfc2045/rfc2045decodemimesectionu.c')
-rw-r--r--rfc2045/rfc2045decodemimesectionu.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/rfc2045/rfc2045decodemimesectionu.c b/rfc2045/rfc2045decodemimesectionu.c
new file mode 100644
index 0000000..3711b1e
--- /dev/null
+++ b/rfc2045/rfc2045decodemimesectionu.c
@@ -0,0 +1,68 @@
+/*
+** Copyright 2000-2011 Double Precision, Inc. See COPYING for
+** distribution information.
+*/
+
+#include "rfc2045_config.h"
+#include "rfc2045.h"
+#include "../unicode/unicode.h"
+#include <stdio.h>
+#include <unistd.h>
+#include <iconv.h>
+#include <errno.h>
+
+/*
+** Call rfc2045_decodemimesection, expecting textual content. Convert
+** textual content to local character set, if possible. This is implemented
+** by saving the real callback function, then calling rfc2045_decodemimesection
+** and specifying our own callback function, which does the conversion, then
+** calls the original callback function. Neat, eh?
+*/
+
+static int myhandler(const char *, size_t, void *);
+
+int rfc2045_decodetextmimesection(struct rfc2045src *src,
+ struct rfc2045 *rfc,
+ const char *mychset,
+ int *conv_err,
+ int (*handler)(const char *,
+ size_t, void *),
+ void *voidarg)
+{
+ const char *dummy;
+ const char *src_chset;
+
+ libmail_u_convert_handle_t ci;
+ int rc;
+ int dummy_flag;
+
+ if (!conv_err)
+ conv_err= &dummy_flag;
+
+ rfc2045_mimeinfo(rfc, &dummy, &dummy, &src_chset);
+
+ *conv_err=0;
+
+ if ((ci=libmail_u_convert_init(src_chset, mychset, handler, voidarg))
+ == NULL)
+ {
+ *conv_err=1;
+ return -1;
+ }
+
+ rc=rfc2045_decodemimesection(src, rfc, &myhandler, &ci);
+
+ dummy_flag=0;
+ if (libmail_u_convert_deinit(ci, &dummy_flag))
+ rc= -1;
+
+ if (dummy_flag)
+ *conv_err=1;
+ return (rc);
+}
+
+static int myhandler(const char *cp, size_t cnt, void *voidarg)
+{
+ return libmail_u_convert(*(libmail_u_convert_handle_t *)
+ voidarg, cp, cnt);
+}