X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-show.c;h=084b7dab78e59423a03137ad57bf18b6a68835e1;hp=3ce4b63cf5046492ab39ebf5ee865ecd72bb785b;hb=15815d4e4c95e87f0bcabcaeb2577237609a6946;hpb=ab022657776af0bb47e72caf2517464ca59e7d48 diff --git a/notmuch-show.c b/notmuch-show.c index 3ce4b63c..084b7dab 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -340,6 +340,48 @@ signature_status_to_string (GMimeSignatureStatus x) return "unknown"; } + +/* Print signature flags */ +struct key_map_struct { + GMimeSignatureError bit; + const char * string; +}; + +static void +do_format_signature_errors (sprinter_t *sp, struct key_map_struct *key_map, + unsigned int array_map_len, GMimeSignatureError errors) { + sp->map_key (sp, "errors"); + sp->begin_map (sp); + + for (unsigned int i = 0; i < array_map_len; i++) { + if (errors & key_map[i].bit) { + sp->map_key (sp, key_map[i].string); + sp->boolean (sp, TRUE); + } + } + + sp->end (sp); +} + +static void +format_signature_errors (sprinter_t *sp, GMimeSignature *signature) +{ + GMimeSignatureError errors = g_mime_signature_get_errors (signature); + + if (errors == GMIME_SIGNATURE_ERROR_NONE) + return; + + struct key_map_struct key_map[] = { + { GMIME_SIGNATURE_ERROR_EXPSIG, "sig-expired" }, + { GMIME_SIGNATURE_ERROR_NO_PUBKEY, "key-missing"}, + { GMIME_SIGNATURE_ERROR_EXPKEYSIG, "key-expired"}, + { GMIME_SIGNATURE_ERROR_REVKEYSIG, "key-revoked"}, + { GMIME_SIGNATURE_ERROR_UNSUPP_ALGO, "alg-unsupported"}, + }; + + do_format_signature_errors (sp, key_map, ARRAY_SIZE(key_map), errors); +} + /* Signature status sprinter (GMime 2.6) */ static void format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node) @@ -404,10 +446,14 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node) } } - GMimeSignatureError errors = g_mime_signature_get_errors (signature); - if (errors != GMIME_SIGNATURE_ERROR_NONE) { - sp->map_key (sp, "errors"); - sp->integer (sp, errors); + if (notmuch_format_version <= 3) { + GMimeSignatureError errors = g_mime_signature_get_errors (signature); + if (errors != GMIME_SIGNATURE_ERROR_NONE) { + sp->map_key (sp, "errors"); + sp->integer (sp, errors); + } + } else { + format_signature_errors (sp, signature); } sp->end (sp); @@ -1009,18 +1055,6 @@ static const notmuch_show_format_t *formatters[] = { [NOTMUCH_FORMAT_RAW] = &format_raw, }; -enum { - ENTIRE_THREAD_DEFAULT = -1, - ENTIRE_THREAD_FALSE = FALSE, - ENTIRE_THREAD_TRUE = TRUE, -}; - -/* The following is to allow future options to be added more easily */ -enum { - EXCLUDE_TRUE, - EXCLUDE_FALSE, -}; - int notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) { @@ -1036,8 +1070,11 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) .output_body = TRUE, }; int format = NOTMUCH_FORMAT_NOT_SPECIFIED; - int exclude = EXCLUDE_TRUE; - int entire_thread = ENTIRE_THREAD_DEFAULT; + int exclude = TRUE; + + /* This value corresponds to neither true nor false being passed + * on the command line */ + int entire_thread = -1; notmuch_bool_t single_message; notmuch_opt_desc_t options[] = { @@ -1049,15 +1086,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) { "raw", NOTMUCH_FORMAT_RAW }, { 0, 0 } } }, { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }, - { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x', - (notmuch_keyword_t []){ { "true", EXCLUDE_TRUE }, - { "false", EXCLUDE_FALSE }, - { 0, 0 } } }, - { NOTMUCH_OPT_KEYWORD, &entire_thread, "entire-thread", 't', - (notmuch_keyword_t []){ { "true", ENTIRE_THREAD_TRUE }, - { "false", ENTIRE_THREAD_FALSE }, - { "", ENTIRE_THREAD_TRUE }, - { 0, 0 } } }, + { NOTMUCH_OPT_BOOLEAN, &exclude, "exclude", 'x', 0 }, + { NOTMUCH_OPT_BOOLEAN, &entire_thread, "entire-thread", 't', 0 }, { NOTMUCH_OPT_INT, ¶ms.part, "part", 'p', 0 }, { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 }, { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.verify, "verify", 'v', 0 }, @@ -1102,7 +1132,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) /* Default is entire-thread = FALSE except for format=json and * format=sexp. */ - if (entire_thread == ENTIRE_THREAD_DEFAULT) { + if (entire_thread != FALSE && entire_thread != TRUE) { if (format == NOTMUCH_FORMAT_JSON || format == NOTMUCH_FORMAT_SEXP) params.entire_thread = TRUE; else @@ -1182,7 +1212,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) } } - if (exclude == EXCLUDE_FALSE) { + if (exclude == FALSE) { notmuch_query_set_omit_excluded (query, FALSE); params.omit_excluded = FALSE; }