*
* tag: Any tags associated with this message by the user.
*
+ * direntry: A colon-separated pair of values (INTEGER:STRING),
+ * where INTEGER is the document ID of a directory
+ * document, and STRING is the name of a file within
+ * that directory for this mail message.
+ *
* A mail document also has two values:
*
* TIMESTAMP: The time_t value corresponding to the message's
* user in searching. But the database doesn't really care itself
* about any of these.
*
- * Finally, the data portion of a mail document contains the path name
- * of the mail message (relative to the database path).
+ * The data portion of a mail document is empty.
*
* Directory document
* ------------------
{ "reference", "XREFERENCE" },
{ "replyto", "XREPLYTO" },
{ "directory", "XDIRECTORY" },
+ { "direntry", "XDIRENTRY" },
{ "parent", "XPARENT" },
};
if (i == end) {
*doc_id = 0;
return NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND;
- } else {
- *doc_id = *i;
- return NOTMUCH_PRIVATE_STATUS_SUCCESS;
}
+
+ *doc_id = *i;
+
+#if DEBUG_DATABASE_SANITY
+ i++;
+
+ if (i != end)
+ INTERNAL_ERROR ("Term %s:%s is not unique as expected.\n",
+ prefix_name, value);
+#endif
+
+ return NOTMUCH_PRIVATE_STATUS_SUCCESS;
}
static Xapian::Document
return status;
}
+const char *
+_notmuch_database_get_directory_path (void *ctx,
+ notmuch_database_t *notmuch,
+ unsigned int doc_id)
+{
+ Xapian::Document document;
+
+ document = find_document_for_doc_id (notmuch, doc_id);
+
+ return talloc_strdup (ctx, document.get_data ().c_str ());
+}
+
+/* Given a legal 'filename' for the database, (either relative to
+ * database path or absolute with initial components identical to
+ * database path), return a new string (with 'ctx' as the talloc
+ * owner) suitable for use as a direntry term value.
+ */
+notmuch_status_t
+_notmuch_database_filename_to_direntry (void *ctx,
+ notmuch_database_t *notmuch,
+ const char *filename,
+ char **direntry)
+{
+ const char *relative, *directory, *basename;
+ Xapian::docid directory_id;
+ notmuch_status_t status;
+
+ relative = _notmuch_database_relative_path (notmuch, filename);
+
+ status = _notmuch_database_split_path (ctx, relative,
+ &directory, &basename);
+ if (status)
+ return status;
+
+ status = _notmuch_database_find_directory_id (notmuch, directory,
+ &directory_id);
+ if (status)
+ return status;
+
+ *direntry = talloc_asprintf (ctx, "%u:%s", directory_id, basename);
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
/* Given a legal 'path' for the database, return the relative path.
*
* The return value will be a pointer to the originl path contents,
if (db_path != path)
free ((char *) db_path);
+ talloc_free (local);
+
return ret;
}
notmuch_private_status_t status;
const char *db_path = NULL;
time_t ret = 0;
- void *local = talloc_new (notmuch);
db_path = directory_db_path (path);
if (db_path != path)
free ((char *) db_path);
- talloc_free (local);
-
return ret;
}
goto DONE;
}
+ _notmuch_message_add_filename (message, filename);
+
/* Is this a newly created message object? */
if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
- _notmuch_message_set_filename (message, filename);
_notmuch_message_add_term (message, "type", "mail");
- } else {
- ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
- goto DONE;
- }
- ret = _notmuch_database_link_message (notmuch, message, message_file);
- if (ret)
- goto DONE;
+ ret = _notmuch_database_link_message (notmuch, message,
+ message_file);
+ if (ret)
+ goto DONE;
- date = notmuch_message_file_get_header (message_file, "date");
- _notmuch_message_set_date (message, date);
+ date = notmuch_message_file_get_header (message_file, "date");
+ _notmuch_message_set_date (message, date);
- _notmuch_message_index_file (message, filename);
+ _notmuch_message_index_file (message, filename);
+ } else {
+ ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
+ }
_notmuch_message_sync (message);
} catch (const Xapian::Error &error) {