144 |
|
|
145 |
return EOK; |
return EOK; |
146 |
} |
} |
147 |
|
|
148 |
static int |
static int |
149 |
str_append (char **to, const char *from) |
str_append (char **to, const char *from) |
150 |
{ |
{ |
152 |
return 0; |
return 0; |
153 |
return str_append_n (to, from, strlen (from)); |
return str_append_n (to, from, strlen (from)); |
154 |
} |
} |
155 |
|
|
156 |
static int |
static int |
157 |
str_append_char (char **to, char c) |
str_append_char (char **to, char c) |
158 |
{ |
{ |
159 |
return str_append_n (to, &c, 1); |
return str_append_n (to, &c, 1); |
160 |
} |
} |
161 |
|
|
162 |
static int |
static int |
163 |
str_append_range (char **to, const char *b, const char *e) |
str_append_range (char **to, const char *b, const char *e) |
164 |
{ |
{ |
165 |
return str_append_n (to, b, e - b); |
return str_append_n (to, b, e - b); |
166 |
} |
} |
167 |
|
|
168 |
static void |
static void |
169 |
str_free (char **s) |
str_free (char **s) |
170 |
{ |
{ |
230 |
{ |
{ |
231 |
return strchr ("()<>@,;:\\\".[]", c) ? 1 : 0; |
return strchr ("()<>@,;:\\\".[]", c) ? 1 : 0; |
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 |
|
|
242 |
int |
int |
243 |
parse822_is_atom_char (char c) |
parse822_is_atom_char (char c) |
244 |
{ |
{ |
245 |
return |
return parse822_is_char (c) && parse822_is_atom_char_ex (c); |
|
parse822_is_char (c) && |
|
|
!parse822_is_special (c) && |
|
|
!parse822_is_space (c) && |
|
|
!parse822_is_ctl (c); |
|
246 |
} |
} |
247 |
|
|
248 |
int |
int |
303 |
|
|
304 |
return EPARSE; |
return EPARSE; |
305 |
} |
} |
306 |
|
|
307 |
int |
int |
308 |
parse822_skip_lwsp_char (const char **p, const char *e) |
parse822_skip_lwsp_char (const char **p, const char *e) |
309 |
{ |
{ |
314 |
} |
} |
315 |
return EPARSE; |
return EPARSE; |
316 |
} |
} |
317 |
|
|
318 |
int |
int |
319 |
parse822_skip_lwsp (const char **p, const char *e) |
parse822_skip_lwsp (const char **p, const char *e) |
320 |
{ |
{ |
493 |
} |
} |
494 |
|
|
495 |
int |
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 |
521 |
parse822_quoted_pair (const char **p, const char *e, char **qpair) |
parse822_quoted_pair (const char **p, const char *e, char **qpair) |
522 |
{ |
{ |
523 |
/* quoted-pair = "\" char */ |
/* quoted-pair = "\" char */ |
633 |
/* Necessary because the quoted string could have found |
/* Necessary because the quoted string could have found |
634 |
* a partial string (invalid syntax). Thus reset, the atom |
* a partial string (invalid syntax). Thus reset, the atom |
635 |
* will fail to if the syntax is invalid. |
* 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." |
639 |
*/ |
*/ |
640 |
|
|
641 |
{ |
{ |
642 |
char *atom = 0; |
char *atom = 0; |
643 |
if (parse822_atom (p, e, &atom) == EOK) |
if (parse822_atom_ex (p, e, &atom) == EOK) |
644 |
{ |
{ |
645 |
rc = str_append (word, atom); |
rc = str_append (word, atom); |
646 |
|
|