message-id.c revision bcb4e51a409d94ae670de96afb8483a4f7855294
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/* Copyright (c) 2006-2018 Dovecot authors, see the included COPYING file */
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstatic bool get_untokenized_msgid(const char **msgid_p, string_t *msgid)
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen rfc822_parser_init(&parser, (const unsigned char *)*msgid_p,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen id-left = dot-atom-text / no-fold-quote / obs-id-left
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen id-right = dot-atom-text / no-fold-literal / obs-id-right
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen no-fold-quote = DQUOTE *(qtext / quoted-pair) DQUOTE
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen no-fold-literal = "[" *(dtext / quoted-pair) "]"
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen ret = rfc822_parse_quoted_string(&parser, msgid);
aba496a58acf9d9c61314de71353550e579f85eeUmut Tezduyar Lindskog if (rfc822_parse_dot_atom(&parser, msgid) <= 0)
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen /* @UNSAFE */
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen /* find the first lwsp */
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen while (*str != ' ' && *str != '\t' && *str != '\r' && *str != '\n') {
fe6b2d55bcb379d01664ed28cea40634cb6b52e3Tom Gundersen if (*str != ' ' && *str != '\t' && *str != '\r' && *str != '\n')
52433f6b65eccd1c54606dde999610640f3458acTom Gundersenconst char *message_id_get_next(const char **msgid_p)
7951dea20911969287878e6897b3eca348721adeSusant Sahani const char *p;
1a436809498faf6486815baa0338fb6b8e5def07Tom Gundersen /* skip until '<' */
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen /* check it through quickly to see if it's already normalized */
14b746f72132324e637c4e39694bd474f85e19f7Tom Gundersen for (;; p++) {
14b746f72132324e637c4e39694bd474f85e19f7Tom Gundersen if ((unsigned char)*p >= 'A') /* matches most */
edbb03e95a3c31bf719d5c6c46eec14d0bcb9c8fTom Gundersen if (*p == '@')
edbb03e95a3c31bf719d5c6c46eec14d0bcb9c8fTom Gundersen if (*p == '>' || *p == '"' || *p == '(' || *p == '[')
02b59d57e0c08231645120077f651151f5bb2babTom Gundersen if (*p == '\0') {
672682a6b9d6fb6a3722c3fea1a93b4831747b54Tom Gundersen if (*p == '>') {
52433f6b65eccd1c54606dde999610640f3458acTom Gundersen /* ok, do it the slow way */
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen /* allocate only once, so we don't leak
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen with multiple invalid message IDs */
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen /* invalid message id, see if there's another valid one */