1 #include "notmuch-private.h"
2 #include "string-util.h"
4 /* Advance 'str' past any whitespace or RFC 822 comments. A comment is
5 * a (potentially nested) parenthesized sequence with '\' used to
6 * escape any character (including parentheses).
8 * If the sequence to be skipped continues to the end of the string,
9 * then 'str' will be left pointing at the final terminating '\0'
13 skip_space_and_comments (const char **str)
18 while (*s && (isspace (*s) || *s == '(')) {
19 while (*s && isspace (*s))
24 while (*s && nesting) {
27 } else if (*s == ')') {
29 } else if (*s == '\\') {
42 _notmuch_message_id_parse (void *ctx, const char *message_id, const char **next)
47 if (message_id == NULL || *message_id == '\0')
52 skip_space_and_comments (&s);
54 /* Skip any unstructured text as well. */
55 while (*s && *s != '<')
66 skip_space_and_comments (&s);
69 while (*end && *end != '>')
78 if (end > s && *end == '>')
83 result = talloc_strndup (ctx, s, end - s + 1);
85 /* Finally, collapse any whitespace that is within the message-id
91 for (r = result, len = strlen (r); *r; r++, len--)
92 if (*r == ' ' || *r == '\t')
93 memmove (r, r+1, len);
100 _notmuch_message_id_parse_strict (void *ctx, const char *message_id)
104 if (message_id == NULL || *message_id == '\0')
107 s = skip_space (message_id);
113 for (end = s; *end && *end != '>'; end++)
120 const char *last = skip_space (end + 1);
125 return talloc_strndup (ctx, s, end - s);