Be more liberal in parsing local parts.
Showing
1 changed file
with
45 additions
and
6 deletions
... | @@ -144,6 +144,7 @@ str_append_n (char **to, const char *from, size_t n) | ... | @@ -144,6 +144,7 @@ str_append_n (char **to, const char *from, size_t n) |
144 | 144 | ||
145 | return EOK; | 145 | return EOK; |
146 | } | 146 | } |
147 | |||
147 | static int | 148 | static int |
148 | str_append (char **to, const char *from) | 149 | str_append (char **to, const char *from) |
149 | { | 150 | { |
... | @@ -151,16 +152,19 @@ str_append (char **to, const char *from) | ... | @@ -151,16 +152,19 @@ str_append (char **to, const char *from) |
151 | return 0; | 152 | return 0; |
152 | return str_append_n (to, from, strlen (from)); | 153 | return str_append_n (to, from, strlen (from)); |
153 | } | 154 | } |
155 | |||
154 | static int | 156 | static int |
155 | str_append_char (char **to, char c) | 157 | str_append_char (char **to, char c) |
156 | { | 158 | { |
157 | return str_append_n (to, &c, 1); | 159 | return str_append_n (to, &c, 1); |
158 | } | 160 | } |
161 | |||
159 | static int | 162 | static int |
160 | str_append_range (char **to, const char *b, const char *e) | 163 | str_append_range (char **to, const char *b, const char *e) |
161 | { | 164 | { |
162 | return str_append_n (to, b, e - b); | 165 | return str_append_n (to, b, e - b); |
163 | } | 166 | } |
167 | |||
164 | static void | 168 | static void |
165 | str_free (char **s) | 169 | str_free (char **s) |
166 | { | 170 | { |
... | @@ -226,14 +230,19 @@ parse822_is_special (char c) | ... | @@ -226,14 +230,19 @@ parse822_is_special (char c) |
226 | { | 230 | { |
227 | return strchr ("()<>@,;:\\\".[]", c) ? 1 : 0; | 231 | return strchr ("()<>@,;:\\\".[]", c) ? 1 : 0; |
228 | } | 232 | } |
233 | |||
234 | int | ||
235 | parse822_is_atom_char_ex (char c) | ||
236 | { | ||
237 | return !parse822_is_special (c) | ||
238 | && !parse822_is_space (c) | ||
239 | && !parse822_is_ctl (c); | ||
240 | } | ||
241 | |||
229 | int | 242 | int |
230 | parse822_is_atom_char (char c) | 243 | parse822_is_atom_char (char c) |
231 | { | 244 | { |
232 | return | 245 | return parse822_is_char (c) && parse822_is_atom_char_ex (c); |
233 | parse822_is_char (c) && | ||
234 | !parse822_is_special (c) && | ||
235 | !parse822_is_space (c) && | ||
236 | !parse822_is_ctl (c); | ||
237 | } | 246 | } |
238 | 247 | ||
239 | int | 248 | int |
... | @@ -294,6 +303,7 @@ parse822_skip_nl (const char **p, const char *e) | ... | @@ -294,6 +303,7 @@ parse822_skip_nl (const char **p, const char *e) |
294 | 303 | ||
295 | return EPARSE; | 304 | return EPARSE; |
296 | } | 305 | } |
306 | |||
297 | int | 307 | int |
298 | parse822_skip_lwsp_char (const char **p, const char *e) | 308 | parse822_skip_lwsp_char (const char **p, const char *e) |
299 | { | 309 | { |
... | @@ -304,6 +314,7 @@ parse822_skip_lwsp_char (const char **p, const char *e) | ... | @@ -304,6 +314,7 @@ parse822_skip_lwsp_char (const char **p, const char *e) |
304 | } | 314 | } |
305 | return EPARSE; | 315 | return EPARSE; |
306 | } | 316 | } |
317 | |||
307 | int | 318 | int |
308 | parse822_skip_lwsp (const char **p, const char *e) | 319 | parse822_skip_lwsp (const char **p, const char *e) |
309 | { | 320 | { |
... | @@ -482,6 +493,31 @@ parse822_atom (const char **p, const char *e, char **atom) | ... | @@ -482,6 +493,31 @@ parse822_atom (const char **p, const char *e, char **atom) |
482 | } | 493 | } |
483 | 494 | ||
484 | int | 495 | int |
496 | parse822_atom_ex (const char **p, const char *e, char **atom) | ||
497 | { | ||
498 | /* atom = 1*<an atom char> */ | ||
499 | |||
500 | const char *save = *p; | ||
501 | int rc = EPARSE; | ||
502 | |||
503 | parse822_skip_comments (p, e); | ||
504 | |||
505 | save = *p; | ||
506 | |||
507 | while ((*p != e) && parse822_is_atom_char_ex (**p)) | ||
508 | { | ||
509 | rc = str_append_char (atom, **p); | ||
510 | *p += 1; | ||
511 | if (rc != EOK) | ||
512 | { | ||
513 | *p = save; | ||
514 | break; | ||
515 | } | ||
516 | } | ||
517 | return rc; | ||
518 | } | ||
519 | |||
520 | int | ||
485 | parse822_quoted_pair (const char **p, const char *e, char **qpair) | 521 | parse822_quoted_pair (const char **p, const char *e, char **qpair) |
486 | { | 522 | { |
487 | /* quoted-pair = "\" char */ | 523 | /* quoted-pair = "\" char */ |
... | @@ -597,11 +633,14 @@ parse822_word (const char **p, const char *e, char **word) | ... | @@ -597,11 +633,14 @@ parse822_word (const char **p, const char *e, char **word) |
597 | /* Necessary because the quoted string could have found | 633 | /* Necessary because the quoted string could have found |
598 | * a partial string (invalid syntax). Thus reset, the atom | 634 | * a partial string (invalid syntax). Thus reset, the atom |
599 | * will fail to if the syntax is invalid. | 635 | * will fail to if the syntax is invalid. |
636 | * We use parse822_atom_ex to allow for non-rfc-compliant atoms: | ||
637 | * | ||
638 | * "Be liberal in what you accept, and conservative in what you send." | ||
600 | */ | 639 | */ |
601 | 640 | ||
602 | { | 641 | { |
603 | char *atom = 0; | 642 | char *atom = 0; |
604 | if (parse822_atom (p, e, &atom) == EOK) | 643 | if (parse822_atom_ex (p, e, &atom) == EOK) |
605 | { | 644 | { |
606 | rc = str_append (word, atom); | 645 | rc = str_append (word, atom); |
607 | 646 | ... | ... |
-
Please register or sign in to post a comment