unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/3] composing patches
@ 2010-12-09 22:32 Felipe Contreras
  2010-12-09 22:32 ` [PATCH 1/3] reply: add message-id header Felipe Contreras
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Felipe Contreras @ 2010-12-09 22:32 UTC (permalink / raw)
  To: notmuch

Hi,

I don't know how it works in gnus, but at least on the vim mode, the output
generated by 'notmuch reply' is not ready to be sent, at least the Message-ID
field is needed, and also is nice to have the User-Agent.

Besides, in order to avoid creating a new message by hand (possibly fetching
the info from notmuch config), it's more straightforward to have 'notmuch
compose' command.

In the future 'notmuch compose' might be used to replace 'notmuch reply' and
possily add a forward option too. It might also be possible to add mail aliases
when composing a message, and these aliases might be used while generating the
'notmuch search' output.

Felipe Contreras (3):
  reply: add message-id header
  reply: add user-agent field
  Add 'compose' command

 Makefile.local    |    1 +
 notmuch-client.h  |    3 +
 notmuch-compose.c |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 notmuch-reply.c   |   16 ++++++++
 notmuch.c         |    5 ++
 5 files changed, 136 insertions(+), 0 deletions(-)
 create mode 100644 notmuch-compose.c

-- 
1.7.3.2

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/3] reply: add message-id header
  2010-12-09 22:32 [PATCH 0/3] composing patches Felipe Contreras
@ 2010-12-09 22:32 ` Felipe Contreras
  2010-12-09 22:32 ` [PATCH 2/3] reply: add user-agent field Felipe Contreras
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Felipe Contreras @ 2010-12-09 22:32 UTC (permalink / raw)
  To: notmuch

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 notmuch-reply.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 23d04b8..53a12c5 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -447,6 +447,8 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
     notmuch_message_t *message;
     const char *subject, *from_addr = NULL;
     const char *in_reply_to, *orig_references, *references;
+    const char *message_id;
+    char *simple_from;
 
     for (messages = notmuch_query_search_messages (query);
 	 notmuch_messages_valid (messages);
@@ -476,6 +478,8 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
 	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);
@@ -496,6 +500,13 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
 	g_mime_object_set_header (GMIME_OBJECT (reply),
 				  "References", references);
 
+	message_id = talloc_asprintf (ctx, "<%lu-notmuch-%s>",
+				      time(NULL),
+				      simple_from);
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+				  "Message-ID", message_id);
+	talloc_free (simple_from);
+
 	show_reply_headers (reply);
 
 	g_object_unref (G_OBJECT (reply));
-- 
1.7.3.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/3] reply: add user-agent field
  2010-12-09 22:32 [PATCH 0/3] composing patches Felipe Contreras
  2010-12-09 22:32 ` [PATCH 1/3] reply: add message-id header Felipe Contreras
@ 2010-12-09 22:32 ` Felipe Contreras
  2010-12-09 22:32 ` =?no?q?=5BPATCH=203/3=5D=20Add=20=27compose=27=20command?= Felipe Contreras
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Felipe Contreras @ 2010-12-09 22:32 UTC (permalink / raw)
  To: notmuch

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 notmuch-reply.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 53a12c5..fc5dac4 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -447,7 +447,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
     notmuch_message_t *message;
     const char *subject, *from_addr = NULL;
     const char *in_reply_to, *orig_references, *references;
-    const char *message_id;
+    const char *message_id, *user_agent;
     char *simple_from;
 
     for (messages = notmuch_query_search_messages (query);
@@ -500,6 +500,11 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
 	g_mime_object_set_header (GMIME_OBJECT (reply),
 				  "References", references);
 
+	user_agent = talloc_asprintf (ctx, "notmuch %s",
+				      STRINGIFY(NOTMUCH_VERSION));
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+				  "User-Agent", user_agent);
+
 	message_id = talloc_asprintf (ctx, "<%lu-notmuch-%s>",
 				      time(NULL),
 				      simple_from);
-- 
1.7.3.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* =?no?q?=5BPATCH=203/3=5D=20Add=20=27compose=27=20command?=
  2010-12-09 22:32 [PATCH 0/3] composing patches Felipe Contreras
  2010-12-09 22:32 ` [PATCH 1/3] reply: add message-id header Felipe Contreras
  2010-12-09 22:32 ` [PATCH 2/3] reply: add user-agent field Felipe Contreras
@ 2010-12-09 22:32 ` Felipe Contreras
  2010-12-09 23:20 ` [PATCH 0/3] composing patches Sebastian Spaeth
  2010-12-10 23:53 ` Michal Sojka
  4 siblings, 0 replies; 10+ messages in thread
From: Felipe Contreras @ 2010-12-09 22:32 UTC (permalink / raw)
  To: notmuch; +Cc: Felipe Contreras

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=no, Size: 5141 bytes --]

Signed-off-by: Felipe Contreras <felipe.contreras@ngmail.com>
---
 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 <cworth@cworth.org>
+ *	    Keith Packard <keithp@keithp.com>
+ *	    Felipe Contreras <felipe.contreras@gmail.com>
+ */
+
+#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,
       "+<tag>|-<tag> [...] [--] <search-terms> [...]",
       "Add/remove tags for all messages matching the search terms.",
-- 
1.7.3.2

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] composing patches
  2010-12-09 22:32 [PATCH 0/3] composing patches Felipe Contreras
                   ` (2 preceding siblings ...)
  2010-12-09 22:32 ` =?no?q?=5BPATCH=203/3=5D=20Add=20=27compose=27=20command?= Felipe Contreras
@ 2010-12-09 23:20 ` Sebastian Spaeth
  2010-12-10 15:35   ` Felipe Contreras
  2010-12-10 23:53 ` Michal Sojka
  4 siblings, 1 reply; 10+ messages in thread
From: Sebastian Spaeth @ 2010-12-09 23:20 UTC (permalink / raw)
  To: Felipe Contreras, notmuch

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]

On Fri, 10 Dec 2010 00:32:49 +0200, Felipe Contreras <felipe.contreras@gmail.com> wrote:
> I don't know how it works in gnus, but at least on the vim mode, the output
> generated by 'notmuch reply' is not ready to be sent, at least the Message-ID
> field is needed, and also is nice to have the User-Agent.

But notmuch is not the User-Agent. That's why the emacs UI fills in the
User-Agent value itself. I am not sure on the policy of creating
Message-IDs, perhaps notmuch-reply could actually fill in some defaults there.

Sebastian

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] composing patches
  2010-12-09 23:20 ` [PATCH 0/3] composing patches Sebastian Spaeth
@ 2010-12-10 15:35   ` Felipe Contreras
  2010-12-10 16:04     ` Jameson Rollins
  2010-12-10 16:38     ` Sebastian Spaeth
  0 siblings, 2 replies; 10+ messages in thread
From: Felipe Contreras @ 2010-12-10 15:35 UTC (permalink / raw)
  To: Sebastian Spaeth; +Cc: notmuch

On Fri, Dec 10, 2010 at 1:20 AM, Sebastian Spaeth <Sebastian@sspaeth.de> wrote:
> On Fri, 10 Dec 2010 00:32:49 +0200, Felipe Contreras <felipe.contreras@gmail.com> wrote:
>> I don't know how it works in gnus, but at least on the vim mode, the output
>> generated by 'notmuch reply' is not ready to be sent, at least the Message-ID
>> field is needed, and also is nice to have the User-Agent.
>
> But notmuch is not the User-Agent. That's why the emacs UI fills in the
> User-Agent value itself. I am not sure on the policy of creating
> Message-IDs, perhaps notmuch-reply could actually fill in some defaults there.

Why it's not? The emacs UI is not really doing anything on top of
'notmuch reply'. And if it is, it can very well override that value.
Besides, what about other users (vim)? Why not make the output of
'notmuch reply' ready to be dumped to sendmail?

It seems right now there's a lot of reliance on emacs UI, and gnus.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] composing patches
  2010-12-10 15:35   ` Felipe Contreras
@ 2010-12-10 16:04     ` Jameson Rollins
  2010-12-10 16:38     ` Sebastian Spaeth
  1 sibling, 0 replies; 10+ messages in thread
From: Jameson Rollins @ 2010-12-10 16:04 UTC (permalink / raw)
  To: Felipe Contreras, Sebastian Spaeth; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 877 bytes --]

On Fri, 10 Dec 2010 17:35:17 +0200, Felipe Contreras <felipe.contreras@gmail.com> wrote:
> Why it's not? The emacs UI is not really doing anything on top of
> 'notmuch reply'. And if it is, it can very well override that value.
> Besides, what about other users (vim)? Why not make the output of
> 'notmuch reply' ready to be dumped to sendmail?

I think this is a reasonable point.  But is there a reason that vim
can't fill in the Message-ID and User-Agent fields?  Presumably it does
when composing new messages, right?

That said, if the pre-filling in those fields will help other user
agents, then I don't see the binary shouldn't do that.  Like you said,
other user agents (like emacs) can change them if they see fit.

> It seems right now there's a lot of reliance on emacs UI, and gnus.

I don't think there's any reliance on gnus.  I certainly don't use it.

jamie.

[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] composing patches
  2010-12-10 15:35   ` Felipe Contreras
  2010-12-10 16:04     ` Jameson Rollins
@ 2010-12-10 16:38     ` Sebastian Spaeth
  1 sibling, 0 replies; 10+ messages in thread
From: Sebastian Spaeth @ 2010-12-10 16:38 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1532 bytes --]

On Fri, 10 Dec 2010 17:35:17 +0200, Felipe Contreras wrote:
> On Fri, Dec 10, 2010 at 1:20 AM, Sebastian Spaeth <Sebastian@sspaeth.de> wrote:
> > But notmuch is not the User-Agent. That's why the emacs UI fills in the
> > User-Agent value itself. I am not sure on the policy of creating
> > Message-IDs, perhaps notmuch-reply could actually fill in some defaults there.
> 
> Why it's not? The emacs UI is not really doing anything on top of
> 'notmuch reply'.

Well, it is taking care of the editing that I do, the formatting, the
attaching of files, and it also decides how the file is being sent
out. Isn't that what an UA does? That having said, I don't mind to
prefill a value that the emacs UI can override. I was just pointing out
that what I send out in a few seconds is not a product of notmuch
(mostly).

> And if it is, it can very well override that value.
> Besides, what about other users (vim)? Why not make the output of
> 'notmuch reply' ready to be dumped to sendmail?

When would it make sense to have notmuch reply be dumped to sendmail? Do
you often send quoted replies back to the original sender? :-)
 
> It seems right now there's a lot of reliance on emacs UI, and gnus.

Besides that I happen to use message mode for editing my mails, I don't
use gnus at all. If adding a message-uid and a User-Agent header counts
as *a lot*, then yes, it's a lot :).

But all that is not worth spending more electrons on, prefill the values
and lets override them where needed.

Sebastian

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] composing patches
  2010-12-09 22:32 [PATCH 0/3] composing patches Felipe Contreras
                   ` (3 preceding siblings ...)
  2010-12-09 23:20 ` [PATCH 0/3] composing patches Sebastian Spaeth
@ 2010-12-10 23:53 ` Michal Sojka
  2011-05-04 20:30   ` Felipe Contreras
  4 siblings, 1 reply; 10+ messages in thread
From: Michal Sojka @ 2010-12-10 23:53 UTC (permalink / raw)
  To: Felipe Contreras, notmuch

On Thu, 09 Dec 2010, Felipe Contreras wrote:
> Hi,
> 
> I don't know how it works in gnus, but at least on the vim mode, the output
> generated by 'notmuch reply' is not ready to be sent, at least the Message-ID
> field is needed, and also is nice to have the User-Agent.

I'm not sure whether filling the message-id in notmuch is a useful
thing. With Emacs UI I often send messages which differ only in small
pieces to several people. I prepare a first version of the message and
send it, then I edit the sent message and send it once again etc. All of
these messages should have a different message-id and date headers.

If you want to allow the UI to send a single message multiple times (and
I find it useful) then you need generate the message-id at the time of
sending and as such it has no sense to generate the headers in notmuch.

I have nothing against filling User-Agent header as its value does not
change frequently.

-Michal

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/3] composing patches
  2010-12-10 23:53 ` Michal Sojka
@ 2011-05-04 20:30   ` Felipe Contreras
  0 siblings, 0 replies; 10+ messages in thread
From: Felipe Contreras @ 2011-05-04 20:30 UTC (permalink / raw)
  To: Michal Sojka; +Cc: notmuch

Sorry for the long delay.

On Sat, Dec 11, 2010 at 1:53 AM, Michal Sojka <sojkam1@fel.cvut.cz> wrote:
> On Thu, 09 Dec 2010, Felipe Contreras wrote:
>> I don't know how it works in gnus, but at least on the vim mode, the output
>> generated by 'notmuch reply' is not ready to be sent, at least the Message-ID
>> field is needed, and also is nice to have the User-Agent.
>
> I'm not sure whether filling the message-id in notmuch is a useful
> thing. With Emacs UI I often send messages which differ only in small
> pieces to several people. I prepare a first version of the message and
> send it, then I edit the sent message and send it once again etc. All of
> these messages should have a different message-id and date headers.
>
> If you want to allow the UI to send a single message multiple times (and
> I find it useful) then you need generate the message-id at the time of
> sending and as such it has no sense to generate the headers in notmuch.

Well, if you have a client that is capable of generating such a
Message-Id, this patch would prevent it from doing so. This is mostly
intended for dummy clients, like none at all (sendmail).

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-05-04 20:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-09 22:32 [PATCH 0/3] composing patches Felipe Contreras
2010-12-09 22:32 ` [PATCH 1/3] reply: add message-id header Felipe Contreras
2010-12-09 22:32 ` [PATCH 2/3] reply: add user-agent field Felipe Contreras
2010-12-09 22:32 ` =?no?q?=5BPATCH=203/3=5D=20Add=20=27compose=27=20command?= Felipe Contreras
2010-12-09 23:20 ` [PATCH 0/3] composing patches Sebastian Spaeth
2010-12-10 15:35   ` Felipe Contreras
2010-12-10 16:04     ` Jameson Rollins
2010-12-10 16:38     ` Sebastian Spaeth
2010-12-10 23:53 ` Michal Sojka
2011-05-04 20:30   ` Felipe Contreras

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).