use my own APIS for headers, parameters and so on
[apps/madmutt.git] / lib-mime / rfc822parse.c
index 6a3c164..fb498b7 100644 (file)
@@ -102,85 +102,85 @@ 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)
+int mutt_check_encoding(const char *s)
 {
-  if (ascii_strncasecmp ("7bit", c, sizeof ("7bit") - 1) == 0)
-    return (ENC7BIT);
-  else if (ascii_strncasecmp ("8bit", c, sizeof ("8bit") - 1) == 0)
-    return (ENC8BIT);
-  else if (ascii_strncasecmp ("binary", c, sizeof ("binary") - 1) == 0)
-    return (ENCBINARY);
-  else
-    if (ascii_strncasecmp
-        ("quoted-printable", c, sizeof ("quoted-printable") - 1) == 0)
-    return (ENCQUOTEDPRINTABLE);
-  else if (ascii_strncasecmp ("base64", c, sizeof ("base64") - 1) == 0)
-    return (ENCBASE64);
-  else if (ascii_strncasecmp ("x-uuencode", c, sizeof ("x-uuencode") - 1) == 0)
-    return (ENCUUENCODED);
-  else
-    return (ENCOTHER);
+#define COMPARE(tok, value)                             \
+    if (!ascii_strncasecmp(tok, s, sizeof(tok) - 1)) {  \
+        return value;                                   \
+    }
+    COMPARE("7bit", ENC7BIT);
+    COMPARE("8bit", ENC8BIT);
+    COMPARE("binary", ENCBINARY);
+    COMPARE("quoted-printable", ENCQUOTEDPRINTABLE);
+    COMPARE("base64", ENCBASE64);
+    COMPARE("x-uuencode", ENCUUENCODED);
+#undef COMPARE
+
+    return ENCOTHER;
 }
 
-static PARAMETER *parse_parameters (const char *s)
+static PARAMETER *parse_parameters(const char *s)
 {
   PARAMETER *head = 0, *cur = 0, *new;
   char buffer[LONG_STRING];
@@ -199,7 +199,7 @@ static PARAMETER *parse_parameters (const char *s)
     if (*p != ';') {
       i = p - s;
 
-      new = mutt_new_parameter ();
+      new = parameter_new();
 
       new->attribute = p_dupstr(s, i);
 
@@ -313,7 +313,7 @@ void mutt_parse_content_type (char *s, BODY * ct)
   char *subtype;
 
   p_delete(&ct->subtype);
-  mutt_free_parameter (&ct->parameter);
+  parameter_delete(&ct->parameter);
 
   /* First extract any existing parameters */
   if ((pc = strchr (s, ';')) != NULL) {
@@ -396,7 +396,7 @@ static void parse_content_disposition (char *s, BODY * ct)
       m_strreplace(&ct->filename, s);
     if ((s = mutt_get_parameter ("name", parms)) != 0)
       ct->form_name = m_strdup(s);
-    mutt_free_parameter (&parms);
+    parameter_delete(&parms);
   }
 }
 
@@ -511,7 +511,7 @@ BODY *mutt_parse_messageRFC822 (FILE * fp, BODY * parent)
 {
   BODY *msg;
 
-  parent->hdr = mutt_new_header ();
+  parent->hdr = header_new();
   parent->hdr->offset = ftello (fp);
   parent->hdr->env = mutt_read_rfc822_header (fp, parent->hdr, 0, 0);
   msg = parent->hdr->content;
@@ -1246,12 +1246,12 @@ done:
  *             Used for recall-message.
  *
  * Returns:     newly allocated envelope structure.  You should free it by
- *              mutt_free_envelope() when envelope stay unneeded.
+ *              envelope_delete() when envelope stay unneeded.
  */
 ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
                                    short weed)
 {
-  ENVELOPE *e = mutt_new_envelope ();
+  ENVELOPE *e = envelope_new();
   LIST *last = NULL;
   char *line = p_new(char, LONG_STRING);
   char *p;