]> git.notmuchmail.org Git - notmuch/commitdiff
Add notmuch_message_get_filename
authorCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2009 12:38:13 +0000 (05:38 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2009 12:48:46 +0000 (05:48 -0700)
This is a new public function to find the filename of the original
email message for a message-object that was found in the database.

We may change this function in the future to support returning a
list of filenames, (for messages with duplicate message IDs).

message.cc
notmuch.h

index 4e59fce09d980c75687641457195e76e71b00c1f..1252a9dfa2fdf29fe528dbfefb56f32ec0079767 100644 (file)
@@ -27,6 +27,7 @@ struct _notmuch_message {
     notmuch_database_t *notmuch;
     Xapian::docid doc_id;
     char *message_id;
+    char *filename;
     Xapian::Document doc;
 };
 
@@ -121,6 +122,7 @@ _notmuch_message_create (const void *talloc_owner,
     message->notmuch = notmuch;
     message->doc_id = doc_id;
     message->message_id = NULL; /* lazily created */
+    message->filename = NULL; /* lazily created */
     new (&message->doc) Xapian::Document;
 
     talloc_set_destructor (message, _notmuch_message_destructor);
@@ -150,6 +152,20 @@ notmuch_message_get_message_id (notmuch_message_t *message)
     return message->message_id;
 }
 
+const char *
+notmuch_message_get_filename (notmuch_message_t *message)
+{
+    std::string filename_str;
+
+    if (message->filename)
+       return message->filename;
+
+    filename_str = message->doc.get_data ();
+    message->filename = talloc_strdup (message, filename_str.c_str ());
+
+    return message->filename;
+}
+
 /* We end up having to call the destructors explicitly because we had
  * to use "placement new" in order to initialize C++ objects within a
  * block that we allocated with talloc. So C++ is making talloc
index bc2caaad5c800fdca224a8288d50ff2f1dbb7ad5..57ff8c8f3003fd63298ca7acd9464399ffe9262b 100644 (file)
--- a/notmuch.h
+++ b/notmuch.h
@@ -342,6 +342,13 @@ notmuch_results_destroy (notmuch_results_t *results);
 const char *
 notmuch_message_get_message_id (notmuch_message_t *message);
 
+/* Get this filename for the email corresponding to 'message'.
+ *
+ * The returned filename is relative to the base of the database from
+ * which 'message' was obtained. See notmuch_database_get_path() .*/
+const char *
+notmuch_message_get_filename (notmuch_message_t *message);
+
 /* Get the tags for 'message', returning a notmuch_tags_t object which
  * can be used to iterate over all tags.
  *