d9898ee8 |
1 | #ifndef rfc2047_h |
2 | #define rfc2047_h |
3 | |
4 | #include <stdlib.h> |
5 | /* |
6 | ** Copyright 1998 - 2002 Double Precision, Inc. See COPYING for |
7 | ** distribution information. |
8 | */ |
9 | |
10 | #ifdef __cplusplus |
11 | extern "C" { |
12 | #endif |
13 | |
14 | |
15 | static const char rfc2047_h_rcsid[]="$Id: rfc2047.h,v 1.9 2007/03/01 04:32:04 mrsam Exp $"; |
16 | |
17 | extern int rfc2047_decode(const char *text, |
18 | int (*func)(const char *, int, |
19 | const char *, |
20 | const char *, |
21 | void *), |
22 | void *arg); |
23 | |
24 | extern char *rfc2047_decode_simple(const char *text); |
25 | |
26 | extern char *rfc2047_decode_enhanced(const char *text, const char *mychset); |
27 | |
28 | /* |
29 | ** If libunicode.a is available, like rfc2047_decode_enhanced, but attempt to |
30 | ** convert to my preferred charset. |
31 | */ |
32 | |
33 | struct unicode_info; |
34 | |
35 | extern char *rfc2047_decode_unicode(const char *text, |
36 | const struct unicode_info *mychset, |
37 | int options); |
38 | |
39 | #define RFC2047_DECODE_DISCARD 1 |
40 | /* options: Discard unknown charsets from decoded string. */ |
41 | #define RFC2047_DECODE_ABORT 2 |
42 | /* options: Abort if we encounter an unknown charset, errno=EINVAL */ |
43 | #define RFC2047_DECODE_NOTAG 4 |
44 | /* options: Do not tag unknown charset strings */ |
45 | #define RFC2047_DECODE_REPLACE 8 |
46 | /* options: Replace unknown characters */ |
47 | |
48 | /* |
49 | ** rfc2047_print is like rfc822_print, except that it converts RFC 2047 |
50 | ** MIME encoding to 8 bit text. |
51 | */ |
52 | |
53 | struct rfc822a; |
54 | |
55 | void rfc2047_print(const struct rfc822a *a, |
56 | const char *charset, |
57 | void (*print_func)(char, void *), |
58 | void (*print_separator)(const char *, void *), void *); |
59 | |
60 | void rfc2047_print_unicode(const struct rfc822a *a, |
61 | const char *charset, |
62 | void (*print_func)(char, void *), |
63 | void (*print_separator)(const char *, void *), |
64 | void *ptr); |
65 | |
66 | |
67 | |
68 | /* |
69 | ** And now, let's encode something with RFC 2047. Encode the following |
70 | ** string in the indicated character set, into a malloced buffer. Returns 0 |
71 | ** if malloc failed. |
72 | */ |
73 | |
74 | char *rfc2047_encode_str(const char *str, const char *charset, |
75 | int (*qp_allow)(char c) /* See below */); |
76 | |
77 | /* |
78 | ** If you can live with the encoded text being generated on the fly, use |
79 | ** rfc2047_encode_callback, which calls a callback function, instead of |
80 | ** dynamically allocating memory. |
81 | */ |
82 | |
83 | int rfc2047_encode_callback(const char *str, /* String to encode */ |
84 | const char *charset, /* Native charset */ |
85 | int (*qp_allow)(char c), |
86 | /* Return true if c can appear in QP-encoded |
87 | ** word */ |
88 | int (*cb_func)(const char *, size_t, void *), |
89 | /* Callback function. */ |
90 | void *arg |
91 | /* Passthrough arg to callback_function */ |
92 | ); |
93 | |
94 | /* Potential arguments for qp_allow */ |
95 | |
96 | int rfc2047_qp_allow_any(char); /* Any character */ |
97 | int rfc2047_qp_allow_comment(char); /* Any character except () */ |
98 | int rfc2047_qp_allow_word(char); /* See RFC2047, bottom of page 7 */ |
99 | |
100 | |
101 | /* |
102 | ** rfc2047_encode_header allocates a buffer, and MIME-encodes an RFC822 header |
103 | ** |
104 | */ |
105 | char *rfc2047_encode_header(const struct rfc822a *a, |
106 | const char *charset); |
107 | |
108 | #ifdef __cplusplus |
109 | } |
110 | #endif |
111 | |
112 | #endif |