Imported upstream version 0.59.3
[hcoop/debian/courier-authlib.git] / rfc822 / rfc822.h
1 /*
2 ** $Id: rfc822.h,v 1.24 2006/04/11 02:24:59 mrsam Exp $
3 */
4 #ifndef rfc822_h
5 #define rfc822_h
6
7 /*
8 ** Copyright 1998 - 2006 Double Precision, Inc.
9 ** See COPYING for distribution information.
10 */
11
12 #if HAVE_CONFIG_H
13 #include "../rfc822/config.h" /* VPATH build */
14 #endif
15
16 #include <time.h>
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /*
23 ** The text string we want to parse is first tokenized into an array of
24 ** struct rfc822token records. 'ptr' points into the original text
25 ** string, and 'len' has how many characters from 'ptr' belongs to this
26 ** token.
27 */
28
29 struct rfc822token {
30 struct rfc822token *next; /* Unused by librfc822, for use by
31 ** clients */
32 int token;
33 /*
34 Values for token:
35
36 '(' - comment
37 '"' - quoted string
38 '<', '>', '@', ',', ';', ':', '.', '[', ']', '%', '!', '=', '?', '/' - RFC atoms.
39 0 - atom
40 */
41
42 #define rfc822_is_atom(p) ( (p) == 0 || (p) == '"' || (p) == '(' )
43
44 const char *ptr; /* Pointer to value for the token. */
45 int len; /* Length of token value */
46 } ;
47
48 /*
49 ** After the struct rfc822token array is built, it is used to create
50 ** the rfc822addr array, which is the array of addresses (plus
51 ** syntactical fluff) extracted from those text strings. Each rfc822addr
52 ** record has several possible interpretation:
53 **
54 ** tokens is NULL - syntactical fluff, look in name/nname for tokens
55 ** representing the syntactical fluff ( which is semicolons
56 ** and list name:
57 **
58 ** tokens is not NULL - actual address. The tokens representing the actual
59 ** address is in tokens/ntokens. If there are comments in
60 ** the address that are possible "real name" for the address
61 ** they are saved in name/nname (name may be null if there
62 ** is none).
63 ** If nname is 1, and name points to a comment token,
64 ** the address was specified in old-style format. Otherwise
65 ** the address was specified in new-style route-addr format.
66 **
67 ** The tokens and name pointers are set to point to the original rfc822token
68 ** array.
69 */
70
71 struct rfc822addr {
72 struct rfc822token *tokens;
73 struct rfc822token *name;
74 } ;
75
76 /***************************************************************************
77 **
78 ** rfc822 tokens
79 **
80 ***************************************************************************/
81
82 struct rfc822t {
83 struct rfc822token *tokens;
84 int ntokens;
85 } ;
86
87 struct rfc822t *rfc822t_alloc(const char *p,
88 void (*err_func)(const char *, int)); /* Parse addresses */
89
90 struct rfc822t *rfc822t_alloc_new(const char *p,
91 void (*err_func)(const char *, int, void *), void *);
92 /* Parse addresses */
93
94 void rfc822t_free(struct rfc822t *); /* Free rfc822 structure */
95
96 void rfc822tok_print(const struct rfc822token *, void (*)(char, void *), void *);
97 /* Print the tokens */
98
99 /***************************************************************************
100 **
101 ** rfc822 addresses
102 **
103 ***************************************************************************/
104
105 struct rfc822a {
106 struct rfc822addr *addrs;
107 int naddrs;
108 } ;
109
110 struct rfc822a *rfc822a_alloc(struct rfc822t *);
111 void rfc822a_free(struct rfc822a *); /* Free rfc822 structure */
112
113 void rfc822_deladdr(struct rfc822a *, int);
114
115 /* rfc822_print "unparses" the rfc822 structure. Each rfc822addr is "printed"
116 (via the attached function). NOTE: instead of separating addresses by
117 commas, the print_separator function is called.
118 */
119
120 void rfc822_print(const struct rfc822a *a,
121 void (*print_func)(char, void *),
122 void (*print_separator)(const char *, void *), void *);
123
124 /* rfc822_print_common is an internal function */
125
126 void rfc822_print_common(const struct rfc822a *a,
127 char *(*decode_func)(const char *, const char *),
128 const char *chset,
129 void (*print_func)(char, void *),
130 void (*print_separator)(const char *, void *), void *);
131
132 /* Another unparser, except that only the raw addresses are extracted,
133 and each address is followed by a newline character */
134
135 void rfc822_addrlist(const struct rfc822a *, void (*print_func)(char, void *),
136 void *);
137
138 /* Now, just the comments. If comments not given, the address. */
139 void rfc822_namelist(const struct rfc822a *, void (*print_func)(char, void *),
140 void *);
141
142 /* Unparse an individual name/addr from a list of addresses. If the given
143 index points to some syntactical fluff, this is a noop */
144
145 void rfc822_prname(const struct rfc822a *, int, void (*)(char, void *), void *);
146 void rfc822_praddr(const struct rfc822a *, int, void (*)(char, void *), void *);
147
148 /* Like rfc822_prname, except that we'll also print the legacy format
149 ** of a list designation.
150 */
151
152 void rfc822_prname_orlist(const struct rfc822a *, int,
153 void (*)(char, void *), void *);
154
155 /* Extra functions */
156
157 char *rfc822_gettok(const struct rfc822token *);
158 char *rfc822_getaddr(const struct rfc822a *, int);
159 char *rfc822_getname(const struct rfc822a *, int);
160 char *rfc822_getname_orlist(const struct rfc822a *, int);
161 char *rfc822_getaddrs(const struct rfc822a *);
162 char *rfc822_getaddrs_wrap(const struct rfc822a *, int);
163
164 void rfc822_mkdate_buf(time_t, char *);
165 const char *rfc822_mkdate(time_t);
166 time_t rfc822_parsedt(const char *);
167
168 #define CORESUBJ_RE 1
169 #define CORESUBJ_FWD 2
170
171 char *rfc822_coresubj(const char *, int *);
172 char *rfc822_coresubj_nouc(const char *, int *);
173 char *rfc822_coresubj_keepblobs(const char *s);
174
175 #ifdef __cplusplus
176 }
177 #endif
178
179 #endif