]> git.notmuchmail.org Git - notmuch/blobdiff - lib/database.cc
notmuch_database_add_message: Add missing error-value propagation.
[notmuch] / lib / database.cc
index eaf526677f789a6939ae86adc3b530327289dcf0..58a350d2f59e8368006d681a2508d20453b2254b 100644 (file)
@@ -42,7 +42,8 @@ typedef struct {
  * Mail document
  * -------------
  * A mail document is associated with a particular email message file
- * on disk. It is indexed with the following prefixed terms:
+ * on disk. It is indexed with the following prefixed terms which the
+ * database uses to construct threads, etc.:
  *
  *    Single terms of given prefix:
  *
@@ -53,6 +54,8 @@ typedef struct {
  *
  *     thread: The ID of the thread to which the mail belongs
  *
+ *     replyto: The ID from the In-Reply-To header of the mail (if any).
+ *
  *    Multiple terms of given prefix:
  *
  *     reference: All message IDs from In-Reply-To and Re ferences
@@ -67,6 +70,11 @@ typedef struct {
  *
  *     MESSAGE_ID:     The unique ID of the mail mess (see "id" above)
  *
+ * In addition, terms from the content of the message are added with
+ * "from", "to", "attachment", and "subject" prefixes for use by the
+ * user in searching. But the database doesn't really care itself
+ * about any of these.
+ *
  * Timestamp document
  * ------------------
  * A timestamp document is used by a client of the notmuch library to
@@ -177,7 +185,7 @@ notmuch_status_to_string (notmuch_status_t status)
     case NOTMUCH_STATUS_TAG_TOO_LONG:
        return "Tag value is too long (exceeds NOTMUCH_TAG_MAX)";
     case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
-       return "Unblanced number of calls to notmuch_message_freeze/thaw";
+       return "Unbalanced number of calls to notmuch_message_freeze/thaw";
     default:
     case NOTMUCH_STATUS_LAST_STATUS:
        return "Unknown error status value";
@@ -309,7 +317,7 @@ skip_space_and_comments (const char **str)
  * Returns a newly talloc'ed string belonging to 'ctx'.
  *
  * Returns NULL if there is any error parsing the message-id. */
-char *
+static char *
 _parse_message_id (void *ctx, const char *message_id, const char **next)
 {
     const char *s, *end;
@@ -718,7 +726,8 @@ _notmuch_database_link_message_to_parents (notmuch_database_t *notmuch,
 
     /* Carefully avoid adding any self-referential in-reply-to term. */
     in_reply_to_message_id = _parse_message_id (message, in_reply_to, NULL);
-    if (strcmp (in_reply_to_message_id,
+    if (in_reply_to_message_id &&
+       strcmp (in_reply_to_message_id,
                notmuch_message_get_message_id (message)))
     {
        _notmuch_message_add_term (message, "replyto",
@@ -899,7 +908,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
         * is to find a message ID (or else create one ourselves). */
 
        header = notmuch_message_file_get_header (message_file, "message-id");
-       if (header) {
+       if (header && *header != '\0') {
            message_id = _parse_message_id (message_file, header, NULL);
            /* So the header value isn't RFC-compliant, but it's
             * better than no message-id at all. */
@@ -931,8 +940,11 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 
        talloc_free (message_id);
 
-       if (message == NULL)
+       if (message == NULL) {
+           ret = COERCE_STATUS (private_status,
+                                "Unexpected status value from _notmuch_message_create_for_message_id");
            goto DONE;
+       }
 
        /* Is this a newly created message object? */
        if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {