const char *thread_id);
void
-_notmuch_thread_add_tag (notmuch_thread_t *thread, const char *tag);
-
-void
-_notmuch_thread_set_subject (notmuch_thread_t *thread, const char *subject);
+_notmuch_thread_add_message (notmuch_thread_t *thread,
+ notmuch_message_t *message);
/* message.cc */
return query_string;
}
-static int
-search_command (int argc, char *argv[])
-{
- void *local = talloc_new (NULL);
- notmuch_database_t *notmuch = NULL;
- notmuch_query_t *query;
- notmuch_thread_results_t *results;
- notmuch_thread_t *thread;
- notmuch_tags_t *tags;
- char *query_str;
- notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
-
- notmuch = notmuch_database_open (NULL);
- if (notmuch == NULL) {
- ret = 1;
- goto DONE;
- }
-
- query_str = query_string_from_args (local, argc, argv);
-
- query = notmuch_query_create (notmuch, query_str);
- if (query == NULL) {
- fprintf (stderr, "Out of memory\n");
- ret = 1;
- goto DONE;
- }
-
- for (results = notmuch_query_search_threads (query);
- notmuch_thread_results_has_more (results);
- notmuch_thread_results_advance (results))
- {
- int first = 1;
-
- thread = notmuch_thread_results_get (results);
-
- printf ("%s %s",
- notmuch_thread_get_thread_id (thread),
- notmuch_thread_get_subject (thread));
-
- printf (" (");
- for (tags = notmuch_thread_get_tags (thread);
- notmuch_tags_has_more (tags);
- notmuch_tags_advance (tags))
- {
- if (! first)
- printf (" ");
- printf ("%s", notmuch_tags_get (tags));
- first = 0;
- }
- printf (")\n");
-
- notmuch_thread_destroy (thread);
- }
-
- notmuch_query_destroy (query);
-
- DONE:
- if (notmuch)
- notmuch_database_close (notmuch);
- talloc_free (local);
-
- return ret;
-}
-
/* Format a nice representation of 'time' relative to the current time.
*
* Examples include:
#undef HOUR
#undef DAY
+static int
+search_command (int argc, char *argv[])
+{
+ void *local = talloc_new (NULL);
+ notmuch_database_t *notmuch = NULL;
+ notmuch_query_t *query;
+ notmuch_thread_results_t *results;
+ notmuch_thread_t *thread;
+ notmuch_tags_t *tags;
+ char *query_str;
+ const char *relative_date;
+ time_t date;
+ notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
+
+ notmuch = notmuch_database_open (NULL);
+ if (notmuch == NULL) {
+ ret = 1;
+ goto DONE;
+ }
+
+ query_str = query_string_from_args (local, argc, argv);
+
+ query = notmuch_query_create (notmuch, query_str);
+ if (query == NULL) {
+ fprintf (stderr, "Out of memory\n");
+ ret = 1;
+ goto DONE;
+ }
+
+ for (results = notmuch_query_search_threads (query);
+ notmuch_thread_results_has_more (results);
+ notmuch_thread_results_advance (results))
+ {
+ int first = 1;
+
+ thread = notmuch_thread_results_get (results);
+
+ date = notmuch_thread_get_oldest_date (thread);
+ relative_date = _format_relative_date (local, date);
+
+ printf ("%s (%s) %s",
+ notmuch_thread_get_thread_id (thread),
+ relative_date,
+ notmuch_thread_get_subject (thread));
+
+ printf (" (");
+ for (tags = notmuch_thread_get_tags (thread);
+ notmuch_tags_has_more (tags);
+ notmuch_tags_advance (tags))
+ {
+ if (! first)
+ printf (" ");
+ printf ("%s", notmuch_tags_get (tags));
+ first = 0;
+ }
+ printf (")\n");
+
+ notmuch_thread_destroy (thread);
+ }
+
+ notmuch_query_destroy (query);
+
+ DONE:
+ if (notmuch)
+ notmuch_database_close (notmuch);
+ talloc_free (local);
+
+ return ret;
+}
+
/* Get a nice, single-line summary of message. */
static const char *
_get_one_line_summary (void *ctx, notmuch_message_t *message)
const char *
notmuch_thread_get_subject (notmuch_thread_t *thread);
+/* Get the date of the oldest message in 'thread' as a time_t value.
+ */
+time_t
+notmuch_thread_get_oldest_date (notmuch_thread_t *thread);
+
+/* Get the date of the oldest message in 'thread' as a time_t value.
+ */
+time_t
+notmuch_thread_get_newest_date (notmuch_thread_t *thread);
+
/* Get the tags for 'thread', returning a notmuch_tags_t object which
* can be used to iterate over all tags.
*
const char *thread_id;
notmuch_message_results_t *message_results;
notmuch_message_t *message;
- notmuch_tags_t *tags;
- const char *tag;
GHashTable *seen;
thread_results = talloc (query, notmuch_thread_results_t);
thread_id, NULL,
(void **) &thread))
{
- const char *subject;
-
thread = _notmuch_thread_create (query, query->notmuch,
thread_id);
- subject = notmuch_message_get_header (message, "subject");
-
- _notmuch_thread_set_subject (thread, subject);
-
g_hash_table_insert (seen, xstrdup (thread_id), thread);
g_ptr_array_add (thread_results->threads, thread);
}
- for (tags = notmuch_message_get_tags (message);
- notmuch_tags_has_more (tags);
- notmuch_tags_advance (tags))
- {
- tag = notmuch_tags_get (tags);
- _notmuch_thread_add_tag (thread, tag);
- }
+ _notmuch_thread_add_message (thread, message);
notmuch_message_destroy (message);
}
char *thread_id;
char *subject;
GHashTable *tags;
+
+ notmuch_bool_t has_message;
+ time_t oldest;
+ time_t newest;
};
static int
thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
free, NULL);
+ thread->has_message = 0;
+ thread->oldest = 0;
+ thread->newest = 0;
+
return thread;
}
}
void
-_notmuch_thread_add_tag (notmuch_thread_t *thread, const char *tag)
+_notmuch_thread_add_message (notmuch_thread_t *thread,
+ notmuch_message_t *message)
{
- g_hash_table_insert (thread->tags, xstrdup (tag), NULL);
-}
+ notmuch_tags_t *tags;
+ const char *tag;
+ time_t date;
-void
-_notmuch_thread_set_subject (notmuch_thread_t *thread, const char *subject)
-{
- thread->subject = talloc_strdup (thread, subject);
+ if (! thread->subject) {
+ const char *subject;
+ subject = notmuch_message_get_header (message, "subject");
+ thread->subject = talloc_strdup (thread, subject);
+ }
+
+ for (tags = notmuch_message_get_tags (message);
+ notmuch_tags_has_more (tags);
+ notmuch_tags_advance (tags))
+ {
+ tag = notmuch_tags_get (tags);
+ g_hash_table_insert (thread->tags, xstrdup (tag), NULL);
+ }
+
+ date = notmuch_message_get_date (message);
+
+ if (date < thread->oldest || ! thread->has_message)
+ thread->oldest = date;
+
+ if (date > thread->newest || ! thread->has_message)
+ thread->newest = date;
+
+ thread->has_message = 1;
}
const char *
return thread->subject;
}
+time_t
+notmuch_thread_get_oldest_date (notmuch_thread_t *thread)
+{
+ return thread->oldest;
+}
+
+time_t
+notmuch_thread_get_newest_date (notmuch_thread_t *thread)
+{
+ return thread->newest;
+}
+
notmuch_tags_t *
notmuch_thread_get_tags (notmuch_thread_t *thread)
{