]> git.notmuchmail.org Git - notmuch/blobdiff - database.cc
Convert notmuch_database_t to start using talloc.
[notmuch] / database.cc
index 31afe7cc147afdc3098e8599eb57337b7c7b785d..e73e210d1071658609f31fbceacbce0b35a13e4e 100644 (file)
@@ -305,6 +305,7 @@ static char *
 parse_message_id (const char *message_id, const char **next)
 {
     const char *s, *end;
+    char *result;
 
     if (message_id == NULL)
        return NULL;
@@ -339,10 +340,23 @@ parse_message_id (const char *message_id, const char **next)
 
     if (end > s && *end == '>')
        end--;
-    if (end > s)
-       return strndup (s, end - s + 1);
-    else
+    if (end <= s)
        return NULL;
+
+    result = strndup (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;
 }
 
 /* Parse a References header value, putting a copy of each referenced
@@ -442,10 +456,8 @@ notmuch_database_open (const char *path)
 
     xapian_path = g_strdup_printf ("%s/%s", notmuch_path, "xapian");
 
-    /* C++ is so nasty in requiring these casts. I'm almost tempted to
-     * write a C wrapper for Xapian... */
-    notmuch = (notmuch_database_t *) xmalloc (sizeof (notmuch_database_t));
-    notmuch->path = xstrdup (path);
+    notmuch = talloc (NULL, notmuch_database_t);
+    notmuch->path = talloc_strdup (notmuch, path);
 
     try {
        notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,
@@ -474,8 +486,7 @@ notmuch_database_close (notmuch_database_t *notmuch)
 {
     delete notmuch->query_parser;
     delete notmuch->xapian_db;
-    free (notmuch->path);
-    free (notmuch);
+    talloc_free (notmuch);
 }
 
 const char *