| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 | /*
** Copyright 2000-2011 Double Precision, Inc.  See COPYING for
** distribution information.
*/
#include "rfc2045_config.h"
#include	"rfc2045.h"
#include	<courier-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;
	unicode_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=unicode_convert_init(src_chset, mychset, handler, voidarg))
	    == NULL)
	{
		*conv_err=1;
		return -1;
	}
	rc=rfc2045_decodemimesection(src, rfc, &myhandler, &ci);
	dummy_flag=0;
	if (unicode_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 unicode_convert(*(unicode_convert_handle_t *)
				 voidarg, cp, cnt);
}
 |