Mercurial > dovecot > core-2.2
annotate src/lib-mail/message-address.c @ 3863:55df57c028d4 HEAD
Added "bool" type and changed all ints that were used as booleans to bool.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 13 Jan 2006 22:25:57 +0200 |
parents | 51bf11f92c07 |
children | 210bb1ff0e6e |
rev | line source |
---|---|
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
1 /* Copyright (C) 2002-2005 Timo Sirainen */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "str.h" |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
5 #include "message-parser.h" |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "message-address.h" |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
7 #include "rfc822-parser.h" |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
9 struct message_address_parser_context { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
10 pool_t pool; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
11 struct rfc822_parser_context parser; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
12 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
13 struct message_address *first_addr, *last_addr, addr; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
14 string_t *str; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
15 }; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
16 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
17 static void add_address(struct message_address_parser_context *ctx) |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 struct message_address *addr; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
21 addr = p_new(ctx->pool, struct message_address, 1); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
22 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
23 memcpy(addr, &ctx->addr, sizeof(ctx->addr)); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
24 memset(&ctx->addr, 0, sizeof(ctx->addr)); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
25 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
26 if (ctx->first_addr == NULL) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
27 ctx->first_addr = addr; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
28 else |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
29 ctx->last_addr->next = addr; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
30 ctx->last_addr = addr; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
31 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
32 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
33 static int parse_local_part(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
34 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
35 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
36 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
37 /* |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
38 local-part = dot-atom / quoted-string / obs-local-part |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
39 obs-local-part = word *("." word) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
40 */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
41 if (ctx->parser.data == ctx->parser.end) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
42 return 0; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
43 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
44 str_truncate(ctx->str, 0); |
3275
7892e3febad6
local-part in message address can be quoted-string as well.
Timo Sirainen <tss@iki.fi>
parents:
3225
diff
changeset
|
45 if (*ctx->parser.data == '"') |
7892e3febad6
local-part in message address can be quoted-string as well.
Timo Sirainen <tss@iki.fi>
parents:
3225
diff
changeset
|
46 ret = rfc822_parse_quoted_string(&ctx->parser, ctx->str); |
7892e3febad6
local-part in message address can be quoted-string as well.
Timo Sirainen <tss@iki.fi>
parents:
3225
diff
changeset
|
47 else |
7892e3febad6
local-part in message address can be quoted-string as well.
Timo Sirainen <tss@iki.fi>
parents:
3225
diff
changeset
|
48 ret = rfc822_parse_dot_atom(&ctx->parser, ctx->str); |
7892e3febad6
local-part in message address can be quoted-string as well.
Timo Sirainen <tss@iki.fi>
parents:
3225
diff
changeset
|
49 if (ret < 0) |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
50 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
51 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
52 ctx->addr.mailbox = p_strdup(ctx->pool, str_c(ctx->str)); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
53 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
54 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
55 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
56 static int parse_domain(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
57 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
58 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
59 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
60 str_truncate(ctx->str, 0); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
61 if ((ret = rfc822_parse_domain(&ctx->parser, ctx->str)) < 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
62 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
63 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
64 ctx->addr.domain = p_strdup(ctx->pool, str_c(ctx->str)); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
65 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
66 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
67 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
68 static int parse_domain_list(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
69 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
70 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
71 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
72 /* obs-domain-list = "@" domain *(*(CFWS / "," ) [CFWS] "@" domain) */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
73 str_truncate(ctx->str, 0); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
74 for (;;) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
75 if (ctx->parser.data == ctx->parser.end) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
76 return 0; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
77 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
78 if (*ctx->parser.data != '@') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
79 break; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
80 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
81 if (str_len(ctx->str) > 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
82 str_append_c(ctx->str, ','); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
83 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
84 str_append_c(ctx->str, '@'); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
85 if ((ret = rfc822_parse_domain(&ctx->parser, ctx->str)) <= 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
86 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
87 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
88 while (rfc822_skip_lwsp(&ctx->parser) && |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
89 *ctx->parser.data == ',') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
90 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
91 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
92 ctx->addr.route = p_strdup(ctx->pool, str_c(ctx->str)); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
93 return 1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
94 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
95 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
96 static int parse_angle_addr(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
97 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
98 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
99 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
100 /* "<" [ "@" route ":" ] local-part "@" domain ">" */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
101 i_assert(*ctx->parser.data == '<'); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
102 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
103 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
104 if ((ret = rfc822_skip_lwsp(&ctx->parser)) <= 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
105 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
106 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
107 if (*ctx->parser.data == '@') { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
108 if (parse_domain_list(ctx) <= 0 || *ctx->parser.data != ':') { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
109 ctx->addr.route = p_strdup(ctx->pool, "INVALID_ROUTE"); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
110 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
111 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
112 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
113 if ((ret = rfc822_skip_lwsp(&ctx->parser)) <= 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
114 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
115 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
116 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
117 if ((ret = parse_local_part(ctx)) <= 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
118 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
119 if (*ctx->parser.data == '@') { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
120 if ((ret = parse_domain(ctx)) <= 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
121 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
122 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
123 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
124 if (*ctx->parser.data != '>') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
125 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
126 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
127 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
128 return rfc822_skip_lwsp(&ctx->parser); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
129 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
130 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
131 static int parse_name_addr(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
132 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
133 /* |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
134 name-addr = [display-name] angle-addr |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
135 display-name = phrase |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
136 */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
137 str_truncate(ctx->str, 0); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
138 if (rfc822_parse_phrase(&ctx->parser, ctx->str) <= 0 || |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
139 *ctx->parser.data != '<') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
140 return -1; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
142 ctx->addr.name = p_strdup(ctx->pool, str_c(ctx->str)); |
3496
51bf11f92c07
If address doesn't have a name, return it as NULL instead of "". This fixes
Timo Sirainen <tss@iki.fi>
parents:
3275
diff
changeset
|
143 if (*ctx->addr.name == '\0') { |
51bf11f92c07
If address doesn't have a name, return it as NULL instead of "". This fixes
Timo Sirainen <tss@iki.fi>
parents:
3275
diff
changeset
|
144 /* Cope with "<address>" without display name */ |
51bf11f92c07
If address doesn't have a name, return it as NULL instead of "". This fixes
Timo Sirainen <tss@iki.fi>
parents:
3275
diff
changeset
|
145 ctx->addr.name = NULL; |
51bf11f92c07
If address doesn't have a name, return it as NULL instead of "". This fixes
Timo Sirainen <tss@iki.fi>
parents:
3275
diff
changeset
|
146 } |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
147 if (parse_angle_addr(ctx) < 0) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
148 /* broken */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
149 ctx->addr.domain = p_strdup(ctx->pool, "SYNTAX_ERROR"); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
150 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
151 return ctx->parser.data != ctx->parser.end; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
152 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
153 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
154 static int parse_addr_spec(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
155 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
156 /* addr-spec = local-part "@" domain */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
157 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
158 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
159 str_truncate(ctx->parser.last_comment, 0); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
160 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
161 if ((ret = parse_local_part(ctx)) < 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
162 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
163 if (ret > 0 && *ctx->parser.data == '@') { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
164 if ((ret = parse_domain(ctx)) < 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
165 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
166 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
167 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
168 if (str_len(ctx->parser.last_comment) > 0) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
169 ctx->addr.name = |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
170 p_strdup(ctx->pool, str_c(ctx->parser.last_comment)); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
171 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
172 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
173 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
174 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
175 static int parse_mailbox(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
176 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
177 const unsigned char *start; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
178 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
179 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
180 if (ctx->parser.data == ctx->parser.end) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
181 return 0; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
182 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
183 /* mailbox = name-addr / addr-spec */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
184 start = ctx->parser.data; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
185 if ((ret = parse_name_addr(ctx)) < 0) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
186 /* nope, should be addr-spec */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
187 ctx->parser.data = start; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
188 if ((ret = parse_addr_spec(ctx)) < 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
189 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
190 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
191 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
192 if (ctx->addr.mailbox == NULL) |
3201
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
193 ctx->addr.mailbox = p_strdup(ctx->pool, "MISSING_MAILBOX"); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
194 if (ctx->addr.domain == NULL) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
195 ctx->addr.domain = p_strdup(ctx->pool, "MISSING_DOMAIN"); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
196 add_address(ctx); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
197 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
198 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
199 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
200 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
201 static int parse_mailbox_list(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
202 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
203 int ret; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
205 /* mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
206 while ((ret = parse_mailbox(ctx)) > 0) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
207 if (*ctx->parser.data != ',') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
208 break; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
209 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
210 rfc822_skip_lwsp(&ctx->parser); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
211 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
212 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
213 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
214 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
215 static int parse_group(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
216 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
217 /* |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
218 group = display-name ":" [mailbox-list / CFWS] ";" [CFWS] |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
219 display-name = phrase |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
220 */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
221 str_truncate(ctx->str, 0); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
222 if (rfc822_parse_phrase(&ctx->parser, ctx->str) <= 0 || |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
223 *ctx->parser.data != ':') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
224 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
225 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
226 /* from now on don't return -1 even if there are problems, so that |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
227 the caller knows this is a group */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
228 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
229 (void)rfc822_skip_lwsp(&ctx->parser); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
230 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
231 ctx->addr.mailbox = p_strdup(ctx->pool, str_c(ctx->str)); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
232 add_address(ctx); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
233 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
234 if (parse_mailbox_list(ctx) > 0) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
235 if (*ctx->parser.data == ';') { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
236 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
237 (void)rfc822_skip_lwsp(&ctx->parser); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
238 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
239 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
240 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
241 add_address(ctx); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
242 return 1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
243 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
244 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
245 static int parse_address(struct message_address_parser_context *ctx) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
246 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
247 const unsigned char *start; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
248 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
249 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
250 /* address = mailbox / group */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
251 start = ctx->parser.data; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
252 if ((ret = parse_group(ctx)) < 0) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
253 /* not a group, try mailbox */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
254 ctx->parser.data = start; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
255 ret = parse_mailbox(ctx); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
256 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
257 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
258 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
259 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
260 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
261 static void parse_address_list(struct message_address_parser_context *ctx, |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
262 unsigned int max_addresses) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
263 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
264 /* address-list = (address *("," address)) / obs-addr-list */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
265 while (max_addresses-- > 0 && parse_address(ctx) > 0) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
266 if (*ctx->parser.data != ',') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
267 break; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
268 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
269 if (rfc822_skip_lwsp(&ctx->parser) <= 0) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
270 break; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
271 } |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 } |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 struct message_address * |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
275 message_address_parse(pool_t pool, const unsigned char *data, size_t size, |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
276 unsigned int max_addresses) |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 { |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
278 struct message_address_parser_context ctx; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 |
3044
2d4630db33fd
Allow giving data stack pool for message_address_parse()
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
280 if (!pool->datastack_pool) |
2d4630db33fd
Allow giving data stack pool for message_address_parse()
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
281 t_push(); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
282 memset(&ctx, 0, sizeof(ctx)); |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
283 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
284 rfc822_parser_init(&ctx.parser, data, size, t_str_new(128)); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
285 ctx.pool = pool; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
286 ctx.str = t_str_new(128); |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 |
3225
43d862951f90
Skip LWSP at the beginning of address.
Timo Sirainen <tss@iki.fi>
parents:
3201
diff
changeset
|
288 rfc822_skip_lwsp(&ctx.parser); |
43d862951f90
Skip LWSP at the beginning of address.
Timo Sirainen <tss@iki.fi>
parents:
3201
diff
changeset
|
289 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
290 (void)parse_address_list(&ctx, max_addresses); |
3044
2d4630db33fd
Allow giving data stack pool for message_address_parse()
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
291 if (!pool->datastack_pool) |
2d4630db33fd
Allow giving data stack pool for message_address_parse()
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
292 t_pop(); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
293 return ctx.first_addr; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 } |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
295 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
296 void message_address_write(string_t *str, const struct message_address *addr) |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
297 { |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3496
diff
changeset
|
298 bool first = TRUE, in_group = FALSE; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
299 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
300 /* a) mailbox@domain |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
301 b) name <@route:mailbox@domain> |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
302 c) group: .. ; */ |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
303 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
304 while (addr != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
305 if (first) |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
306 first = FALSE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
307 else |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
308 str_append(str, ", "); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
309 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
310 if (addr->domain == NULL) { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
311 if (!in_group) { |
3201
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
312 /* beginning of group. mailbox is the group |
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
313 name, others are NULL. */ |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
314 if (addr->mailbox != NULL) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
315 str_append(str, addr->mailbox); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
316 str_append(str, ": "); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
317 first = TRUE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
318 } else { |
3201
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
319 /* end of group. all fields should be NULL. */ |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
320 i_assert(addr->mailbox == NULL); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
321 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
322 /* cut out the ", " */ |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
323 str_truncate(str, str_len(str)-2); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
324 str_append_c(str, ';'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
325 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
326 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
327 in_group = !in_group; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
328 } else if ((addr->name == NULL || *addr->name == '\0') && |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
329 addr->route == NULL) { |
3201
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
330 /* no name and no route. use only mailbox@domain */ |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
331 i_assert(addr->mailbox != NULL); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
332 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
333 str_append(str, addr->mailbox); |
3201
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
334 str_append_c(str, '@'); |
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
335 str_append(str, addr->domain); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
336 } else { |
3201
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
337 /* name and/or route. use full <mailbox@domain> Name */ |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
338 i_assert(addr->mailbox != NULL); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
339 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
340 if (addr->name != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
341 str_append(str, addr->name); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
342 str_append_c(str, ' '); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
343 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
344 str_append_c(str, '<'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
345 if (addr->route != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
346 str_append_c(str, '@'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
347 str_append(str, addr->route); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
348 str_append_c(str, ':'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
349 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
350 str_append(str, addr->mailbox); |
3201
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
351 str_append_c(str, '@'); |
2bf86099376e
If mailbox name was missing from message address, we didn't set it to
Timo Sirainen <tss@iki.fi>
parents:
3044
diff
changeset
|
352 str_append(str, addr->domain); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
353 str_append_c(str, '>'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
354 } |
1279
b14d1f375039
message_address_write() didn't work.
Timo Sirainen <tss@iki.fi>
parents:
1278
diff
changeset
|
355 |
b14d1f375039
message_address_write() didn't work.
Timo Sirainen <tss@iki.fi>
parents:
1278
diff
changeset
|
356 addr = addr->next; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
357 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
358 } |