Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id B45A5431FBC for ; Tue, 24 Nov 2009 17:35:12 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ypHYMU4q4yqe for ; Tue, 24 Nov 2009 17:35:12 -0800 (PST) Received: from mail-bw0-f224.google.com (mail-bw0-f224.google.com [209.85.218.224]) by olra.theworths.org (Postfix) with ESMTP id D0FE0431FC2 for ; Tue, 24 Nov 2009 17:35:11 -0800 (PST) Received: by mail-bw0-f224.google.com with SMTP id 24so5514914bwz.30 for ; Tue, 24 Nov 2009 17:35:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:cc:subject :date:message-id:x-mailer:in-reply-to:references; bh=ZwuYLICj5WOi56vRA5vpD22zPJ0OU2fik+/HhvuZnX4=; b=lD2s99vp6nNo1oVlz01oHKRPq9VUpp8xE23ATFlRuSY/AtJKhowdXKxcx1nX07xeiC 4lwvS5/09ZDnCyBO5Tm4JZGOppPKI4lX2HF1f0F1ijkwIn5RQ3T644cngmeUxPmcpRJM qo8R4B249jvqHnZks5cdpCQpykQadlrex+0CA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=bRIDD2dDu2cXUtH8Auvria0nF4Y7jFpPeuQLdwZ7/oNSsT4FE0lVef9zCg9UfErRRf irsZIH0zginzx1GJM7WVczvxyOcH375/1tYlkFCU1/YZDRewm2JKLcdl/tFLieEACz9w kPpjaTHUTTlk2JW5yXJbtJAHBKcrGqE1WZ92A= Received: by 10.204.10.8 with SMTP id n8mr6923194bkn.48.1259112911049; Tue, 24 Nov 2009 17:35:11 -0800 (PST) Received: from localhost.localdomain (vawpc43.ethz.ch [129.132.59.11]) by mx.google.com with ESMTPS id 35sm7911394fkt.40.2009.11.24.17.35.09 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 24 Nov 2009 17:35:10 -0800 (PST) Sender: Jed Brown From: Jed Brown To: notmuch@notmuchmail.org Date: Wed, 25 Nov 2009 02:35:13 +0100 Message-Id: <1259112914-19806-2-git-send-email-jed@59A2.org> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <1259112914-19806-1-git-send-email-jed@59A2.org> References: <1259112914-19806-1-git-send-email-jed@59A2.org> Subject: [notmuch] [PATCH 1/2] notmuch-reply.c: accept the --format=default default option. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2009 01:35:12 -0000 This factors actual generation of the reply out of notmuch_reply_command into notmuch_reply_format_default(), in preparation for other --format= options. Signed-off-by: Jed Brown --- notmuch-reply.c | 121 +++++++++++++++++++++++++++++++++++------------------- 1 files changed, 78 insertions(+), 43 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index 65bd356..17eb38d 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -23,6 +23,17 @@ #include "notmuch-client.h" #include "gmime-filter-reply.h" +static const struct { + const char *header; + const char *fallback; + GMimeRecipientType recipient_type; +} reply_to_map[] = { + { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO }, + { "to", NULL, GMIME_RECIPIENT_TYPE_TO }, + { "cc", NULL, GMIME_RECIPIENT_TYPE_CC }, + { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC } +}; + static void reply_part_content (GMimeObject *part) { @@ -182,58 +193,17 @@ add_recipients_for_string (GMimeMessage *message, return add_recipients_for_address_list (message, config, type, list); } -int -notmuch_reply_command (void *ctx, int argc, char *argv[]) +static int +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query) { - notmuch_config_t *config; - notmuch_database_t *notmuch; - notmuch_query_t *query; GMimeMessage *reply; - char *query_string; notmuch_messages_t *messages; notmuch_message_t *message; - int ret = 0; const char *subject, *recipients, *from_addr = NULL; const char *in_reply_to, *orig_references, *references; char *reply_headers; - struct { - const char *header; - const char *fallback; - GMimeRecipientType recipient_type; - } reply_to_map[] = { - { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO }, - { "to", NULL, GMIME_RECIPIENT_TYPE_TO }, - { "cc", NULL, GMIME_RECIPIENT_TYPE_CC }, - { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC } - }; unsigned int i; - config = notmuch_config_open (ctx, NULL, NULL); - if (config == NULL) - return 1; - - query_string = query_string_from_args (ctx, argc, argv); - if (query_string == NULL) { - fprintf (stderr, "Out of memory\n"); - return 1; - } - - if (*query_string == '\0') { - fprintf (stderr, "Error: notmuch reply requires at least one search term.\n"); - return 1; - } - - notmuch = notmuch_database_open (notmuch_config_get_database_path (config), - NOTMUCH_DATABASE_MODE_READ_ONLY); - if (notmuch == NULL) - return 1; - - query = notmuch_query_create (notmuch, query_string); - if (query == NULL) { - fprintf (stderr, "Out of memory\n"); - return 1; - } - for (messages = notmuch_query_search_messages (query); notmuch_messages_has_more (messages); notmuch_messages_advance (messages)) @@ -310,6 +280,71 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) notmuch_message_destroy (message); } + return 0; +} + +int +notmuch_reply_command (void *ctx, int argc, char *argv[]) +{ + notmuch_config_t *config; + notmuch_database_t *notmuch; + notmuch_query_t *query; + char *opt, *query_string; + int i, ret = 0; + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query); + + reply_format_func = notmuch_reply_format_default; + + for (i = 0; i < argc && argv[i][0] == '-'; i++) { + if (strcmp (argv[i], "--") == 0) { + i++; + break; + } + if (STRNCMP_LITERAL (argv[i], "--format=") == 0) { + opt = argv[i] + sizeof ("--format=") - 1; + if (strcmp (opt, "default") == 0) { + reply_format_func = notmuch_reply_format_default; + } else { + fprintf (stderr, "Invalid value for --format: %s\n", opt); + return 1; + } + } else { + fprintf (stderr, "Unrecognized option: %s\n", argv[i]); + return 1; + } + } + + argc -= i; + argv += i; + + config = notmuch_config_open (ctx, NULL, NULL); + if (config == NULL) + return 1; + + query_string = query_string_from_args (ctx, argc, argv); + if (query_string == NULL) { + fprintf (stderr, "Out of memory\n"); + return 1; + } + + if (*query_string == '\0') { + fprintf (stderr, "Error: notmuch reply requires at least one search term.\n"); + return 1; + } + + notmuch = notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_ONLY); + if (notmuch == NULL) + return 1; + + query = notmuch_query_create (notmuch, query_string); + if (query == NULL) { + fprintf (stderr, "Out of memory\n"); + return 1; + } + + if (reply_format_func (ctx, config, query) != 0) + return 1; notmuch_query_destroy (query); notmuch_database_close (notmuch); -- 1.6.5.3