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 170AB431FC9 for ; Tue, 24 Nov 2009 17:35:18 -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 QNlxXLGaMvD4 for ; Tue, 24 Nov 2009 17:35:17 -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 8E5F3431FBC for ; Tue, 24 Nov 2009 17:35:16 -0800 (PST) Received: by mail-bw0-f224.google.com with SMTP id 24so5514914bwz.30 for ; Tue, 24 Nov 2009 17:35:16 -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=4++x3HFF3KcDPZFjuT4QxhwyOx5q35MMbfUt16Z7yH4=; b=R/rL30kLrIK13ulDwxYZ8nujKqpCVp7ePmxZrzWBs/uQTxjnfpBpY7RNtRkxLSsxCf dIZoMeqH+K+rYwQnCPLYe2nTeHyKGEp3zlFK5uv7EsSwFj66i6WtsWSyrB0vPwQbpP6P X1RbOIiCWsnx8cCIXBJ1O2XHSAI0uWyHyJXNA= 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=rTeWZQTtNo/9E2wDebkT8ASo3/LJfDsEacaqYSIUNF0xmy5m0sGAqbVqGW2wWVl/oU FwSdlupfcI8Hs6dxH6rFFopLxfFPd9MXGTfwhyFWXNtImyZM3tVJQ0pZh2GTP/R25B3D A4dtLiKGz7QHnSjkv7g3TWg/l/ZusF1RyyA2o= Received: by 10.204.150.68 with SMTP id x4mr6803275bkv.151.1259112916316; Tue, 24 Nov 2009 17:35:16 -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.14 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 24 Nov 2009 17:35:15 -0800 (PST) Sender: Jed Brown From: Jed Brown To: notmuch@notmuchmail.org Date: Wed, 25 Nov 2009 02:35:14 +0100 Message-Id: <1259112914-19806-3-git-send-email-jed@59A2.org> X-Mailer: git-send-email 1.6.5.3 In-Reply-To: <1259112914-19806-2-git-send-email-jed@59A2.org> References: <1259112914-19806-1-git-send-email-jed@59A2.org> <1259112914-19806-2-git-send-email-jed@59A2.org> Subject: [notmuch] [PATCH 2/2] notmuch-reply.c: implement notmuch_reply_format_headers_only 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:18 -0000 This command only generates References, To, and Cc headers. The purpose is primarily for use in git send-email --notmuch id: to get proper threading and address the relevant parties. Hooks for other SCMs may come later. Signed-off-by: Jed Brown --- notmuch-reply.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index 17eb38d..e85568c 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -283,6 +283,74 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ return 0; } +/* This format is currently tuned for a git send-email --notmuch hook */ +static int +notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +{ + GMimeMessage *reply; + notmuch_messages_t *messages; + notmuch_message_t *message; + const char *recipients, *in_reply_to, *orig_references, *references; + char *reply_headers; + unsigned int i; + + for (messages = notmuch_query_search_messages (query); + notmuch_messages_has_more (messages); + notmuch_messages_advance (messages)) + { + message = notmuch_messages_get (messages); + + /* The 0 means we do not want headers in a "pretty" order. */ + reply = g_mime_message_new (0); + if (reply == NULL) { + fprintf (stderr, "Out of memory\n"); + return 1; + } + + in_reply_to = talloc_asprintf (ctx, "<%s>", + notmuch_message_get_message_id (message)); + + orig_references = notmuch_message_get_header (message, "references"); + + /* We print References first because git format-patch treats it specially. + * Git uses the first entry of References to create In-Reply-To. + */ + references = talloc_asprintf (ctx, "%s%s%s", + in_reply_to, + orig_references ? orig_references : "", + orig_references ? " " : ""); + g_mime_object_set_header (GMIME_OBJECT (reply), + "References", references); + + for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { + const char *addr; + + recipients = notmuch_message_get_header (message, + reply_to_map[i].header); + if ((recipients == NULL || recipients[0] == '\0') && reply_to_map[i].fallback) + recipients = notmuch_message_get_header (message, + reply_to_map[i].fallback); + + addr = add_recipients_for_string (reply, config, + reply_to_map[i].recipient_type, + recipients); + } + + g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc", + notmuch_config_get_user_primary_email (config)); + + reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply)); + printf ("%s", reply_headers); + free (reply_headers); + + g_object_unref (G_OBJECT (reply)); + reply = NULL; + + notmuch_message_destroy (message); + } + return 0; +} + int notmuch_reply_command (void *ctx, int argc, char *argv[]) { @@ -304,6 +372,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) opt = argv[i] + sizeof ("--format=") - 1; if (strcmp (opt, "default") == 0) { reply_format_func = notmuch_reply_format_default; + } else if (strcmp (opt, "headers-only") == 0) { + reply_format_func = notmuch_reply_format_headers_only; } else { fprintf (stderr, "Invalid value for --format: %s\n", opt); return 1; -- 1.6.5.3