Back to index

courier  0.68.2
rfc2045decodemimesectionu.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2000-2011 Double Precision, Inc.  See COPYING for
00003 ** distribution information.
00004 */
00005 
00006 #include "rfc2045_config.h"
00007 #include      "rfc2045.h"
00008 #include      "../unicode/unicode.h"
00009 #include      <stdio.h>
00010 #include      <unistd.h>
00011 #include      <iconv.h>
00012 #include      <errno.h>
00013 
00014 /*
00015 ** Call rfc2045_decodemimesection, expecting textual content.  Convert
00016 ** textual content to local character set, if possible.  This is implemented
00017 ** by saving the real callback function, then calling rfc2045_decodemimesection
00018 ** and specifying our own callback function, which does the conversion, then
00019 ** calls the original callback function.  Neat, eh?
00020 */
00021 
00022 static int myhandler(const char *, size_t, void *);
00023 
00024 int rfc2045_decodetextmimesection(struct rfc2045src *src,
00025                               struct rfc2045 *rfc,
00026                               const char *mychset,
00027                               int *conv_err,
00028                               int (*handler)(const char *,
00029                                            size_t, void *),
00030                               void *voidarg)
00031 {
00032        const char *dummy;
00033        const char *src_chset;
00034 
00035        libmail_u_convert_handle_t ci;
00036        int rc;
00037        int dummy_flag;
00038 
00039        if (!conv_err)
00040               conv_err= &dummy_flag;
00041 
00042        rfc2045_mimeinfo(rfc, &dummy, &dummy, &src_chset);
00043 
00044        *conv_err=0;
00045 
00046        if ((ci=libmail_u_convert_init(src_chset, mychset, handler, voidarg))
00047            == NULL)
00048        {
00049               *conv_err=1;
00050               return -1;
00051        }
00052 
00053        rc=rfc2045_decodemimesection(src, rfc, &myhandler, &ci);
00054 
00055        dummy_flag=0;
00056        if (libmail_u_convert_deinit(ci, &dummy_flag))
00057               rc= -1;
00058 
00059        if (dummy_flag)
00060               *conv_err=1;
00061        return (rc);
00062 }
00063 
00064 static int myhandler(const char *cp, size_t cnt, void *voidarg)
00065 {
00066        return libmail_u_convert(*(libmail_u_convert_handle_t *)
00067                              voidarg, cp, cnt);
00068 }