X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-reply.c;h=1357142903d5771566678a132f15c6537e4e7714;hp=47993d223090ee423b7c42126122dcd688215c8b;hb=23180439cb632e5565e9e3dfd8172c997262bf4c;hpb=998a8a95c3cd19950b78c50912345669952ba3eb diff --git a/notmuch-reply.c b/notmuch-reply.c index 47993d22..13571429 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -21,6 +21,7 @@ */ #include "notmuch-client.h" +#include "string-util.h" #include "sprinter.h" static void @@ -465,14 +466,21 @@ guess_from_in_received_headers (notmuch_config_t *config, notmuch_message_t *message) { const char *received, *addr; + char *sanitized; received = notmuch_message_get_header (message, "received"); if (! received) return NULL; - addr = guess_from_in_received_for (config, received); + sanitized = sanitize_string (NULL, received); + if (! sanitized) + return NULL; + + addr = guess_from_in_received_for (config, sanitized); if (! addr) - addr = guess_from_in_received_by (config, received); + addr = guess_from_in_received_by (config, sanitized); + + talloc_free (sanitized); return addr; } @@ -598,8 +606,13 @@ notmuch_reply_format_default(void *ctx, notmuch_messages_t *messages; notmuch_message_t *message; mime_node_t *root; + notmuch_status_t status; - for (messages = notmuch_query_search_messages (query); + status = notmuch_query_search_messages_st (query, &messages); + if (print_status_query ("notmuch reply", query, status)) + return 1; + + for (; notmuch_messages_valid (messages); notmuch_messages_move_to_next (messages)) { @@ -642,13 +655,22 @@ notmuch_reply_format_sprinter(void *ctx, notmuch_messages_t *messages; notmuch_message_t *message; mime_node_t *node; + unsigned count; + notmuch_status_t status; + + status = notmuch_query_count_messages_st (query, &count); + if (print_status_query ("notmuch reply", query, status)) + return 1; - if (notmuch_query_count_messages (query) != 1) { + if (count != 1) { fprintf (stderr, "Error: search term did not match precisely one message.\n"); return 1; } - messages = notmuch_query_search_messages (query); + status = notmuch_query_search_messages_st (query, &messages); + if (print_status_query ("notmuch reply", query, status)) + return 1; + message = notmuch_messages_get (messages); if (mime_node_open (ctx, message, &(params->crypto), &node) != NOTMUCH_STATUS_SUCCESS) return 1; @@ -690,8 +712,13 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_message_t *message; const char *in_reply_to, *orig_references, *references; char *reply_headers; + notmuch_status_t status; + + status = notmuch_query_search_messages_st (query, &messages); + if (print_status_query ("notmuch reply", query, status)) + return 1; - for (messages = notmuch_query_search_messages (query); + for (; notmuch_messages_valid (messages); notmuch_messages_move_to_next (messages)) { @@ -761,7 +788,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]) .part = -1, .crypto = { .verify = FALSE, - .decrypt = FALSE + .decrypt = FALSE, + .gpgpath = NULL } }; int format = FORMAT_DEFAULT; @@ -781,6 +809,7 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]) { "sender", FALSE }, { 0, 0 } } }, { NOTMUCH_OPT_BOOLEAN, ¶ms.crypto.decrypt, "decrypt", 'd', 0 }, + { NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 }, { 0, 0, 0, 0, 0 } }; @@ -788,6 +817,8 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]) if (opt_index < 0) return EXIT_FAILURE; + notmuch_process_shared_options (argv[0]); + if (format == FORMAT_HEADERS_ONLY) { reply_format_func = notmuch_reply_format_headers_only; } else if (format == FORMAT_JSON) { @@ -813,10 +844,14 @@ notmuch_reply_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");