From: Pierre Habouzit Date: Sun, 5 Nov 2006 19:41:34 +0000 (+0100) Subject: simplify mutt_parse_references X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=fa4c2af84416f9b4663bb80d36faaba35db05524 simplify mutt_parse_references Signed-off-by: Pierre Habouzit --- diff --git a/lib-mime/mime.h b/lib-mime/mime.h index 51585a0..096c321 100644 --- a/lib-mime/mime.h +++ b/lib-mime/mime.h @@ -56,6 +56,7 @@ extern const char *BodyEncodings[]; extern const char RFC822Specials[]; ssize_t mutt_read_rfc822_line(FILE*, char**, ssize_t*); +LIST *mutt_parse_references (char *, int); /*** addresses ***/ diff --git a/lib-mime/rfc822parse.c b/lib-mime/rfc822parse.c index 6a3c164..adc73d9 100644 --- a/lib-mime/rfc822parse.c +++ b/lib-mime/rfc822parse.c @@ -102,62 +102,65 @@ ssize_t mutt_read_rfc822_line(FILE *f, char **line, ssize_t *n) } } -LIST *mutt_parse_references (char *s, int in_reply_to) +/* TODO: Make that a string list somehow */ +LIST *mutt_parse_references(char *s, int in_reply_to) { - LIST *t, *lst = NULL; - int m, n = 0; - char *o = NULL, *new, *at; + LIST *lst = NULL; + int n = 0; + char *o = NULL; - while ((s = strtok (s, " \t;")) != NULL) { - /* - * some mail clients add other garbage besides message-ids, so do a quick + /* some mail clients add other garbage besides message-ids, so do a quick * check to make sure this looks like a valid message-id * some idiotic clients also break their message-ids between lines, deal * with that too (give up if it's more than two lines, though) */ - t = NULL; - new = NULL; - - if (*s == '<') { - n = m_strlen(s); - if (s[n - 1] != '>') { - o = s; - s = NULL; - continue; - } - new = m_strdup(s); - } - else if (o) { - m = m_strlen(s); - if (s[m - 1] == '>') { - new = p_new(char, n + m + 1); - strcpy (new, o); /* __STRCPY_CHECKED__ */ - strcpy (new + n, s); /* __STRCPY_CHECKED__ */ - } - } - if (new) { - /* make sure that this really does look like a message-id. - * it should have exactly one @, and if we're looking at - * an in-reply-to header, make sure that the part before - * the @ has more than eight characters or it's probably - * an email address - */ - if (!(at = strchr (new, '@')) || strchr (at + 1, '@') - || (in_reply_to && at - new <= 8)) - p_delete(&new); - else { - t = p_new(LIST, 1); - t->data = new; - t->next = lst; - lst = t; - } + for (s = strtok(s, " \t;"); s; s = strtok(NULL, " \t;")) { + char *new = NULL; + + if (*s == '<') { + n = m_strlen(s); + if (s[n - 1] != '>') { + o = s; + continue; + } + + new = m_strdup(s); + } else if (o) { + ssize_t m = m_strlen(s); + + if (s[m - 1] != '>') { + o = NULL; + } else { + new = p_new(char, n + m + 1); + strcpy(new, o); + strcpy(new + n, s); + } + } + + /* make sure that this really does look like a message-id. + * it should have exactly one @, and if we're looking at + * an in-reply-to header, make sure that the part before + * the @ has more than eight characters or it's probably + * an email address + */ + if (new) { + char *at = strchr(new, '@'); + LIST *tmp; + + if (!at || strchr(at + 1, '@') || (in_reply_to && at - new <= 8)) { + p_delete(&new); + continue; + } + + tmp = p_new(LIST, 1); + tmp->data = new; + tmp->next = lst; + lst = tmp; + } } - o = NULL; - s = NULL; - } - return (lst); + return lst; } int mutt_check_encoding (const char *c) diff --git a/protos.h b/protos.h index b4c17bd..0daa2ac 100644 --- a/protos.h +++ b/protos.h @@ -71,7 +71,6 @@ BODY *mutt_read_mime_header (FILE *, int); CONTENT *mutt_get_content_info (const char *fname, BODY * b); LIST *mutt_make_references (ENVELOPE * e); -LIST *mutt_parse_references (char *, int); ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short); HEADER *mutt_dup_header (HEADER *);