Mercurial > dovecot > core-2.2
annotate src/lib-mail/message-address.c @ 3044:2d4630db33fd HEAD
Allow giving data stack pool for message_address_parse()
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 06 Jan 2005 22:50:36 +0200 |
parents | d6910d273852 |
children | 2bf86099376e |
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); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
45 if ((ret = rfc822_parse_dot_atom(&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
|
46 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
47 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
48 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
|
49 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
50 } |
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 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
|
53 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
54 int ret; |
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 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
|
57 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
|
58 return -1; |
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 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
|
61 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
62 } |
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 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
|
65 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
66 int ret; |
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 /* 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
|
69 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
|
70 for (;;) { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
71 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
|
72 return 0; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
73 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
74 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
|
75 break; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
76 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
77 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
|
78 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
|
79 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
80 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
|
81 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
|
82 return ret; |
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 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
|
85 *ctx->parser.data == ',') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
86 ctx->parser.data++; |
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 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
|
89 return 1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
90 } |
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 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
|
93 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
94 int ret; |
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 /* "<" [ "@" 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
|
97 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
|
98 ctx->parser.data++; |
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 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
|
101 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
102 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
107 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
108 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 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
|
110 return ret; |
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 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
113 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
|
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 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
|
116 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
|
117 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
118 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
119 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
120 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
|
121 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
122 ctx->parser.data++; |
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 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
|
125 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
126 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
127 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
|
128 { |
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 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
|
131 display-name = phrase |
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 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
|
134 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
|
135 *ctx->parser.data != '<') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
136 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
|
137 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
138 ctx->addr.name = 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
|
139 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
|
140 /* broken */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
141 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
|
142 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
143 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
|
144 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
145 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
146 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
|
147 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
148 /* 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
|
149 int ret; |
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 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
|
152 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
153 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
|
154 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
155 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
|
156 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
|
157 return 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 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
160 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
|
161 ctx->addr.name = |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
162 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
|
163 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
164 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
165 } |
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 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
|
168 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
169 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
|
170 int ret; |
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 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
|
173 return 0; |
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 /* 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
|
176 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
|
177 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
|
178 /* 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
|
179 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
|
180 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
|
181 return -1; |
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 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
184 if (ctx->addr.mailbox == NULL) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
185 ctx->addr.domain = p_strdup(ctx->pool, "MISSING_MAILBOX"); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
186 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
|
187 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
|
188 add_address(ctx); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
189 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
190 return ret; |
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 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
193 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
|
194 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
195 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
|
196 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
197 /* 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
|
198 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
|
199 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
|
200 break; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
201 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
202 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
|
203 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
204 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
205 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
206 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
207 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
|
208 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
209 /* |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
210 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
|
211 display-name = phrase |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
212 */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
213 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
|
214 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
|
215 *ctx->parser.data != ':') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
216 return -1; |
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 /* 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
|
219 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
|
220 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
221 (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
|
222 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
223 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
|
224 add_address(ctx); |
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 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
|
227 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
|
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 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
232 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
233 add_address(ctx); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
234 return 1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
235 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
236 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
237 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
|
238 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
239 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
|
240 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
241 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
242 /* address = mailbox / group */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
243 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
|
244 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
|
245 /* 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
|
246 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
|
247 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
|
248 } |
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 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
251 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
252 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
253 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
|
254 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
|
255 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
256 /* 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
|
257 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
|
258 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
|
259 break; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
260 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
261 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
|
262 break; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
263 } |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 } |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 struct message_address * |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
267 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
|
268 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
|
269 { |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
270 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
|
271 |
3044
2d4630db33fd
Allow giving data stack pool for message_address_parse()
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
272 if (!pool->datastack_pool) |
2d4630db33fd
Allow giving data stack pool for message_address_parse()
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
273 t_push(); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
274 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
|
275 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
276 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
|
277 ctx.pool = pool; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
278 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
|
279 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
280 (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
|
281 if (!pool->datastack_pool) |
2d4630db33fd
Allow giving data stack pool for message_address_parse()
Timo Sirainen <tss@iki.fi>
parents:
3039
diff
changeset
|
282 t_pop(); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
283 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
|
284 } |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
286 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
|
287 { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
288 int first = TRUE, in_group = FALSE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
289 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
290 /* a) mailbox@domain |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
291 b) name <@route:mailbox@domain> |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
292 c) group: .. ; */ |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
293 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
294 while (addr != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
295 if (first) |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
296 first = FALSE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
297 else |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
298 str_append(str, ", "); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
299 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
300 if (addr->domain == NULL) { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
301 if (!in_group) { |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
302 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
|
303 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
|
304 str_append(str, ": "); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
305 first = TRUE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
306 } else { |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
307 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
|
308 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
309 /* cut out the ", " */ |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
310 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
|
311 str_append_c(str, ';'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
312 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
313 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
314 in_group = !in_group; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
315 } 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
|
316 addr->route == NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
317 i_assert(addr->mailbox != NULL); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
318 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
319 str_append(str, addr->mailbox); |
1631
c2f5d02965ca
Don't crash if there's no domain in address
Timo Sirainen <tss@iki.fi>
parents:
1279
diff
changeset
|
320 if (addr->domain != NULL) { |
c2f5d02965ca
Don't crash if there's no domain in address
Timo Sirainen <tss@iki.fi>
parents:
1279
diff
changeset
|
321 str_append_c(str, '@'); |
c2f5d02965ca
Don't crash if there's no domain in address
Timo Sirainen <tss@iki.fi>
parents:
1279
diff
changeset
|
322 str_append(str, addr->domain); |
c2f5d02965ca
Don't crash if there's no domain in address
Timo Sirainen <tss@iki.fi>
parents:
1279
diff
changeset
|
323 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
324 } else { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
325 i_assert(addr->mailbox != NULL); |
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 if (addr->name != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
328 str_append(str, addr->name); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
329 str_append_c(str, ' '); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
330 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
331 str_append_c(str, '<'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
332 if (addr->route != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
333 str_append_c(str, '@'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
334 str_append(str, addr->route); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
335 str_append_c(str, ':'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
336 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
337 str_append(str, addr->mailbox); |
1631
c2f5d02965ca
Don't crash if there's no domain in address
Timo Sirainen <tss@iki.fi>
parents:
1279
diff
changeset
|
338 if (addr->domain != NULL) { |
c2f5d02965ca
Don't crash if there's no domain in address
Timo Sirainen <tss@iki.fi>
parents:
1279
diff
changeset
|
339 str_append_c(str, '@'); |
c2f5d02965ca
Don't crash if there's no domain in address
Timo Sirainen <tss@iki.fi>
parents:
1279
diff
changeset
|
340 str_append(str, addr->domain); |
c2f5d02965ca
Don't crash if there's no domain in address
Timo Sirainen <tss@iki.fi>
parents:
1279
diff
changeset
|
341 } |
988
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 } |
1279
b14d1f375039
message_address_write() didn't work.
Timo Sirainen <tss@iki.fi>
parents:
1278
diff
changeset
|
344 |
b14d1f375039
message_address_write() didn't work.
Timo Sirainen <tss@iki.fi>
parents:
1278
diff
changeset
|
345 addr = addr->next; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
346 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
347 } |