simplify mutt_parse_references
authorPierre Habouzit <madcoder@debian.org>
Sun, 5 Nov 2006 19:41:34 +0000 (20:41 +0100)
committerPierre Habouzit <madcoder@debian.org>
Sun, 5 Nov 2006 19:41:34 +0000 (20:41 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
lib-mime/mime.h
lib-mime/rfc822parse.c
protos.h

index 51585a0..096c321 100644 (file)
@@ -56,6 +56,7 @@ extern const char *BodyEncodings[];
 extern const char RFC822Specials[];
 
 ssize_t mutt_read_rfc822_line(FILE*, char**, ssize_t*);
 extern const char RFC822Specials[];
 
 ssize_t mutt_read_rfc822_line(FILE*, char**, ssize_t*);
+LIST *mutt_parse_references (char *, int);
 
 /*** addresses ***/
 
 
 /*** addresses ***/
 
index 6a3c164..adc73d9 100644 (file)
@@ -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)
      */
      * 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)
 }
 
 int mutt_check_encoding (const char *c)
index b4c17bd..0daa2ac 100644 (file)
--- 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);
 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 *);
 
 ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short);
 HEADER *mutt_dup_header (HEADER *);