aboutsummaryrefslogtreecommitdiffhomepage
path: root/message.cc
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2009-10-23 05:38:13 -0700
committerGravatar Carl Worth <cworth@cworth.org>2009-10-23 05:48:46 -0700
commit868d3b30683e40af723a8c94141172bd78d2b118 (patch)
treef9a9445798527b6d0cb741c7d867436d2cdaccd1 /message.cc
parent31044d10ed114637464481d1a0f4771ed170950e (diff)
Add notmuch_message_get_filename
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).
Diffstat (limited to 'message.cc')
-rw-r--r--message.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/message.cc b/message.cc
index 4e59fce0..1252a9df 100644
--- a/message.cc
+++ b/message.cc
@@ -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