From 1dd95f3cecb127e8781598b1f2d0414914c55ffb Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Wed, 18 Apr 2012 15:39:11 +0300 Subject: [PATCH] [PATCH v2 1/3] Add 'compose' command --- b8/a9961eb2a320e0725b854d7e75d70001b980ba | 237 ++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 b8/a9961eb2a320e0725b854d7e75d70001b980ba diff --git a/b8/a9961eb2a320e0725b854d7e75d70001b980ba b/b8/a9961eb2a320e0725b854d7e75d70001b980ba new file mode 100644 index 000000000..bed53404c --- /dev/null +++ b/b8/a9961eb2a320e0725b854d7e75d70001b980ba @@ -0,0 +1,237 @@ +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 1A14D431FAE + for ; Wed, 18 Apr 2012 05:39:56 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +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 iUj6WZ0qMbjg for ; + Wed, 18 Apr 2012 05:39:51 -0700 (PDT) +Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com + [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 1ABAC431FC3 + for ; Wed, 18 Apr 2012 05:39:43 -0700 (PDT) +Received: by lbdb5 with SMTP id b5so2794488lbd.26 + for ; Wed, 18 Apr 2012 05:39:42 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references + :mime-version:content-type:content-transfer-encoding; + bh=DgLDlP4+izCFtyi+8mjMYjPEp4dtu4IPoIsktFOF0MM=; + b=n3b2/Xh3KAIM/rz3iUyRdazdOyFxyEhFlu/xb6biFqefdlMtqMjeBA2v9amr/tPqzU + fCucKgD3qHMVF30TYdkrB5naqewT1+qm6v2LYY89tYItbSC+76ILWzP4Ezd96ZN2h1pF + 6ImhadJK4DtF0Reb8aNhpzDdn4ZB/Q7QwfHteZvCL3anU4kRv06o65lKfeob3gMYBztO + n4gUVw7ddprX/0QuLl1HbP+Zjer+F3yGG8MNvhEcX4NhsKChhlGf88y3tSSqGVXvZaun + MG/zwsIEo7i3O17HwaS1hLss0T1mOeQCi9J4Vk7KuXlyPhz1bySwSKH4kLah0e/kLqKU + zisw== +Received: by 10.112.26.10 with SMTP id h10mr949974lbg.79.1334752782437; + Wed, 18 Apr 2012 05:39:42 -0700 (PDT) +Received: from localhost (85-156-70-103.elisa-mobile.fi. [85.156.70.103]) + by mx.google.com with ESMTPS id o2sm7352895lbd.7.2012.04.18.05.39.40 + (version=TLSv1/SSLv3 cipher=OTHER); + Wed, 18 Apr 2012 05:39:41 -0700 (PDT) +From: Felipe Contreras +To: notmuch@notmuchmail.org +Subject: =?UTF-8?q?=5BPATCH=20v2=201/3=5D=20Add=20=27compose=27=20command?= +Date: Wed, 18 Apr 2012 15:39:11 +0300 +Message-Id: <1334752753-23970-2-git-send-email-felipe.contreras@gmail.com> +X-Mailer: git-send-email 1.7.10 +In-Reply-To: <1334752753-23970-1-git-send-email-felipe.contreras@gmail.com> +References: <1334752753-23970-1-git-send-email-felipe.contreras@gmail.com> +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Cc: Felipe Contreras +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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, 18 Apr 2012 12:39:56 -0000 + +Signed-off-by: Felipe Contreras +--- + Makefile.local | 1 + + notmuch-client.h | 3 ++ + notmuch-compose.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++ + notmuch.c | 5 +++ + 4 files changed, 120 insertions(+) + create mode 100644 notmuch-compose.c + +diff --git a/Makefile.local b/Makefile.local +index 53b4a0d..2c15ec2 100644 +--- a/Makefile.local ++++ b/Makefile.local +@@ -279,6 +279,7 @@ notmuch_client_srcs = \ + gmime-filter-headers.c \ + hooks.c \ + notmuch.c \ ++ notmuch-compose.c \ + notmuch-config.c \ + notmuch-count.c \ + notmuch-dump.c \ +diff --git a/notmuch-client.h b/notmuch-client.h +index 19b7f01..1146cd1 100644 +--- a/notmuch-client.h ++++ b/notmuch-client.h +@@ -126,6 +126,9 @@ int + notmuch_reply_command (void *ctx, int argc, char *argv[]); + + int ++notmuch_compose_command (void *ctx, int argc, char *argv[]); ++ ++int + notmuch_restore_command (void *ctx, int argc, char *argv[]); + + int +diff --git a/notmuch-compose.c b/notmuch-compose.c +new file mode 100644 +index 0000000..ac5ea95 +--- /dev/null ++++ b/notmuch-compose.c +@@ -0,0 +1,111 @@ ++/* notmuch - Not much of an email program, (just index and search) ++ * ++ * Copyright © 2009 Carl Worth ++ * Copyright © 2009 Keith Packard ++ * ++ * This program is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * 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/ . ++ * ++ * Authors: Carl Worth ++ * Keith Packard ++ * Felipe Contreras ++ */ ++ ++#include "notmuch-client.h" ++#include "gmime-filter-headers.h" ++ ++static void ++show_message_headers (GMimeMessage *message) ++{ ++ GMimeStream *stream_stdout = NULL, *stream_filter = NULL; ++ ++ stream_stdout = g_mime_stream_file_new (stdout); ++ if (stream_stdout) { ++ g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE); ++ stream_filter = g_mime_stream_filter_new(stream_stdout); ++ if (stream_filter) { ++ g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream_filter), ++ g_mime_filter_headers_new()); ++ g_mime_object_write_to_stream(GMIME_OBJECT(message), stream_filter); ++ g_object_unref(stream_filter); ++ } ++ g_object_unref(stream_stdout); ++ } ++} ++ ++static int ++notmuch_compose (void *ctx, notmuch_config_t *config) ++{ ++ GMimeMessage *msg; ++ const char *from_addr = NULL; ++ const char *message_id, *user_agent; ++ char *simple_from; ++ ++ /* The 1 means we want headers in a "pretty" order. */ ++ msg = g_mime_message_new (1); ++ if (msg == NULL) { ++ fprintf (stderr, "Out of memory\n"); ++ return 1; ++ } ++ ++ g_mime_message_set_subject (msg, ""); ++ ++ g_mime_object_set_header (GMIME_OBJECT (msg), "To", ""); ++ ++ if (from_addr == NULL) ++ from_addr = notmuch_config_get_user_primary_email (config); ++ ++ simple_from = talloc_strdup (ctx, from_addr); ++ ++ from_addr = talloc_asprintf (ctx, "%s <%s>", ++ notmuch_config_get_user_name (config), ++ from_addr); ++ g_mime_object_set_header (GMIME_OBJECT (msg), ++ "From", from_addr); ++ ++ g_mime_object_set_header (GMIME_OBJECT (msg), "Bcc", ++ notmuch_config_get_user_primary_email (config)); ++ ++ user_agent = talloc_asprintf (ctx, "notmuch %s", ++ STRINGIFY(NOTMUCH_VERSION)); ++ g_mime_object_set_header (GMIME_OBJECT (msg), ++ "User-Agent", user_agent); ++ ++ message_id = talloc_asprintf (ctx, "<%lu-notmuch-%s>", ++ time(NULL), ++ simple_from); ++ g_mime_object_set_header (GMIME_OBJECT (msg), ++ "Message-ID", message_id); ++ talloc_free (simple_from); ++ ++ show_message_headers (msg); ++ ++ g_object_unref (G_OBJECT (msg)); ++ ++ return 0; ++} ++ ++int ++notmuch_compose_command (void *ctx, unused (int argc), unused (char *argv[])) ++{ ++ notmuch_config_t *config; ++ int ret = 0; ++ ++ config = notmuch_config_open (ctx, NULL, NULL); ++ if (config == NULL) ++ return 1; ++ ++ ret = notmuch_compose (ctx, config); ++ ++ return ret; ++} +diff --git a/notmuch.c b/notmuch.c +index 477a09c..2b500d7 100644 +--- a/notmuch.c ++++ b/notmuch.c +@@ -65,6 +65,11 @@ static command_t commands[] = { + { "reply", notmuch_reply_command, + "[options...] [...]", + "Construct a reply template for a set of messages." }, ++ { "compose", notmuch_compose_command, ++ NULL, ++ "Constructs an empty message.", ++ "\tConstructs a new empty message filling basic headers such as\n" ++ "\tFrom:, User-Agent: and Message-ID:." }, + { "tag", notmuch_tag_command, + "+|- [...] [--] [...]" , + "Add/remove tags for all messages matching the search terms." }, +-- +1.7.10 + -- 2.26.2