2 ** Copyright 1998 - 2000 Double Precision, Inc. See COPYING for
3 ** distribution information.
16 static const char rcsid
[]="$Id: rfc2047u.c,v 1.5 2004/05/23 14:28:24 mrsam Exp $";
20 #include "../unicode/unicode.h"
22 struct decode_unicode_s
{
23 const struct unicode_info
*mychset
;
30 static void save_unicode_text(const char *p
, int l
, struct decode_unicode_s
*s
)
33 memcpy(s
->bufptr
+s
->bufsize
, p
, l
);
38 static int save_unicode(const char *txt
, int len
, const char *chset
,
42 struct decode_unicode_s
*p
=(struct decode_unicode_s
*)arg
;
43 char *txts
=malloc(len
+1);
49 memcpy(txts
, txt
, len
);
53 chset
=unicode_ISO8859_1
.chset
;
55 s
=unicode_convert_fromchset(txts
, chset
, p
->mychset
);
56 if (!s
&& p
->options
& RFC2047_DECODE_REPLACE
)
58 const struct unicode_info
*uiptr
=unicode_find(chset
);
60 s
=unicode_xconvert(txts
, uiptr
, p
->mychset
);
65 save_unicode_text(s
, strlen(s
), p
);
70 if (p
->options
& RFC2047_DECODE_ABORT
)
76 if (p
->options
& RFC2047_DECODE_DISCARD
)
79 if (!(p
->options
& RFC2047_DECODE_NOTAG
))
81 save_unicode_text(" [", 2, p
);
82 save_unicode_text(chset
, strlen(chset
), p
);
83 save_unicode_text("] ", 2, p
);
84 if (!(p
->options
& RFC2047_DECODE_REPLACE
))
86 save_unicode_text(txt
, len
, p
);
91 if (p
->options
& RFC2047_DECODE_REPLACE
)
92 for (i
=0; i
< strlen(txt
); i
++)
93 save_unicode_text("?", 1, p
);
98 char *rfc2047_decode_unicode(const char *text
,
99 const struct unicode_info
*mychset
,
102 struct decode_unicode_s s
;
112 if (rfc2047_decode(text
, &save_unicode
, &s
))
115 s
.bufptr
=p
=malloc(s
.bufsize
);
120 if (rfc2047_decode(text
, &save_unicode
, &s
))
125 save_unicode_text("", 1, (void *)&s
);
130 static char *do_rfc2047_decode_enhanced(const char *text
, const char *mychset
)
132 const struct unicode_info
*u
=unicode_find(mychset
);
134 if (!u
) u
=&unicode_ISO8859_1
;
136 return rfc2047_decode_unicode(text
, u
, 0);
139 void rfc2047_print_unicode(const struct rfc822a
*a
,
141 void (*print_func
)(char, void *),
142 void (*print_separator
)(const char *, void *),
145 rfc822_print_common(a
, &do_rfc2047_decode_enhanced
, charset
,
146 print_func
, print_separator
, ptr
);