X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-show.c;h=ef675b4ded411e5db31b83fff86b740e7b73572c;hp=d416fbd5ccb73593ec44fd976bd331de0bf13be6;hb=33944a559a4ae7589347b7e7a3da5dd810a4c136;hpb=ecbb29e8cea404faab2ef55b06431942ee329941 diff --git a/notmuch-show.c b/notmuch-show.c index d416fbd5..ef675b4d 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -13,7 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/ . + * along with this program. If not, see https://www.gnu.org/licenses/ . * * Author: Carl Worth */ @@ -110,6 +110,17 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message) from, relative_date, tags); } +static const char *_get_disposition(GMimeObject *meta) +{ + GMimeContentDisposition *disposition; + + disposition = g_mime_object_get_content_disposition (meta); + if (!disposition) + return NULL; + + return g_mime_content_disposition_get_disposition (disposition); +} + /* Emit a sequence of key/value pairs for the metadata of message. * The caller should begin a map before calling this. */ static void @@ -133,7 +144,20 @@ format_message_sprinter (sprinter_t *sp, notmuch_message_t *message) sp->boolean (sp, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED)); sp->map_key (sp, "filename"); - sp->string (sp, notmuch_message_get_filename (message)); + if (notmuch_format_version >= 3) { + notmuch_filenames_t *filenames; + + sp->begin_list (sp); + for (filenames = notmuch_message_get_filenames (message); + notmuch_filenames_valid (filenames); + notmuch_filenames_move_to_next (filenames)) { + sp->string (sp, notmuch_filenames_get (filenames)); + } + notmuch_filenames_destroy (filenames); + sp->end (sp); + } else { + sp->string (sp, notmuch_message_get_filename (message)); + } sp->map_key (sp, "timestamp"); date = notmuch_message_get_date (message); @@ -334,8 +358,6 @@ show_text_part_content (GMimeObject *part, GMimeStream *stream_out, g_object_unref(stream_filter); } -#ifdef GMIME_ATLEAST_26 - /* Get signature status string (GMime 2.6) */ static const char* signature_status_to_string (GMimeSignatureStatus x) @@ -427,91 +449,6 @@ format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node) sp->end (sp); } -#else /* GMIME_ATLEAST_26 */ - -/* Get signature status string (GMime 2.4) */ -static const char* -signer_status_to_string (GMimeSignerStatus x) -{ - switch (x) { - case GMIME_SIGNER_STATUS_NONE: - return "none"; - case GMIME_SIGNER_STATUS_GOOD: - return "good"; - case GMIME_SIGNER_STATUS_BAD: - return "bad"; - case GMIME_SIGNER_STATUS_ERROR: - return "error"; - } - return "unknown"; -} - -/* Signature status sprinter (GMime 2.4) */ -static void -format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node) -{ - const GMimeSignatureValidity* validity = node->sig_validity; - - sp->begin_list (sp); - - if (!validity) { - sp->end (sp); - return; - } - - const GMimeSigner *signer = g_mime_signature_validity_get_signers (validity); - while (signer) { - sp->begin_map (sp); - - /* status */ - sp->map_key (sp, "status"); - sp->string (sp, signer_status_to_string (signer->status)); - - if (signer->status == GMIME_SIGNER_STATUS_GOOD) - { - if (signer->fingerprint) { - sp->map_key (sp, "fingerprint"); - sp->string (sp, signer->fingerprint); - } - /* these dates are seconds since the epoch; should we - * provide a more human-readable format string? */ - if (signer->created) { - sp->map_key (sp, "created"); - sp->integer (sp, signer->created); - } - if (signer->expires) { - sp->map_key (sp, "expires"); - sp->integer (sp, signer->expires); - } - /* output user id only if validity is FULL or ULTIMATE. */ - /* note that gmime is using the term "trust" here, which - * is WRONG. It's actually user id "validity". */ - if ((signer->name) && (signer->trust)) { - if ((signer->trust == GMIME_SIGNER_TRUST_FULLY) || (signer->trust == GMIME_SIGNER_TRUST_ULTIMATE)) { - sp->map_key (sp, "userid"); - sp->string (sp, signer->name); - } - } - } else { - if (signer->keyid) { - sp->map_key (sp, "keyid"); - sp->string (sp, signer->keyid); - } - } - if (signer->errors != GMIME_SIGNER_ERROR_NONE) { - sp->map_key (sp, "errors"); - sp->integer (sp, signer->errors); - } - - sp->end (sp); - signer = signer->next; - } - - sp->end (sp); -} - -#endif /* GMIME_ATLEAST_26 */ - static notmuch_status_t format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, int indent, const notmuch_show_params_t *params) @@ -537,13 +474,13 @@ format_part_text (const void *ctx, sprinter_t *sp, mime_node_t *node, notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0, notmuch_message_get_filename (message)); } else { - GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta); + const char *disposition = _get_disposition (meta); const char *cid = g_mime_object_get_content_id (meta); const char *filename = leaf ? g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; if (disposition && - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) + strcasecmp (disposition, GMIME_DISPOSITION_ATTACHMENT) == 0) part_type = "attachment"; else part_type = "part"; @@ -658,6 +595,7 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node, GMimeObject *meta = node->envelope_part ? GMIME_OBJECT (node->envelope_part) : node->part; GMimeContentType *content_type = g_mime_object_get_content_type (meta); + const char *disposition = _get_disposition (meta); const char *cid = g_mime_object_get_content_id (meta); const char *filename = GMIME_IS_PART (node->part) ? g_mime_part_get_filename (GMIME_PART (node->part)) : NULL; @@ -687,6 +625,11 @@ format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node, sp->map_key (sp, "content-type"); sp->string (sp, g_mime_content_type_to_string (content_type)); + if (disposition) { + sp->map_key (sp, "content-disposition"); + sp->string (sp, disposition); + } + if (cid) { sp->map_key (sp, "content-id"); sp->string (sp, cid); @@ -982,13 +925,22 @@ do_show_single (void *ctx, { notmuch_messages_t *messages; notmuch_message_t *message; + notmuch_status_t status; + unsigned int count; - if (notmuch_query_count_messages (query) != 1) { - fprintf (stderr, "Error: search term did not match precisely one message.\n"); + status = notmuch_query_count_messages_st (query, &count); + if (print_status_query ("notmuch show", query, status)) + return 1; + + if (count != 1) { + fprintf (stderr, "Error: search term did not match precisely one message (matched %d messages).\n", count); return 1; } - messages = notmuch_query_search_messages (query); + status = notmuch_query_search_messages_st (query, &messages); + if (print_status_query ("notmuch show", query, status)) + return 1; + message = notmuch_messages_get (messages); if (message == NULL) { @@ -1015,8 +967,8 @@ do_show (void *ctx, notmuch_messages_t *messages; notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS; - threads = notmuch_query_search_threads (query); - if (! threads) + status= notmuch_query_search_threads_st (query, &threads); + if (print_status_query ("notmuch show", query, status)) return 1; sp->begin_list (sp); @@ -1082,13 +1034,15 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) .output_body = TRUE, .crypto = { .verify = FALSE, - .decrypt = FALSE + .decrypt = FALSE, + .gpgpath = NULL }, .include_html = FALSE }; int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED; int exclude = EXCLUDE_TRUE; int entire_thread = ENTIRE_THREAD_DEFAULT; + notmuch_bool_t single_message; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f', @@ -1113,6 +1067,7 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.verify, "verify", 'v', 0 }, { NOTMUCH_OPT_BOOLEAN, ¶ms.output_body, "body", 'b', 0 }, { NOTMUCH_OPT_BOOLEAN, ¶ms.include_html, "include-html", 0, 0 }, + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, { 0, 0, 0, 0, 0 } }; @@ -1120,10 +1075,15 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) if (opt_index < 0) return EXIT_FAILURE; + notmuch_process_shared_options (argv[0]); + /* decryption implies verification */ if (params.crypto.decrypt) params.crypto.verify = TRUE; + /* specifying a part implies single message display */ + single_message = params.part >= 0; + if (format_sel == NOTMUCH_FORMAT_NOT_SPECIFIED) { /* if part was requested and format was not specified, use format=raw */ if (params.part >= 0) @@ -1152,11 +1112,8 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) break; case NOTMUCH_FORMAT_RAW: format = &format_raw; - /* If --format=raw specified without specifying part, we can only - * output single message, so set part=0 */ - if (params.part < 0) - params.part = 0; - params.raw = TRUE; + /* raw format only supports single message display */ + single_message = TRUE; break; } @@ -1203,10 +1160,14 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; } + params.crypto.gpgpath = notmuch_config_get_crypto_gpg_path (config); + if (notmuch_database_open (notmuch_config_get_database_path (config), NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much)) return EXIT_FAILURE; + notmuch_exit_if_unmatched_db_uuid (notmuch); + query = notmuch_query_create (notmuch, query_string); if (query == NULL) { fprintf (stderr, "Out of memory\n"); @@ -1217,9 +1178,9 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[]) sprinter = format->new_sprinter(config, stdout); /* If a single message is requested we do not use search_excludes. */ - if (params.part >= 0) + if (single_message) { ret = do_show_single (config, query, format, sprinter, ¶ms); - else { + } else { /* We always apply set the exclude flag. The * exclude=true|false option controls whether or not we return * threads that only match in an excluded message */