]> git.notmuchmail.org Git - notmuch/commitdiff
database: Allowing storing multiple filenames for a single message ID.
authorCarl Worth <cworth@cworth.org>
Mon, 21 Dec 2009 20:08:46 +0000 (12:08 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 6 Jan 2010 18:32:05 +0000 (10:32 -0800)
The library interface is unchanged so far, (still just
notmuch_database_add_message), but internally, the old
_set_filename function is now _add_filename instead.

lib/database.cc
lib/message.cc
lib/notmuch-private.h
lib/notmuch.h

index 7d09119cecddf54a94e34b8f2a9948ee203fbb85..553c9f823588d22f7ac96d162d2399fd63febc02 100644 (file)
@@ -843,7 +843,6 @@ notmuch_database_get_directory_mtime (notmuch_database_t *notmuch,
     notmuch_private_status_t status;
     const char *db_path = NULL;
     time_t ret = 0;
     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);
 
 
     db_path = directory_db_path (path);
 
@@ -1188,23 +1187,24 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
            goto DONE;
        }
 
            goto DONE;
        }
 
+       _notmuch_message_add_filename (message, filename);
+
        /* Is this a newly created message object? */
        if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
        /* 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");
            _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) {
 
        _notmuch_message_sync (message);
     } catch (const Xapian::Error &error) {
index 3f5334239e0839d5d0bcae3595e4e28b7f1b5280..7d586903913305b9e654644024b016bbcc1f6f28 100644 (file)
@@ -385,15 +385,12 @@ notmuch_message_get_replies (notmuch_message_t *message)
     return _notmuch_messages_create (message->replies);
 }
 
     return _notmuch_messages_create (message->replies);
 }
 
-/* Set the filename for 'message' to 'filename'.
- *
- * XXX: We should still figure out if we think it's important to store
- * multiple filenames for email messages with identical message IDs.
+/* Add an additional 'filename' for 'message'.
  *
  * This change will not be reflected in the database until the next
  * call to _notmuch_message_set_sync. */
 notmuch_status_t
  *
  * This change will not be reflected in the database until the next
  * call to _notmuch_message_set_sync. */
 notmuch_status_t
-_notmuch_message_set_filename (notmuch_message_t *message,
+_notmuch_message_add_filename (notmuch_message_t *message,
                               const char *filename)
 {
     const char *relative, *directory, *basename;
                               const char *filename)
 {
     const char *relative, *directory, *basename;
index 5a930bb32a87f0204a3f13c75ea5071b0f9b8136..e9712832aa690f47e08d6cd1ed26ffdb7f13d62f 100644 (file)
@@ -211,7 +211,7 @@ _notmuch_message_gen_terms (notmuch_message_t *message,
                            const char *text);
 
 notmuch_status_t
                            const char *text);
 
 notmuch_status_t
-_notmuch_message_set_filename (notmuch_message_t *message,
+_notmuch_message_add_filename (notmuch_message_t *message,
                               const char *filename);
 
 void
                               const char *filename);
 
 void
index 786b8e9f034d4ec73352687b13699319208a9397..e96474f65861b94b30d538f5e3baebb5da4bf0c9 100644 (file)
@@ -698,14 +698,20 @@ notmuch_message_get_thread_id (notmuch_message_t *message);
 notmuch_messages_t *
 notmuch_message_get_replies (notmuch_message_t *message);
 
 notmuch_messages_t *
 notmuch_message_get_replies (notmuch_message_t *message);
 
-/* Get the filename for the email corresponding to 'message'.
+/* Get a filename for the email corresponding to 'message'.
  *
  * The returned filename is an absolute filename, (the initial
  * component will match notmuch_database_get_path() ).
  *
  * The returned string belongs to the message so should not be
  * modified or freed by the caller (nor should it be referenced after
  *
  * The returned filename is an absolute filename, (the initial
  * component will match notmuch_database_get_path() ).
  *
  * The returned string belongs to the message so should not be
  * modified or freed by the caller (nor should it be referenced after
- * the message is destroyed). */
+ * the message is destroyed).
+ *
+ * Note: If this message corresponds to multiple files in the mail
+ * store, (that is, multiple files contain identical message IDs),
+ * this function will arbitrarily return a single one of those
+ * filenames.
+ */
 const char *
 notmuch_message_get_filename (notmuch_message_t *message);
 
 const char *
 notmuch_message_get_filename (notmuch_message_t *message);