[notmuch] [PATCH 1/2] lib/message: Add function to get maildir flags.

Stefan Schmidt stefan at datenfreihafen.org
Sat Nov 21 16:11:00 PST 2009


With notmuch_message_get_flags() we gain the information if the message was
flagged as read, draft, trashed, etc. Handy for big mail spooles that were used
with another mailer.

Signed-off-by: Stefan Schmidt <stefan at datenfreihafen.org>
---
 lib/message.cc |   26 ++++++++++++++++++++++++++
 lib/notmuch.h  |   10 ++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 069cedb..9bec61e 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -35,6 +35,7 @@ struct _notmuch_message {
     char *thread_id;
     char *in_reply_to;
     char *filename;
+    char *flags;
     notmuch_message_file_t *message_file;
     notmuch_message_list_t *replies;
 
@@ -114,6 +115,7 @@ _notmuch_message_create (const void *talloc_owner,
     message->thread_id = NULL;
     message->in_reply_to = NULL;
     message->filename = NULL;
+    message->flags = NULL;
     message->message_file = NULL;
 
     message->replies = _notmuch_message_list_create (message);
@@ -438,6 +440,30 @@ notmuch_message_get_filename (notmuch_message_t *message)
     return message->filename;
 }
 
+const char *
+notmuch_message_get_flags (notmuch_message_t *message)
+{
+    std::string filename_str, flags;
+    size_t position;
+    const char *db_path;
+
+    if (message->flags)
+	return message->flags;
+
+    filename_str = message->doc.get_data ();
+    db_path = notmuch_database_get_path (message->notmuch);
+
+    if (filename_str[0] != '/')
+	filename_str.insert (0, db_path);
+
+    /* Flags are everything behind ":" */
+    position = filename_str.find (":");
+    flags = filename_str.substr (position + 3); /* We don't want :2, */
+    message->flags = talloc_strdup (message, flags.c_str ());
+
+    return message->flags;
+}
+
 time_t
 notmuch_message_get_date (notmuch_message_t *message)
 {
diff --git a/lib/notmuch.h b/lib/notmuch.h
index a61cd02..1da5dfd 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -694,6 +694,16 @@ notmuch_message_get_replies (notmuch_message_t *message);
 const char *
 notmuch_message_get_filename (notmuch_message_t *message);
 
+/* Get the maildir flags for the email corresponding to 'message'.
+ *
+ * The returned flags will be a string of ascii format flags.
+ *
+ * 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). */
+const char *
+notmuch_message_get_flags (notmuch_message_t *message);
+
 /* Get the date of 'message' as a time_t value.
  *
  * For the original textual representation of the Date header from the
-- 
1.6.5.3



More information about the notmuch mailing list