[PATCH v2 07/11] lib: thread: add thread total size function

Ioan-Adrian Ratiu adi at adirat.com
Thu May 18 15:27:04 PDT 2017


Given a thread object this function computes the total disk space used
by all messages contained in the thread.

Signed-off-by: Ioan-Adrian Ratiu <adi at adirat.com>
---
 lib/notmuch.h |  7 +++++++
 lib/thread.cc | 12 ++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/lib/notmuch.h b/lib/notmuch.h
index b7bf3526..4f2afbe4 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1185,6 +1185,13 @@ time_t
 notmuch_thread_get_newest_date (notmuch_thread_t *thread);
 
 /**
+ * Get the total disk space used by the thread i.e. a sum of the
+ * thread messages filesizes.
+ */
+unsigned long
+notmuch_thread_get_total_filesize (notmuch_thread_t *thread);
+
+/**
  * Get the tags for 'thread', returning a notmuch_tags_t object which
  * can be used to iterate over all tags.
  *
diff --git a/lib/thread.cc b/lib/thread.cc
index 1a1ecfa5..72878b62 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -596,6 +596,18 @@ notmuch_thread_get_newest_date (notmuch_thread_t *thread)
     return thread->newest;
 }
 
+unsigned long
+notmuch_thread_get_total_filesize (notmuch_thread_t *thread)
+{
+    notmuch_message_node_t *node;
+    unsigned long total_filesize = 0;
+
+    for (node = thread->message_list->head; node; node = node->next)
+	total_filesize += notmuch_message_get_filesize (node->message);
+
+    return total_filesize;
+}
+
 notmuch_tags_t *
 notmuch_thread_get_tags (notmuch_thread_t *thread)
 {
-- 
2.13.0



More information about the notmuch mailing list