Mercurial > dovecot > core-2.2
annotate src/lib-mail/message-address.c @ 22713:cb108f786fb4
Updated copyright notices to include the year 2018.
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Mon, 01 Jan 2018 22:42:08 +0100 |
parents | 2a979ce1885d |
children | f578acb188d6 |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22403
diff
changeset
|
1 /* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */ |
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" |
22158
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
5 #include "strescape.h" |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
6 #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
|
7 #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
|
8 #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
|
9 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
10 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
|
11 pool_t pool; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
12 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
|
13 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
14 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
|
15 string_t *str; |
4635
210bb1ff0e6e
Added fill_missing parameter to message_address_parse() which specifies if
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
16 |
210bb1ff0e6e
Added fill_missing parameter to message_address_parse() which specifies if
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
17 bool fill_missing; |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
18 }; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
19 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
20 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
|
21 { |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 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
|
23 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
24 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
|
25 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
26 memcpy(addr, &ctx->addr, sizeof(ctx->addr)); |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21211
diff
changeset
|
27 i_zero(&ctx->addr); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
28 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
29 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
|
30 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
|
31 else |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
32 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
|
33 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
|
34 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
35 |
22158
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
36 /* quote with "" and escape all '\', '"' and "'" characters if need */ |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
37 static void str_append_maybe_escape(string_t *dest, const char *cstr, bool escape_dot) |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
38 { |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
39 const char *p; |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
40 |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
41 /* see if we need to quote it */ |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
42 for (p = cstr; *p != '\0'; p++) { |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
43 if (!IS_ATEXT(*p) && (escape_dot || *p != '.')) |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
44 break; |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
45 } |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
46 |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
47 if (*p == '\0') { |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
48 str_append_data(dest, cstr, (size_t) (p - cstr)); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
49 return; |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
50 } |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
51 |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
52 /* see if we need to escape it */ |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
53 for (p = cstr; *p != '\0'; p++) { |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
54 if (IS_ESCAPED_CHAR(*p)) |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
55 break; |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
56 } |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
57 |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
58 if (*p == '\0') { |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
59 /* only quote */ |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
60 str_append_c(dest, '"'); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
61 str_append_data(dest, cstr, (size_t) (p - cstr)); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
62 str_append_c(dest, '"'); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
63 return; |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
64 } |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
65 |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
66 /* quote and escape */ |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
67 str_append_c(dest, '"'); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
68 str_append_data(dest, cstr, (size_t) (p - cstr)); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
69 |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
70 for (; *p != '\0'; p++) { |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
71 if (IS_ESCAPED_CHAR(*p)) |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
72 str_append_c(dest, '\\'); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
73 str_append_c(dest, *p); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
74 } |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
75 |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
76 str_append_c(dest, '"'); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
77 } |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
78 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
79 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
|
80 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
81 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
82 |
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 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
|
85 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
|
86 */ |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
87 i_assert(ctx->parser.data != ctx->parser.end); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
88 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 else |
7892e3febad6
local-part in message address can be quoted-string as well.
Timo Sirainen <tss@iki.fi>
parents:
3225
diff
changeset
|
93 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
|
94 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
|
95 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
96 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
97 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
|
98 return 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 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
101 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
|
102 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
103 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
104 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
105 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
|
106 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
|
107 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
108 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
109 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
|
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 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
|
114 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
115 int ret; |
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 /* 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
|
118 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
|
119 for (;;) { |
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 == ctx->parser.end) |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
121 return 0; |
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 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
|
124 break; |
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 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
|
127 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
|
128 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
129 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
|
130 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
|
131 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
132 |
8202
79b29796d239
message address parser: Fixed some assert-crashes.
Timo Sirainen <tss@iki.fi>
parents:
8171
diff
changeset
|
133 while (rfc822_skip_lwsp(&ctx->parser) > 0 && |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
134 *ctx->parser.data == ',') |
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 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
137 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
|
138 return 1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
139 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
140 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
141 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
|
142 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
143 int ret; |
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 /* "<" [ "@" 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
|
146 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
|
147 ctx->parser.data++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
148 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
149 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
|
150 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
151 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
152 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
|
153 if (parse_domain_list(ctx) <= 0 || *ctx->parser.data != ':') { |
22168
fb24444dd968
lib-mail: message_address_parse() - Add INVALID_ROUTE/SYNTAX_ERROR only if fill_missing==TRUE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22167
diff
changeset
|
154 if (ctx->fill_missing) |
fb24444dd968
lib-mail: message_address_parse() - Add INVALID_ROUTE/SYNTAX_ERROR only if fill_missing==TRUE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22167
diff
changeset
|
155 ctx->addr.route = "INVALID_ROUTE"; |
22173
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
156 if (ctx->parser.data == ctx->parser.end) |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
157 return -1; |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
158 /* try to continue anyway */ |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
159 } else { |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
160 ctx->parser.data++; |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
161 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
162 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
|
163 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
164 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
165 |
22173
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
166 if (*ctx->parser.data == '>') { |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
167 /* <> address isn't valid */ |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
168 } else { |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
169 if ((ret = parse_local_part(ctx)) <= 0) |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
170 return ret; |
22173
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
171 if (*ctx->parser.data == '@') { |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
172 if ((ret = parse_domain(ctx)) <= 0) |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
173 return ret; |
ce23a868bf13
lib-mail: message_address_parse() - don't stop at <> when parsing address lists
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22172
diff
changeset
|
174 } |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
175 } |
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 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
|
178 return -1; |
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++; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
180 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
181 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
|
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 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
|
185 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
186 /* |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
187 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
|
188 display-name = phrase |
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 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
|
191 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
|
192 *ctx->parser.data != '<') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
193 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
|
194 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
195 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
|
196 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
|
197 /* 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
|
198 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
|
199 } |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
200 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
|
201 /* broken */ |
22168
fb24444dd968
lib-mail: message_address_parse() - Add INVALID_ROUTE/SYNTAX_ERROR only if fill_missing==TRUE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22167
diff
changeset
|
202 if (ctx->fill_missing) |
fb24444dd968
lib-mail: message_address_parse() - Add INVALID_ROUTE/SYNTAX_ERROR only if fill_missing==TRUE
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22167
diff
changeset
|
203 ctx->addr.domain = "SYNTAX_ERROR"; |
8169
cb01142bb9e8
message address parser: Check better if adress is invalid and set invalid_syntax.
Timo Sirainen <tss@iki.fi>
parents:
8167
diff
changeset
|
204 ctx->addr.invalid_syntax = TRUE; |
3039
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 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
|
207 } |
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 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
|
210 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
211 /* addr-spec = local-part "@" domain */ |
22175
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
212 int ret, ret2 = -2; |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
213 |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
214 i_assert(ctx->parser.data != ctx->parser.end); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
215 |
22170
293249bf0b5a
lib-mail: message_address_parse() - Remove unnecessary NULL checks
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22168
diff
changeset
|
216 str_truncate(ctx->parser.last_comment, 0); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
217 |
22175
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
218 bool quoted_string = *ctx->parser.data == '"'; |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
219 ret = parse_local_part(ctx); |
22156
b37395fd83cd
lib-mail: parse_addr_spec: Email address without local-part is invalid
Pali Rohár <pali.rohar@gmail.com>
parents:
22155
diff
changeset
|
220 if (ret <= 0) { |
b37395fd83cd
lib-mail: parse_addr_spec: Email address without local-part is invalid
Pali Rohár <pali.rohar@gmail.com>
parents:
22155
diff
changeset
|
221 /* end of input or parsing local-part failed */ |
b37395fd83cd
lib-mail: parse_addr_spec: Email address without local-part is invalid
Pali Rohár <pali.rohar@gmail.com>
parents:
22155
diff
changeset
|
222 ctx->addr.invalid_syntax = TRUE; |
b37395fd83cd
lib-mail: parse_addr_spec: Email address without local-part is invalid
Pali Rohár <pali.rohar@gmail.com>
parents:
22155
diff
changeset
|
223 } |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
224 if (ret != 0 && *ctx->parser.data == '@') { |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
225 ret2 = parse_domain(ctx); |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
226 if (ret2 <= 0) |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
227 ret = ret2; |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
228 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
229 |
22170
293249bf0b5a
lib-mail: message_address_parse() - Remove unnecessary NULL checks
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22168
diff
changeset
|
230 if (str_len(ctx->parser.last_comment) > 0) |
293249bf0b5a
lib-mail: message_address_parse() - Remove unnecessary NULL checks
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22168
diff
changeset
|
231 ctx->addr.name = p_strdup(ctx->pool, str_c(ctx->parser.last_comment)); |
22175
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
232 else if (ret2 == -2) { |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
233 /* So far we've read user without @domain and without |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
234 (Display Name). We'll assume that a single "user" (already |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
235 read into addr.mailbox) is a mailbox, but if it's followed |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
236 by anything else it's a display-name. */ |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
237 str_append_c(ctx->str, ' '); |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
238 size_t orig_str_len = str_len(ctx->str); |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
239 (void)rfc822_parse_phrase(&ctx->parser, ctx->str); |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
240 if (str_len(ctx->str) != orig_str_len) { |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
241 ctx->addr.mailbox = NULL; |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
242 ctx->addr.name = p_strdup(ctx->pool, str_c(ctx->str)); |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
243 } else { |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
244 if (!quoted_string) |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
245 ctx->addr.domain = ""; |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
246 } |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
247 ctx->addr.invalid_syntax = TRUE; |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
248 ret = -1; |
755d206606df
lib-mail: message_address_parse() - Handle invalid standalone phrases better
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22173
diff
changeset
|
249 } |
3039
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 |
8167
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
253 static void add_fixed_address(struct message_address_parser_context *ctx) |
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
254 { |
8169
cb01142bb9e8
message address parser: Check better if adress is invalid and set invalid_syntax.
Timo Sirainen <tss@iki.fi>
parents:
8167
diff
changeset
|
255 if (ctx->addr.mailbox == NULL) { |
8167
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
256 ctx->addr.mailbox = !ctx->fill_missing ? "" : "MISSING_MAILBOX"; |
8169
cb01142bb9e8
message address parser: Check better if adress is invalid and set invalid_syntax.
Timo Sirainen <tss@iki.fi>
parents:
8167
diff
changeset
|
257 ctx->addr.invalid_syntax = TRUE; |
cb01142bb9e8
message address parser: Check better if adress is invalid and set invalid_syntax.
Timo Sirainen <tss@iki.fi>
parents:
8167
diff
changeset
|
258 } |
22176
fc301d74f851
lib-mail: message_address_parse() - Fix fill_missing==TRUE handling
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22175
diff
changeset
|
259 if (ctx->addr.domain == NULL || ctx->addr.domain[0] == '\0') { |
8167
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
260 ctx->addr.domain = !ctx->fill_missing ? "" : "MISSING_DOMAIN"; |
8169
cb01142bb9e8
message address parser: Check better if adress is invalid and set invalid_syntax.
Timo Sirainen <tss@iki.fi>
parents:
8167
diff
changeset
|
261 ctx->addr.invalid_syntax = TRUE; |
cb01142bb9e8
message address parser: Check better if adress is invalid and set invalid_syntax.
Timo Sirainen <tss@iki.fi>
parents:
8167
diff
changeset
|
262 } |
8167
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
263 add_address(ctx); |
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
264 } |
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
265 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
266 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
|
267 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
268 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
|
269 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
270 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
271 /* 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
|
272 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
|
273 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
|
274 /* 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
|
275 ctx->parser.data = start; |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
276 ret = parse_addr_spec(ctx); |
22157
19734488e58a
lib-mail: parse_mailbox: Set display name instead mailbox when parsing failed
Pali Rohár <pali.rohar@gmail.com>
parents:
22156
diff
changeset
|
277 if (ctx->addr.invalid_syntax && ctx->addr.name == NULL && |
22160
79a84a2282ef
lib-mail: Fixed to 91fdb25b5
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22158
diff
changeset
|
278 ctx->addr.mailbox != NULL && ctx->addr.domain == NULL) { |
22157
19734488e58a
lib-mail: parse_mailbox: Set display name instead mailbox when parsing failed
Pali Rohár <pali.rohar@gmail.com>
parents:
22156
diff
changeset
|
279 ctx->addr.name = ctx->addr.mailbox; |
19734488e58a
lib-mail: parse_mailbox: Set display name instead mailbox when parsing failed
Pali Rohár <pali.rohar@gmail.com>
parents:
22156
diff
changeset
|
280 ctx->addr.mailbox = NULL; |
19734488e58a
lib-mail: parse_mailbox: Set display name instead mailbox when parsing failed
Pali Rohár <pali.rohar@gmail.com>
parents:
22156
diff
changeset
|
281 } |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
282 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
283 |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
284 if (ret < 0) |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
285 ctx->addr.invalid_syntax = TRUE; |
8167
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
286 add_fixed_address(ctx); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
287 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
288 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
289 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
290 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
|
291 { |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
292 int ret; |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
293 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
294 /* |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
295 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
|
296 display-name = phrase |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
297 */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
298 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
|
299 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
|
300 *ctx->parser.data != ':') |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
301 return -1; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
302 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
303 /* 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
|
304 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
|
305 ctx->parser.data++; |
8202
79b29796d239
message address parser: Fixed some assert-crashes.
Timo Sirainen <tss@iki.fi>
parents:
8171
diff
changeset
|
306 if ((ret = rfc822_skip_lwsp(&ctx->parser)) <= 0) |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
307 ctx->addr.invalid_syntax = TRUE; |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
308 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
309 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
|
310 add_address(ctx); |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
311 |
8877
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
312 if (ret > 0 && *ctx->parser.data != ';') { |
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
313 for (;;) { |
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
314 /* mailbox-list = |
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
315 (mailbox *("," mailbox)) / obs-mbox-list */ |
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
316 if (parse_mailbox(ctx) <= 0) { |
22172
f9f565979ef2
lib-mail: message_address_parse() - don't stop at invalid addresses when parsing group
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22171
diff
changeset
|
317 /* broken mailbox - try to continue anyway. */ |
8877
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
318 } |
22172
f9f565979ef2
lib-mail: message_address_parse() - don't stop at invalid addresses when parsing group
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22171
diff
changeset
|
319 if (ctx->parser.data == ctx->parser.end || |
f9f565979ef2
lib-mail: message_address_parse() - don't stop at invalid addresses when parsing group
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22171
diff
changeset
|
320 *ctx->parser.data != ',') |
8877
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
321 break; |
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
322 ctx->parser.data++; |
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
323 if (rfc822_skip_lwsp(&ctx->parser) <= 0) { |
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
324 ret = -1; |
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
325 break; |
8202
79b29796d239
message address parser: Fixed some assert-crashes.
Timo Sirainen <tss@iki.fi>
parents:
8171
diff
changeset
|
326 } |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
327 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
328 } |
11036
ae8294182346
message address parser: Fixed potential problems with parsing invalid address groups.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
329 if (ret >= 0) { |
22172
f9f565979ef2
lib-mail: message_address_parse() - don't stop at invalid addresses when parsing group
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22171
diff
changeset
|
330 if (ctx->parser.data == ctx->parser.end || |
f9f565979ef2
lib-mail: message_address_parse() - don't stop at invalid addresses when parsing group
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22171
diff
changeset
|
331 *ctx->parser.data != ';') |
11036
ae8294182346
message address parser: Fixed potential problems with parsing invalid address groups.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
332 ret = -1; |
ae8294182346
message address parser: Fixed potential problems with parsing invalid address groups.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
333 else { |
ae8294182346
message address parser: Fixed potential problems with parsing invalid address groups.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
334 ctx->parser.data++; |
ae8294182346
message address parser: Fixed potential problems with parsing invalid address groups.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
335 ret = rfc822_skip_lwsp(&ctx->parser); |
ae8294182346
message address parser: Fixed potential problems with parsing invalid address groups.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
336 } |
8877
e5658894cd13
Message address parser didn't handle empty group:; correctly.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
337 } |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
338 if (ret < 0) |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
339 ctx->addr.invalid_syntax = TRUE; |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
340 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
341 add_address(ctx); |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
342 return ret == 0 ? 0 : 1; |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
343 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
344 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
345 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
|
346 { |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
347 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
|
348 int ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
349 |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
350 /* address = mailbox / group */ |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
351 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
|
352 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
|
353 /* 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
|
354 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
|
355 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
|
356 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
357 return ret; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
358 } |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
359 |
8166
a1f6c93afbc2
message address parser: Set invalid_syntax=TRUE if the input is invalid.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
360 static int parse_address_list(struct message_address_parser_context *ctx, |
a1f6c93afbc2
message address parser: Set invalid_syntax=TRUE if the input is invalid.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
361 unsigned int max_addresses) |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
362 { |
8166
a1f6c93afbc2
message address parser: Set invalid_syntax=TRUE if the input is invalid.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
363 int ret = 0; |
a1f6c93afbc2
message address parser: Set invalid_syntax=TRUE if the input is invalid.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
364 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
365 /* address-list = (address *("," address)) / obs-addr-list */ |
21211
2d5f8e678f7c
global: Avoid loops unnecessarily decreasing below zero.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
366 while (max_addresses > 0) { |
2d5f8e678f7c
global: Avoid loops unnecessarily decreasing below zero.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
19552
diff
changeset
|
367 max_addresses--; |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
368 if ((ret = parse_address(ctx)) == 0) |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
369 break; |
22171
7bb6969f1f08
lib-mail: message_address_parse() - Fix reading out-of-bounds read on invalid input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22170
diff
changeset
|
370 if (ctx->parser.data == ctx->parser.end || |
7bb6969f1f08
lib-mail: message_address_parse() - Fix reading out-of-bounds read on invalid input
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22170
diff
changeset
|
371 *ctx->parser.data != ',') { |
8166
a1f6c93afbc2
message address parser: Set invalid_syntax=TRUE if the input is invalid.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
372 ret = -1; |
a1f6c93afbc2
message address parser: Set invalid_syntax=TRUE if the input is invalid.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
373 break; |
a1f6c93afbc2
message address parser: Set invalid_syntax=TRUE if the input is invalid.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
374 } |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
375 ctx->parser.data++; |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
376 if ((ret = rfc822_skip_lwsp(&ctx->parser)) <= 0) { |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
377 if (ret < 0) { |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
378 /* ends with some garbage */ |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
379 add_fixed_address(ctx); |
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
380 } |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
381 break; |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
382 } |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
383 } |
8166
a1f6c93afbc2
message address parser: Set invalid_syntax=TRUE if the input is invalid.
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
384 return ret; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
385 } |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
386 |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
387 static struct message_address * |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
388 message_address_parse_real(pool_t pool, const unsigned char *data, size_t size, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
389 unsigned int max_addresses, bool fill_missing) |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 { |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
391 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
|
392 |
21389
59437f8764c6
global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
21211
diff
changeset
|
393 i_zero(&ctx); |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
394 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
395 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
|
396 ctx.pool = pool; |
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
397 ctx.str = t_str_new(128); |
4635
210bb1ff0e6e
Added fill_missing parameter to message_address_parse() which specifies if
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
398 ctx.fill_missing = fill_missing; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
399 |
8321
b62e350500c9
Fixed message address assert-crashing if the entire input was invalid.
Timo Sirainen <tss@iki.fi>
parents:
8202
diff
changeset
|
400 if (rfc822_skip_lwsp(&ctx.parser) <= 0) { |
8167
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
401 /* no addresses */ |
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
402 return NULL; |
99704b6b8dde
message address parser: Handle errors better, fix crash in previous change.
Timo Sirainen <tss@iki.fi>
parents:
8166
diff
changeset
|
403 } |
8171
60b8c2609087
message address parser: More error handling improvements.
Timo Sirainen <tss@iki.fi>
parents:
8169
diff
changeset
|
404 (void)parse_address_list(&ctx, max_addresses); |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
405 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
|
406 } |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
407 |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
408 struct message_address * |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
409 message_address_parse(pool_t pool, const unsigned char *data, size_t size, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
410 unsigned int max_addresses, bool fill_missing) |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
411 { |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
412 struct message_address *addr; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
413 |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
414 if (pool->datastack_pool) { |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
415 return message_address_parse_real(pool, data, size, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
416 max_addresses, fill_missing); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
417 } |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
418 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
419 addr = message_address_parse_real(pool, data, size, |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
420 max_addresses, fill_missing); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
421 } T_END; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
422 return addr; |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
423 } |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
424 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
425 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
|
426 { |
22153
528bd5a67923
lib-mail: message_address_write: Fix generating empty group list
Pali Rohár <pali.rohar@gmail.com>
parents:
21390
diff
changeset
|
427 const char *tmp; |
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
|
428 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
|
429 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
430 /* a) mailbox@domain |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
431 b) name <@route:mailbox@domain> |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
432 c) group: .. ; */ |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
433 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
434 while (addr != NULL) { |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
435 if (first) |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
436 first = FALSE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
437 else |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
438 str_append(str, ", "); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
439 |
3039
d6910d273852
Added rfc822 parser which will probably replace message_tokenizer at some
Timo Sirainen <tss@iki.fi>
parents:
1782
diff
changeset
|
440 if (addr->domain == NULL) { |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
441 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
|
442 /* 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
|
443 name, others are NULL. */ |
22154
91278ef69de7
lib-mail: message_address_write: Fix generating group list with empty name
Pali Rohár <pali.rohar@gmail.com>
parents:
22153
diff
changeset
|
444 if (addr->mailbox != NULL && *addr->mailbox != '\0') { |
22158
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
445 /* check for MIME encoded-word */ |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
446 if (strstr(addr->mailbox, "=?") != NULL) |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
447 /* MIME encoded-word MUST NOT appear within a 'quoted-string' |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
448 so escaping and quoting of phrase is not possible, instead |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
449 use obsolete RFC822 phrase syntax which allow spaces */ |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
450 str_append(str, addr->mailbox); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
451 else |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
452 str_append_maybe_escape(str, addr->mailbox, TRUE); |
22154
91278ef69de7
lib-mail: message_address_write: Fix generating group list with empty name
Pali Rohár <pali.rohar@gmail.com>
parents:
22153
diff
changeset
|
453 } else { |
91278ef69de7
lib-mail: message_address_write: Fix generating group list with empty name
Pali Rohár <pali.rohar@gmail.com>
parents:
22153
diff
changeset
|
454 /* empty group name needs to be quoted */ |
91278ef69de7
lib-mail: message_address_write: Fix generating group list with empty name
Pali Rohár <pali.rohar@gmail.com>
parents:
22153
diff
changeset
|
455 str_append(str, "\"\""); |
91278ef69de7
lib-mail: message_address_write: Fix generating group list with empty name
Pali Rohár <pali.rohar@gmail.com>
parents:
22153
diff
changeset
|
456 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
457 str_append(str, ": "); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
458 first = TRUE; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
459 } 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
|
460 /* 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
|
461 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
|
462 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
463 /* cut out the ", " */ |
22153
528bd5a67923
lib-mail: message_address_write: Fix generating empty group list
Pali Rohár <pali.rohar@gmail.com>
parents:
21390
diff
changeset
|
464 tmp = str_c(str)+str_len(str)-2; |
528bd5a67923
lib-mail: message_address_write: Fix generating empty group list
Pali Rohár <pali.rohar@gmail.com>
parents:
21390
diff
changeset
|
465 i_assert((tmp[0] == ',' || tmp[0] == ':') && tmp[1] == ' '); |
528bd5a67923
lib-mail: message_address_write: Fix generating empty group list
Pali Rohár <pali.rohar@gmail.com>
parents:
21390
diff
changeset
|
466 if (tmp[0] == ',' && tmp[1] == ' ') |
528bd5a67923
lib-mail: message_address_write: Fix generating empty group list
Pali Rohár <pali.rohar@gmail.com>
parents:
21390
diff
changeset
|
467 str_truncate(str, str_len(str)-2); |
528bd5a67923
lib-mail: message_address_write: Fix generating empty group list
Pali Rohár <pali.rohar@gmail.com>
parents:
21390
diff
changeset
|
468 else if (tmp[0] == ':' && tmp[1] == ' ') |
528bd5a67923
lib-mail: message_address_write: Fix generating empty group list
Pali Rohár <pali.rohar@gmail.com>
parents:
21390
diff
changeset
|
469 str_truncate(str, str_len(str)-1); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
470 str_append_c(str, ';'); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
471 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
472 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
473 in_group = !in_group; |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
474 } else { |
22166
0e46fc927c94
lib-mail: message_address_write() - Always write <user@domain> as output
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22165
diff
changeset
|
475 /* "Display Name" <mailbox@domain> */ |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
476 i_assert(addr->mailbox != NULL); |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
477 |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
478 if (addr->name != NULL) { |
22158
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
479 /* check for MIME encoded-word */ |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22160
diff
changeset
|
480 if (strstr(addr->name, "=?") != NULL) |
22158
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
481 /* MIME encoded-word MUST NOT appear within a 'quoted-string' |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
482 so escaping and quoting of phrase is not possible, instead |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
483 use obsolete RFC822 phrase syntax which allow spaces */ |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
484 str_append(str, addr->name); |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
485 else |
862126b86ef1
lib-mail: message_address_write: Quote and escape strings if needed
Pali Rohár <pali.rohar@gmail.com>
parents:
22157
diff
changeset
|
486 str_append_maybe_escape(str, addr->name, TRUE); |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
487 } |
22165
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
488 if (addr->route != NULL || |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
489 addr->mailbox[0] != '\0' || |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
490 addr->domain[0] != '\0') { |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
491 if (addr->name != NULL && addr->name[0] != '\0') |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
492 str_append_c(str, ' '); |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
493 str_append_c(str, '<'); |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
494 if (addr->route != NULL) { |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
495 str_append(str, addr->route); |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
496 str_append_c(str, ':'); |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
497 } |
22167
15ca457e629d
lib-mail: message_address_write() - Write empy username as ""
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22166
diff
changeset
|
498 if (addr->mailbox[0] == '\0') |
15ca457e629d
lib-mail: message_address_write() - Write empy username as ""
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22166
diff
changeset
|
499 str_append(str, "\"\""); |
15ca457e629d
lib-mail: message_address_write() - Write empy username as ""
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22166
diff
changeset
|
500 else |
15ca457e629d
lib-mail: message_address_write() - Write empy username as ""
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22166
diff
changeset
|
501 str_append_maybe_escape(str, addr->mailbox, FALSE); |
22165
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
502 if (addr->domain[0] != '\0') { |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
503 str_append_c(str, '@'); |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
504 str_append(str, addr->domain); |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
505 } |
9318f53e7817
lib-mail: message_address_write() - Don't write empty <>
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22164
diff
changeset
|
506 str_append_c(str, '>'); |
22164
ef94192cddde
lib-mail: message_address_write() - Don't add '@' if domain is missing
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22161
diff
changeset
|
507 } |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
508 } |
1279
b14d1f375039
message_address_write() didn't work.
Timo Sirainen <tss@iki.fi>
parents:
1278
diff
changeset
|
509 |
b14d1f375039
message_address_write() didn't work.
Timo Sirainen <tss@iki.fi>
parents:
1278
diff
changeset
|
510 addr = addr->next; |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
511 } |
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
512 } |
13097
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
513 |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
514 static const char *address_headers[] = { |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
515 "From", "Sender", "Reply-To", |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
516 "To", "Cc", "Bcc", |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
517 "Resent-From", "Resent-Sender", "Resent-To", "Resent-Cc", "Resent-Bcc" |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
518 }; |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
519 |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
520 bool message_header_is_address(const char *hdr_name) |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
521 { |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
522 unsigned int i; |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
523 |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
524 for (i = 0; i < N_ELEMENTS(address_headers); i++) { |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
525 if (strcasecmp(hdr_name, address_headers[i]) == 0) |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
526 return TRUE; |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
527 } |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
528 return FALSE; |
e07c5cb0ae60
lib-mail: Added message_header_is_address()
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
529 } |
22403
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
530 |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
531 void message_detail_address_parse(const char *delimiter_string, |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
532 const char *address, const char **username_r, |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
533 const char **detail_r) |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
534 { |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
535 const char *p, *domain; |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
536 |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
537 *username_r = address; |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
538 *detail_r = ""; |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
539 |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
540 if (*delimiter_string == '\0') |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
541 return; |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
542 |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
543 domain = strchr(address, '@'); |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
544 p = strstr(address, delimiter_string); |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
545 if (p != NULL && (domain == NULL || p < domain)) { |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
546 /* user+detail@domain */ |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
547 *username_r = t_strdup_until(*username_r, p); |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
548 if (domain == NULL) |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
549 *detail_r = p+strlen(delimiter_string); |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
550 else { |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
551 *detail_r = t_strdup_until(p+strlen(delimiter_string), domain); |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
552 *username_r = t_strconcat(*username_r, domain, NULL); |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
553 } |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
554 } |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
555 } |
2a979ce1885d
lib-mail: Add message_detail_address_parse
Aki Tuomi <aki.tuomi@dovecot.fi>
parents:
22176
diff
changeset
|
556 |