message-id.c revision 4e8d6d03c2ff85448df79b181a2ea850fb5d4199
/* Copyright (c) 2006-2012 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "str.h"
#include "rfc822-parser.h"
#include "message-id.h"
{
struct rfc822_parser_context parser;
int ret;
/*
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
id-left = dot-atom-text / no-fold-quote / obs-id-left
id-right = dot-atom-text / no-fold-literal / obs-id-right
no-fold-quote = DQUOTE *(qtext / quoted-pair) DQUOTE
no-fold-literal = "[" *(dtext / quoted-pair) "]"
*/
else
if (ret <= 0)
return FALSE;
return FALSE;
return FALSE;
return FALSE;
return TRUE;
}
static void strip_lwsp(char *str)
{
/* @UNSAFE */
char *dest;
/* find the first lwsp */
if (*str == '\0')
return;
str++;
}
}
*dest = '\0';
}
const char *message_id_get_next(const char **msgid_p)
{
const char *p;
bool found_at;
return NULL;
for (;;) {
/* skip until '<' */
while (*msgid != '<') {
if (*msgid == '\0') {
return NULL;
}
msgid++;
}
msgid++;
/* check it through quickly to see if it's already normalized */
for (;; p++) {
if ((unsigned char)*p >= 'A') /* matches most */
continue;
if (*p == '@')
if (*p == '>' || *p == '"' || *p == '(' || *p == '[')
break;
if (*p == '\0') {
*msgid_p = p;
return NULL;
}
}
if (*p == '>') {
*msgid_p = p+1;
if (found_at) {
char *s;
msgid, p);
strip_lwsp(s);
return s;
}
} else {
/* ok, do it the slow way */
/* allocate only once, so we don't leak
with multiple invalid message IDs */
}
}
/* invalid message id, see if there's another valid one */
}
}