- 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;
+ }