unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob a1dce9c85114d987ad391c184f8fd64d0536cfa6 2359 bytes (raw)
name: lib/message-id.c 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 
#include "notmuch-private.h"
#include "string-util.h"

/* Advance 'str' past any whitespace or RFC 822 comments. A comment is
 * a (potentially nested) parenthesized sequence with '\' used to
 * escape any character (including parentheses).
 *
 * If the sequence to be skipped continues to the end of the string,
 * then 'str' will be left pointing at the final terminating '\0'
 * character.
 */
static void
skip_space_and_comments (const char **str)
{
    const char *s;

    s = *str;
    while (*s && (isspace (*s) || *s == '(')) {
	while (*s && isspace (*s))
	    s++;
	if (*s == '(') {
	    int nesting = 1;
	    s++;
	    while (*s && nesting) {
		if (*s == '(') {
		    nesting++;
		} else if (*s == ')') {
		    nesting--;
		} else if (*s == '\\') {
		    if (*(s+1))
			s++;
		}
		s++;
	    }
	}
    }

    *str = s;
}

char *
_notmuch_message_id_parse (void *ctx, const char *message_id, const char **next)
{
    const char *s, *end;
    char *result;

    if (message_id == NULL || *message_id == '\0')
	return NULL;

    s = message_id;

    skip_space_and_comments (&s);

    /* Skip any unstructured text as well. */
    while (*s && *s != '<')
	s++;

    if (*s == '<') {
	s++;
    } else {
	if (next)
	    *next = s;
	return NULL;
    }

    skip_space_and_comments (&s);

    end = s;
    while (*end && *end != '>')
	end++;
    if (next) {
	if (*end)
	    *next = end + 1;
	else
	    *next = end;
    }

    if (end > s && *end == '>')
	end--;
    if (end <= s)
	return NULL;

    result = talloc_strndup (ctx, s, end - s + 1);

    /* Finally, collapse any whitespace that is within the message-id
     * itself. */
    {
	char *r;
	int len;

	for (r = result, len = strlen (r); *r; r++, len--)
	    if (*r == ' ' || *r == '\t')
		memmove (r, r+1, len);
    }

    return result;
}

char *
_notmuch_message_id_parse_strict (void *ctx, const char *message_id)
{
    const char *s, *end;
    char *result;

    if (message_id == NULL || *message_id == '\0')
	return NULL;

    s = skip_space (message_id);
    if (*s == '<')
	s++;
    else
	return NULL;

    for (end = s; *end && *end != '>'; end++)
	if (isspace (*end))
	    return NULL;

    if (*end != '>')
	return NULL;
    else {
	const char *last =  skip_space (end+1);
	if (*last != '\0')
	    return NULL;
    }

    result = talloc_strndup (ctx, s, end - s);
    return result;
}

debug log:

solving a1dce9c8 ...
found a1dce9c8 in https://yhetil.org/notmuch/20180830112915.11761-15-david@tethera.net/ ||
	https://yhetil.org/notmuch/20180730224555.26047-14-david@tethera.net/ ||
	https://yhetil.org/notmuch/20180723082259.32440-5-david@tethera.net/ ||
	https://yhetil.org/notmuch/20180801045823.7802-1-david@tethera.net/
found d7541d50 in https://yhetil.org/notmuch.git/
preparing index
index prepared:
100644 d7541d50102d671ca6fd465ff047ceb4c220753a	lib/message-id.c

applying [1/1] https://yhetil.org/notmuch/20180830112915.11761-15-david@tethera.net/
diff --git a/lib/message-id.c b/lib/message-id.c
index d7541d50..a1dce9c8 100644

Checking patch lib/message-id.c...
Applied patch lib/message-id.c cleanly.

skipping https://yhetil.org/notmuch/20180730224555.26047-14-david@tethera.net/ for a1dce9c8
skipping https://yhetil.org/notmuch/20180723082259.32440-5-david@tethera.net/ for a1dce9c8
skipping https://yhetil.org/notmuch/20180801045823.7802-1-david@tethera.net/ for a1dce9c8
index at:
100644 a1dce9c85114d987ad391c184f8fd64d0536cfa6	lib/message-id.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).