[PATCH 0/3] composing patches

2010-12-10 Thread Sebastian Spaeth
On Fri, 10 Dec 2010 17:35:17 +0200, Felipe Contreras wrote:
> On Fri, Dec 10, 2010 at 1:20 AM, Sebastian Spaeth  
> 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
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20101210/d19219df/attachment.pgp>


[PATCH 0/3] composing patches

2010-12-10 Thread Felipe Contreras
On Fri, Dec 10, 2010 at 1:20 AM, Sebastian Spaeth  
wrote:
> On Fri, 10 Dec 2010 00:32:49 +0200, 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


[PATCH 0/3] composing patches

2010-12-10 Thread Jameson Rollins
On Fri, 10 Dec 2010 17:35:17 +0200, Felipe Contreras  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.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20101210/5d3b7c41/attachment.pgp>


[PATCH 3/3] Add 'compose' command

2010-12-10 Thread Felipe Contreras
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 000..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 

[PATCH 2/3] reply: add user-agent field

2010-12-10 Thread Felipe Contreras
Signed-off-by: Felipe Contreras 
---
 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



[PATCH 1/3] reply: add message-id header

2010-12-10 Thread Felipe Contreras
Signed-off-by: Felipe Contreras 
---
 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



[PATCH 0/3] composing patches

2010-12-10 Thread Felipe Contreras
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



[PATCH 3/3] vim: implement archive in show view

2010-12-10 Thread Felipe Contreras
From: Felipe Contreras 

Signed-off-by: Felipe Contreras 
---
 vim/plugin/notmuch.vim |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/vim/plugin/notmuch.vim b/vim/plugin/notmuch.vim
index 8815712..882c141 100644
--- a/vim/plugin/notmuch.vim
+++ b/vim/plugin/notmuch.vim
@@ -494,7 +494,8 @@ function! s:NM_show_next_thread()
 endfunction

 function! s:NM_show_archive_thread()
-echo 'not implemented'
+call NM_tag(b:nm_search_words, ['-inbox'])
+call NM_show_next_thread()
 endfunction

 function! s:NM_show_mark_read_then_archive_thread()
-- 
1.7.3.2



[PATCH 0/3] composing patches

2010-12-10 Thread Sebastian Spaeth
On Fri, 10 Dec 2010 00:32:49 +0200, 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.

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
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20101210/92eeeb17/attachment-0001.pgp>


[PATCH 2/3] vim: fix get_user_email()

2010-12-10 Thread Felipe Contreras
From: Felipe Contreras 

Signed-off-by: Felipe Contreras 
---
 vim/plugin/notmuch.vim |8 +++-
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/vim/plugin/notmuch.vim b/vim/plugin/notmuch.vim
index 6898d56..8815712 100644
--- a/vim/plugin/notmuch.vim
+++ b/vim/plugin/notmuch.vim
@@ -1027,11 +1027,9 @@ endfunction
 " --- --- compose screen helper functions {{{2

 function! s:NM_compose_get_user_email()
-let name = substitute(system('id -u -n'), '\v(^\s*|\s*$|\n)', '', 'g')
-let fqdn = substitute(system('hostname -f'), '\v(^\s*|\s*$|\n)', '', 
'g')
-
-" TODO: do this properly
-return name . '@' . fqdn
+let rname = system("getent passwd $USER | cut -d ':' -f 5")
+let rname = substitute(rname, '\n*$', '', '')
+return printf("%s <%s>", rname, $EMAIL)
 endfunction

 function! s:NM_compose_find_line_match(start, pattern, failure)
-- 
1.7.3.2



[PATCH 1/3] vim: refactor tagging stuff

2010-12-10 Thread Felipe Contreras
From: Felipe Contreras 

Signed-off-by: Felipe Contreras 
---
 vim/plugin/notmuch.vim |   18 ++
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/vim/plugin/notmuch.vim b/vim/plugin/notmuch.vim
index 8d5d1c3..6898d56 100644
--- a/vim/plugin/notmuch.vim
+++ b/vim/plugin/notmuch.vim
@@ -307,12 +307,12 @@ function! s:NM_search_edit()
 endfunction

 function! s:NM_search_archive_thread()
-call NM_add_remove_tags([], '-', ['inbox'])
+call NM_tag([], ['-inbox'])
 norm j
 endfunction

 function! s:NM_search_mark_read_then_archive_thread()
-call NM_add_remove_tags([], '-', ['unread', 'inbox'])
+call NM_tag([], ['-unread', '-inbox'])
 norm j
 endfunction

@@ -403,7 +403,8 @@ function! s:NM_search_add_remove_tags(prompt, prefix, 
intags)
 else
 let tags = a:intags
 endif
-call NM_add_remove_tags([], a:prefix, tags)
+call map(tags, 'a:prefix . v:val')
+call NM_tag([], tags)
 endfunction

 " --- implement show screen {{{1
@@ -497,7 +498,7 @@ function! s:NM_show_archive_thread()
 endfunction

 function! s:NM_show_mark_read_then_archive_thread()
-call NM_add_remove_tags(b:nm_search_words, '-', ['unread', 
'inbox'])
+call NM_tag(b:nm_search_words, ['-unread', '-inbox'])
 call NM_show_next_thread()
 endfunction

@@ -561,7 +562,8 @@ function! s:NM_show_advance_marking_read_and_archiving()
 let filter = NM_combine_tags('tag:', advance_tags, 'OR', 
'()')
  \ + ['AND']
  \ + NM_combine_tags('', ids, 'OR', '()')
-call NM_add_remove_tags(filter, '-', advance_tags)
+call map(advance_tags, '"+" . v:val')
+call NM_tag(filter, advance_tags)
 call NM_show_next(1, 1)
 return
 endif
@@ -580,7 +582,8 @@ function! s:NM_show_advance_marking_read_and_archiving()
 " do this last to hide the latency
 let filter = NM_combine_tags('tag:', 
advance_tags, 'OR', '()')
  \ + ['AND', msg_top['id']]
-call NM_add_remove_tags(filter, '-', advance_tags)
+call map(advance_tags, '"-" . v:val')
+call NM_tag(filter, advance_tags)
 endif
 return
 endif
@@ -1266,12 +1269,11 @@ function! s:NM_search_expand(arg)
 let b:nm_prev_bufnr = prev_bufnr
 endfunction

-function! s:NM_add_remove_tags(filter, prefix, tags)
+function! s:NM_tag(filter, tags)
 let filter = len(a:filter) ? a:filter : [NM_search_thread_id()]
 if !len(filter)
 throw 'Eeek! I couldn''t find the thead id!'
 endif
-call map(a:tags, 'a:prefix . v:val')
 let args = ['tag']
 call extend(args, a:tags)
 call add(args, '--')
-- 
1.7.3.2



[PATCH 0/3] vim fixes

2010-12-10 Thread Felipe Contreras
Hi,

These are a few patches to improve the vim support.

If nobody comments on these I'll push them.

Felipe Contreras (3):
  vim: refactor tagging stuff
  vim: fix get_user_email()
  vim: implement archive in show view

 vim/plugin/notmuch.vim |   29 +++--
 1 files changed, 15 insertions(+), 14 deletions(-)

-- 
1.7.3.2



Re: [PATCH 0/3] composing patches

2010-12-10 Thread Felipe Contreras
On Fri, Dec 10, 2010 at 1:20 AM, Sebastian Spaeth sebast...@sspaeth.de wrote:
 On Fri, 10 Dec 2010 00:32:49 +0200, Felipe Contreras 
 felipe.contre...@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
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 0/3] composing patches

2010-12-10 Thread Sebastian Spaeth
On Fri, 10 Dec 2010 17:35:17 +0200, Felipe Contreras wrote:
 On Fri, Dec 10, 2010 at 1:20 AM, Sebastian Spaeth sebast...@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


pgpnaArA6MBVy.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 0/3] composing patches

2010-12-10 Thread Michal Sojka
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
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch