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 3B59541A550 for ; Thu, 9 Dec 2010 14:33:04 -0800 (PST) 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 U3FbQt+HL1YD for ; Thu, 9 Dec 2010 14:33:02 -0800 (PST) Received: from mail-bw0-f52.google.com (mail-bw0-f52.google.com [209.85.214.52]) by olra.theworths.org (Postfix) with ESMTP id 05A6D41A555 for ; Thu, 9 Dec 2010 14:33:00 -0800 (PST) Received: by mail-bw0-f52.google.com with SMTP id 4so3710179bwz.39 for ; Thu, 09 Dec 2010 14:33:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references:mime-version :content-type:content-transfer-encoding; bh=ge7lQN6JFf8BNMpepNRqiI7WdaQee7MRdQuDiws4ClM=; b=ta06tAb6uXoQlaj4QE8xX0iE0zUULY0FPCeHz3THSUmAWFMYBS4z4FOILq2ptK3C3w L7IdnkVWCdOEkdQQlX9CShefoYan+eEmX1+OQf6s2m7pY/T9pR5mgEkVD4q83DUpJvK4 2iDwQXaATp6GqTvVQkZb0/Y4UDWsiehOlcL4s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; b=Wd8OrVBTJwUZYCOTCuDQGtX+GI6hBO6HgW6rnBCB12yhHAVedF3by3T5iaMSzHdFox kOO9yTorn6eQYL+XSJGo2w1qgSola5hohaBvxQ9no2lpDPd2bYFyb9oO8focaX0CPQ2v WkTeEdHUABHNLJaWzhcH94vkdtm+YetQ0d/dk= Received: by 10.204.118.4 with SMTP id t4mr18924bkq.38.1291933980649; Thu, 09 Dec 2010 14:33:00 -0800 (PST) Received: from localhost (a91-153-253-80.elisa-laajakaista.fi [91.153.253.80]) by mx.google.com with ESMTPS id q18sm1219652bka.15.2010.12.09.14.32.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 09 Dec 2010 14:33:00 -0800 (PST) From: Felipe Contreras To: notmuch@notmuchmail.org Subject: =?no?q?=5BPATCH=203/3=5D=20Add=20=27compose=27=20command?= Date: Fri, 10 Dec 2010 00:32:52 +0200 Message-Id: <1291933972-7186-4-git-send-email-felipe.contreras@gmail.com> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1291933972-7186-1-git-send-email-felipe.contreras@gmail.com> References: <1291933972-7186-1-git-send-email-felipe.contreras@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=no 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: Thu, 09 Dec 2010 22:33:04 -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(+), 0 deletions(-) create mode 100644 notmuch-compose.c diff --git a/Makefile.local b/Makefile.local index f9b5a9b..cdf5e49 100644 --- a/Makefile.local +++ b/Makefile.local @@ -235,6 +235,7 @@ notmuch_client_srcs = \ gmime-filter-reply.c \ gmime-filter-headers.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 005385d..1a48a8b 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -93,6 +93,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 9ba0ec0..d652f44 100644 --- a/notmuch.c +++ b/notmuch.c @@ -306,6 +306,11 @@ command_t commands[] = { "\n" "\tSee \"notmuch help search-terms\" for details of the search\n" "\tterms syntax." }, + { "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.3.2