]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-show.c
emacs: use --exclude=false when counting total messages
[notmuch] / notmuch-show.c
index 481e5d540a6f2c2cff23b0e33548726da13ed891..6a54d9c16a0684b28bbc9e98e2c62bed340ba03e 100644 (file)
@@ -209,6 +209,30 @@ _is_from_line (const char *line)
        return 0;
 }
 
+/* Output extra headers if configured with the `show.extra_headers'
+ * configuration option
+ */
+static void
+format_extra_headers_sprinter (sprinter_t *sp, GMimeMessage *message)
+{
+    GMimeHeaderList *header_list = g_mime_object_get_header_list (GMIME_OBJECT (message));
+
+    for (notmuch_config_values_t *extra_headers = notmuch_config_get_values (
+            sp->notmuch, NOTMUCH_CONFIG_EXTRA_HEADERS);
+        notmuch_config_values_valid (extra_headers);
+        notmuch_config_values_move_to_next (extra_headers)) {
+       GMimeHeader *header;
+       const char *header_name = notmuch_config_values_get (extra_headers);
+
+       header = g_mime_header_list_get_header (header_list, header_name);
+       if (header == NULL)
+           continue;
+
+       sp->map_key (sp, g_mime_header_get_name (header));
+       sp->string (sp, g_mime_header_get_value (header));
+    }
+}
+
 void
 format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
                         bool reply, const _notmuch_message_crypto_t *msg_crypto)
@@ -269,6 +293,9 @@ format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
        sp->string (sp, g_mime_message_get_date_string (sp, message));
     }
 
+    /* Output extra headers the user has configured, if any */
+    if (! reply)
+       format_extra_headers_sprinter (sp, message);
     sp->end (sp);
     talloc_free (local);
 }
@@ -475,6 +502,11 @@ format_part_sigstatus_sprinter (sprinter_t *sp, GMimeSignatureList *siglist)
                    sp->map_key (sp, "userid");
                    sp->string (sp, uid);
                }
+               const char *email = g_mime_certificate_get_valid_email (certificate);
+               if (email) {
+                   sp->map_key (sp, "email");
+                   sp->string (sp, email);
+               }
            }
        } else if (certificate) {
            const char *key_id = g_mime_certificate_get_fpr16 (certificate);
@@ -1225,8 +1257,7 @@ static const notmuch_show_format_t *formatters[] = {
 };
 
 int
-notmuch_show_command (unused (notmuch_config_t *config), notmuch_database_t *notmuch,
-                     int argc, char *argv[])
+notmuch_show_command (notmuch_database_t *notmuch, int argc, char *argv[])
 {
     notmuch_query_t *query;
     char *query_string;
@@ -1245,8 +1276,13 @@ notmuch_show_command (unused (notmuch_config_t *config), notmuch_database_t *not
     bool single_message;
     bool unthreaded = FALSE;
     notmuch_status_t status;
+    int sort = NOTMUCH_SORT_NEWEST_FIRST;
 
     notmuch_opt_desc_t options[] = {
+       { .opt_keyword = &sort, .name = "sort", .keywords =
+             (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },
+                                     { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },
+                                     { 0, 0 } } },
        { .opt_keyword = &format, .name = "format", .keywords =
              (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },
                                      { "text", NOTMUCH_FORMAT_TEXT },
@@ -1278,7 +1314,7 @@ notmuch_show_command (unused (notmuch_config_t *config), notmuch_database_t *not
     if (opt_index < 0)
        return EXIT_FAILURE;
 
-    notmuch_process_shared_options (argv[0]);
+    notmuch_process_shared_options (notmuch, argv[0]);
 
     /* explicit decryption implies verification */
     if (params.crypto.decrypt == NOTMUCH_DECRYPT_NOSTASH ||
@@ -1344,8 +1380,6 @@ notmuch_show_command (unused (notmuch_config_t *config), notmuch_database_t *not
        }
     }
 
-    notmuch_exit_if_unmatched_db_uuid (notmuch);
-
     query_string = query_string_from_args (notmuch, argc - opt_index, argv + opt_index);
     if (query_string == NULL) {
        fprintf (stderr, "Out of memory\n");
@@ -1357,11 +1391,13 @@ notmuch_show_command (unused (notmuch_config_t *config), notmuch_database_t *not
        return EXIT_FAILURE;
     }
 
-    query = notmuch_query_create (notmuch, query_string);
-    if (query == NULL) {
-       fprintf (stderr, "Out of memory\n");
+    status = notmuch_query_create_with_syntax (notmuch, query_string,
+                                              shared_option_query_syntax (),
+                                              &query);
+    if (print_status_database ("notmuch show", notmuch, status))
        return EXIT_FAILURE;
-    }
+
+    notmuch_query_set_sort (query, sort);
 
     /* Create structure printer. */
     formatter = formatters[format];