Imported Upstream version 0.63.0
[hcoop/debian/courier-authlib.git] / rfc822 / rfc2047.h
1 #ifndef rfc2047_h
2 #define rfc2047_h
3
4 #include <stdlib.h>
5 /*
6 ** Copyright 1998 - 2009 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.12 2009/11/14 21:15:43 mrsam Exp $";
16
17 struct unicode_info;
18
19 /*
20 ** Raw RFC 2047 parser.
21 **
22 ** rfc2047_decoder() repeatedly invokes the callback function, passing it
23 ** the decoded RFC 2047 string that's given as an argument.
24 */
25
26 int rfc2047_decoder(const char *text,
27 void (*callback)(const char *chset,
28 const char *lang,
29 const char *content,
30 size_t cnt,
31 void *dummy),
32 void *ptr);
33
34 /*
35 ** rfc2047_print_unicodeaddr is like rfc822_print, except that it converts
36 ** RFC 2047 MIME encoding to 8 bit text.
37 */
38
39 struct rfc822a;
40
41 int rfc2047_print_unicodeaddr(const struct rfc822a *a,
42 const char *charset,
43 void (*print_func)(char, void *),
44 void (*print_separator)(const char *, void *),
45 void *ptr);
46
47
48 /*
49 ** And now, let's encode something with RFC 2047. Encode the following
50 ** string in the indicated character set, into a malloced buffer. Returns 0
51 ** if malloc failed.
52 */
53
54 char *rfc2047_encode_str(const char *str, const char *charset,
55 int (*qp_allow)(char c) /* See below */);
56
57 /*
58 ** If you can live with the encoded text being generated on the fly, use
59 ** rfc2047_encode_callback, which calls a callback function, instead of
60 ** dynamically allocating memory.
61 */
62
63 int rfc2047_encode_callback(const char *str, /* String to encode */
64 const char *charset, /* Native charset */
65 int (*qp_allow)(char c),
66 /* Return true if c can appear in QP-encoded
67 ** word */
68 int (*cb_func)(const char *, size_t, void *),
69 /* Callback function. */
70 void *arg
71 /* Passthrough arg to callback_function */
72 );
73
74 /* Potential arguments for qp_allow */
75
76 int rfc2047_qp_allow_any(char); /* Any character */
77 int rfc2047_qp_allow_comment(char); /* Any character except () */
78 int rfc2047_qp_allow_word(char); /* See RFC2047, bottom of page 7 */
79
80
81
82 /*
83 ** rfc2047_encode_header allocates a buffer, and MIME-encodes a header.
84 **
85 ** The name of the header, passed as the first parameter, should be
86 ** "From", "To", "Subject", etc... It is not included in the encoded contents.
87 */
88 char *rfc2047_encode_header_tobuf(const char *name, /* Header name */
89 const char *header, /* Header's contents */
90 const char *charset);
91
92 /*
93 ** rfc2047_encode_header_addr allocates a buffer, and MIME-encodes an
94 ** RFC822 address header.
95 **
96 */
97 char *rfc2047_encode_header_addr(const struct rfc822a *a,
98 const char *charset);
99
100 #ifdef __cplusplus
101 }
102 #endif
103
104 #endif