[RFC] reordering and cleanup of thread authors

2010-04-06 Thread Dirk Hohndel

This is based in part on some discussion on IRC today.
When a thread is displayed in the search results, previously the authors
were always displayed in chronological order. But if only part of the
thread matches the query, that may or may not be the intuitive thing to
do.
Imagine the default "+inbox" query. Those mails in the thread that
match the query are actually "new" (whatever that means). And some
people seem to think that it would be much better to see those author
names first. For example, imagine a long and drawn out thread that once
was started by me; you have long read the older part of the thread and
removed the inbox tag. Whenever a new email comes in on this thread, the
author column in the search display will first show "Dirk Hohndel" - I
think it should first show the actual author(s) of the new mail(s).

The second cleanup that I've done in this context is to convert all
author names into the much easier to parse "Firstname Lastname"
format. Some broken mail systems (cough - Exchange - Cough) seem to
prefer "Lastname, Firstname" - which makes the comma separated list of
authors really hard to parse at one glance. Worse, it creates douplicate
entries if a person happens to show in both orders. So this does a
rather simplistic "look for a comma, if it's there, reorder" approach to
cleaning up the author name.

I don't think this is ready to be pulled. There was a strong request on
IRC to make the re-ordering of the author names configurable. I think
the cleanup of the names (First Last) should be configurable as well.
And of course I wonder about my implementation, given that I'm still
trying to wrap my mind around the current code base.

Thanks

/D

diff --git a/lib/message.cc b/lib/message.cc
index 721c9a6..ac0afd9 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -35,6 +35,7 @@ struct _notmuch_message {
 char *thread_id;
 char *in_reply_to;
 char *filename;
+char *author;
 notmuch_message_file_t *message_file;
 notmuch_message_list_t *replies;
 unsigned long flags;
@@ -110,6 +111,7 @@ _notmuch_message_create (const void *talloc_owner,
 message->in_reply_to = NULL;
 message->filename = NULL;
 message->message_file = NULL;
+message->author = NULL;

 message->replies = _notmuch_message_list_create (message);
 if (unlikely (message->replies == NULL)) {
@@ -533,6 +535,20 @@ notmuch_message_get_tags (notmuch_message_t *message)
 return _notmuch_convert_tags(message, i, end);
 }

+const char *
+notmuch_message_get_author (notmuch_message_t *message)
+{
+return message->author;
+}
+
+void
+notmuch_message_set_author (notmuch_message_t *message,
+   const char *author)
+{
+message->author = talloc_strdup(message, author);
+return;
+}
+
 void
 _notmuch_message_set_date (notmuch_message_t *message,
   const char *date)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 88da078..79638bb 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -771,6 +771,17 @@ notmuch_message_set_flag (notmuch_message_t *message,
 time_t
 notmuch_message_get_date  (notmuch_message_t *message);

+/* Set the author member of 'message' - this is the representation used
+ * when displaying the message
+ */
+void
+notmuch_message_set_author (notmuch_message_t *message, const char *author);
+
+/* Get the author member of 'message'
+ */
+const char *
+notmuch_message_get_author (notmuch_message_t *message);
+
 /* Get the value of the specified header from 'message'.
  *
  * The value will be read from the actual message file, not from the
diff --git a/lib/thread.cc b/lib/thread.cc
index 48c070e..c3c83a3 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -32,6 +32,7 @@ struct _notmuch_thread {
 char *subject;
 GHashTable *authors_hash;
 char *authors;
+char *nonmatched_authors;
 GHashTable *tags;

 notmuch_message_list_t *message_list;
@@ -69,8 +70,95 @@ _thread_add_author (notmuch_thread_t *thread,
thread->authors = talloc_asprintf (thread, "%s, %s",
   thread->authors,
   author);
-else
+else {
thread->authors = talloc_strdup (thread, author);
+}
+}
+
+/*
+ * move authors of matched messages in the thread to 
+ * the front of the authors list, but keep them in
+ * oldest first order within their group
+ */
+static void
+_thread_move_matched_author (notmuch_thread_t *thread,
+const char *author)
+{
+char *authorscopy;
+char *currentauthor;
+int idx,nmstart,author_len,authors_len;
+
+if (thread->authors == NULL)
+   return;
+if (thread->nonmatched_authors == NULL)
+   thread->nonmatched_authors = thread->authors;
+author_len = strlen(author);
+authors_len = strlen(thread->authors);
+if (author_len == authors_len) {
+   /* just one author */
+   thread->nonmatched_authors += author_len;
+   return;
+}
+   

[PATCH] test-lib.sh: Add explicit license detail, with change from GPLv2 to GPLv2+.

2010-04-06 Thread Michal Sojka
On Sat, 20 Feb 2010, Carl Worth wrote:
> This file has had no explicit license information noted in it, but
> has clearly been created and modified according to the terms of GPLv2
> as with the rest of the git code base.
> 
> The purpose of relicensing is to allow other GPLv3+ projects (in
> particular, the notmuch project: http://notmuchmail.org) to use this
> same test-suite structure (and to contribute changes back as well).

Hi Carl,

here is my report of git's test-lib relicensing. The following is the
last list sent to me by Junio. I guess you have this information
somewhere in your mailbox as well.

Acked-by: Alex Riesen 
Acked-by: Brandon Casey 
Acked-by: David Reiss 
Acked-by: Emil Sit 
Acked-by: Eric Wong 
Acked-by: Jakub Narebski 
Acked-by: Jeff King 
Acked-by: Johannes Schindelin 
Acked-by: Johannes Sixt 
Acked-by: Jonathan Nieder 
Acked-by: Josh Triplett 
Acked-by: Junio C Hamano 
Acked-by: Lea Wiemann 
Acked-by: Markus Heidelberg 
Acked-by: Martin Waitz 
Acked-by: Matthew Ogilvie 
Acked-by: Michele Ballabio 
Acked-by: Miklos Vajna 
Acked-by: Nicolas Pitre 
Acked-by: Pavel Roskin 
Acked-by: Petr Baudis 
Acked-by: Pierre Habouzit 
Acked-by: Robin Rosenberg 
Acked-by: Shawn O. Pearce 
Acked-by: Stephen Boyd 
Acked-by: Sverre Rabbelier 

According to https://git.wiki.kernel.org/index.php/Test-lib_reclicensing
we can add there the following lines:

Acked-by: Clemens Buchacher 
Acked-by: Fredrik Kuivinen 
Acked-by: Gerrit Pape 
Acked-by: Christian Couder 
Acked-by: Johan Herland 
Acked-by: Matthias Lederhofer 
Acked-by: Michael J Gruber 
Acked-by: Thomas Rast 

There are three contributors who didn't respond to me. The contributions
of two of them are clearly not copyrightable (Stephan Beyer and Bert
Wesarg - see the links to commits in the wiki). The last contributor is
Bryan Donlan who fix a few quoting problems which are quite simple but I
do not have any clue whether this is copyrightable or not
(see gitk --author='Bryan Donlan' t/test-lib.sh).

Junio was talking about only three missing Acks so I guess he already
did some filtering based on copyrightability. Do you know which three
Acks were missing according to Junio and whether these are in my list?

Thanks
Michal

> 
> The request for relicensing was presented to the git community in:
> 
>   Message-ID: <871vgmki4f.fsf at steelpick.localdomain>
> 
> and explicitly agreed to by Junio C Hamano, Sverre Rabbelier, Johannes
> Schindelin, Pierre Habouzit, and Johannes Sixt.
> 
>  t/test-lib.sh |   12 
>  1 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index afd3053..004470f 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -2,6 +2,18 @@
>  #
>  # Copyright (c) 2005 Junio C Hamano
>  #
> +# 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 2 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/ .
>  
>  # if --tee was passed, write the output not only to the terminal, but
>  # additionally to the file test-results/$BASENAME.out, too.
> -- 
> 1.6.5.7
> 
Non-text part: application/pgp-signature


[PATCH] fix obvious cut and paste error

2010-04-06 Thread Carl Worth
On Tue, 06 Apr 2010 15:36:25 -0700, Dirk Hohndel  
wrote:
> -if (unlikely (thread_id_query == NULL))
> +if (unlikely (matched_query == NULL))

Good catch. This is pushed now.

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100406/4167da47/attachment.pgp>


[PATCH 2/2] guess From address from Received headers

2010-04-06 Thread Carl Worth
On Tue, 06 Apr 2010 12:45:57 -0700, Dirk Hohndel  
wrote:
>  When replying to a message notmuch tries to pick the correct From
>  address by looking which one of a user's configured email addresses
>  were included in To or Cc headers of the email that is being replied to.
>  If none of the users email addresses are in the To or Cc headers we now
>  try to guess from the first (chronologically, last) Received header
>  which domain this email was received in and therefore which of the
>  email addresses to use in a reply
>  If that fails we still use the primary email as From email

Thanks, Dirk.

This looks like an awfully useful and clever piece of
functionality. I've applied this patch, (with some tiny style
cleanups[*] afterwards), along with the previous patch that this depends
on.

I'd like to have a test case in the test suite for this as well, but I'm
not going to make the patch block on that (instead I just added that to
TODO).

-Carl

[*] I really need to add a CODING_STYLE document to advertise my
preferred style issues. And before you ask, yes, there *is* a patch for
that.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100406/d3fc8675/attachment.pgp>


[PATCH] json: Avoid calling strlen(NULL)

2010-04-06 Thread Anthony Towns
On Tue, Apr 6, 2010 at 17:25, David Edmondson  wrote:
> ? ?json: Avoid calling strlen(NULL)
> ? ?MIME parts may have no filename, which previously resulted in calling
> ? ?strlen(NULL).
> ?char *
> ?json_quote_str(const void *ctx, const char *str)
> ?{
> + ? ?if (str == NULL)
> + ? ? ? return (char *)"\"\"";
> +
> ? ? return (json_quote_chararray (ctx, str, strlen (str)));
> ?}

There's already a check in json_quote_chararray for len==0, so it
might be sensible to say:

return (json_quote_chararray (ctx, str, str != NULL ? strlen (str) : 0));

OTOH, the code in json_quote_array to deal with that does the same
thing (returns a literal string containing two quote marks), which
seems wrong -- the normal code path is to talloc to get a newly
allocated, editable string, that might be talloc_free'd later,
wouldn't it make more sense just to let the str==NULL / len==0
behaviour fall through into the normal case code?

FWIW:

commit 5b93a488221b50c02db18d86a550cb3c038c00da
Author: Anthony 
Date:   Tue Apr 6 18:10:39 2010 +1000

json: Avoid calling strlen(NULL), and always return a newly talloced array.

MIME parts may have a no filename, which causes json_quote_str()
to be invoked
with NULL instead of a string.

diff --git a/json.c b/json.c
index f90b0fa..5e379ef 100644
--- a/json.c
+++ b/json.c
@@ -57,9 +57,6 @@ json_quote_chararray(const void *ctx, const char
*str, const size_t len)
 size_t loop;
 size_t required;

-if (len == 0)
-   return (char *)"\"\"";
-
 for (loop = 0, required = 0, ptr = str;
 loop < len;
 loop++, required++, ptr++) {
@@ -105,5 +102,8 @@ json_quote_chararray(const void *ctx, const char
*str, const size_t len)
 char *
 json_quote_str(const void *ctx, const char *str)
 {
+if (str == NULL)
+str = "";
+
 return (json_quote_chararray (ctx, str, strlen (str)));
 }



-- 
Anthony Towns 


[PATCH] Derive version numbers from git

2010-04-06 Thread Michal Sojka
 On Tue, 06 Apr 2010, Sebastian Spaeth wrote:
 > On 2010-04-06, Michal Sojka wrote:
 > > I often have several versions of notmuch compiled and it would be very
 > > helpful to be able to distinguish between them. Git has a very nice
 > > feature to make intermediate numbering automatic and unambiguous so
 > > let's use it here.
 > 
 > But, there are people without git installed that download the release
 > tarball. So if this patch makes it, we need to replace this with a
 > static version number when baking a release tar.

Right, here is an updated patch. It's more complicated than the previous
one, but it solves the issue.

-Michal


--8<---cut here---start->8---
I often have several versions of notmuch compiled and it would be very
helpful to be able to distinguish between them. Git has a very nice
feature to make intermediate numbering automatic and unambiguous so
let's use it here.

For tagged versions, the version is the name of the tag, for
intermediate versions, the unique ID of the commit is appended to the
tag name.

When notmuch is compiled from a release tarball, there is no git
repository and therefore the tarball has to contain a special file
'version', which contains the correct version number.
---
 .gitignore |1 +
 Makefile.local |   24 +---
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 95c50ec..b72ce72 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 .first-build-message
 Makefile.config
+Makefile.version
 TAGS
 tags
 *cscope*
diff --git a/Makefile.local b/Makefile.local
index 74f0f86..09fffa6 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -7,11 +7,14 @@
 # digit when we reach particularly major milestones of usability.
 #
 # Between releases, (such as when compiling notmuch from the git
-# repository), we add a third digit, (0.1.1, 0.1.2, etc.), and
-# increment it occasionally, (such as after a big batch of commits are
-# merged.
+# repository), we let git to append identification of the actual
+# commit.
 PACKAGE=notmuch
-VERSION=0.1.1
+include Makefile.version
+
+.PHONY: Makefile.version
+Makefile.version:
+   echo VERSION=$(if $(wildcard version),`cat version`,`git describe 
--dirty`) > $@

 RELEASE_HOST=notmuchmail.org
 RELEASE_DIR=/srv/notmuchmail.org/www/releases
@@ -61,8 +64,15 @@ ifeq ($(shell cat .first-build-message),)
 endif
 endif

-$(TAR_FILE):
-   git archive --format=tar --prefix=$(PACKAGE)-$(VERSION)/ HEAD | gzip > 
$(TAR_FILE)
+.PHONY: version # Always regenerate version
+version:
+   git describe > $@
+
+$(TAR_FILE): version
+   git archive --format=tar --prefix=$(PACKAGE)-$(VERSION)/ HEAD > 
$(TAR_FILE).tmp
+   tar --append -f $(TAR_FILE).tmp --transform s_^_$(PACKAGE)-$(VERSION)/_ 
version
+   rm version
+   gzip < $(TAR_FILE).tmp > $(TAR_FILE)
@echo "Source is ready for release in $(TAR_FILE)"

 $(SHA1_FILE): $(TAR_FILE)
@@ -263,4 +273,4 @@ install-zsh:
$(call quiet_install_data, contrib/notmuch-completion.zsh 
$(DESTDIR)$(zsh_completion_dir)/notmuch)

 SRCS  := $(SRCS) $(notmuch_client_srcs)
-CLEAN := $(CLEAN) notmuch notmuch-shared $(notmuch_client_modules) notmuch.elc 
notmuch.1.gz
+CLEAN := $(CLEAN) notmuch notmuch-shared $(notmuch_client_modules) notmuch.elc 
notmuch.1.gz version
-- 
1.7.0.2


[PATCH] fix obvious cut and paste error

2010-04-06 Thread Dirk Hohndel

the wrong variable is checked for success of an allocation

Signed-off-by: Dirk Hohndel 
---
 lib/thread.cc |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/lib/thread.cc b/lib/thread.cc
index 1c8b39d..48c070e 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -236,7 +236,7 @@ _notmuch_thread_create (void *ctx,
return NULL;

 matched_query = notmuch_query_create (notmuch, matched_query_string);
-if (unlikely (thread_id_query == NULL))
+if (unlikely (matched_query == NULL))
return NULL;

 thread = talloc (ctx, notmuch_thread_t);
-- 
1.6.6.1



-- 
Dirk Hohndel
Intel Open Source Technology Center


[PATCH] Derive version numbers from git

2010-04-06 Thread Sebastian Spaeth
On 2010-04-06, Michal Sojka wrote:
> I often have several versions of notmuch compiled and it would be very
> helpful to be able to distinguish between them. Git has a very nice
> feature to make intermediate numbering automatic and unambiguous so
> let's use it here.

But, there are people without git installed that download the release
tarball. So if this patch makes it, we need to replace this with a
static version number when baking a release tar.

Sebastian


[notmuch] Bulk message tagging

2010-04-06 Thread Mark Anderson
On Mon, 5 Apr 2010 01:15:39 -0500, Xavier Maillard  wrote:
> On Sun, 04 Apr 2010 07:38:03 -0400, Jesse Rosenthal  
> wrote:
> > On Sun, 04 Apr 2010 06:37:53 +0200, Xavier Maillard  wrote:
> > > Is there an easy way to mark a whole bunch of message (restricted
> > > in a region, result of a search, ...) ?
> > 
> > In addition to the "*" command that was mentioned, there is a patch I
> > wrote to tag messages in search view by region in emacs. You can find it
> 
> Sounds interesting. * is good when your search criteria is
> perfect but you proposed patch is a good companion for all the
> rest.
> 
> Sadly, git is not really something I know wll enough to play with
> all this stuff :(
> 
> Xavier

Also, you will want to be careful with '*' in emacs.

It runs notmuch tag + ,
but the notmuch-search buffer can be woefully out of date.

I like to go through and add tags, archive, etc, lots of email.  Then I
'q' back to the search buffer, and I may realize that I want to tag
everything I can see.  '*' isn't really that command, it applies a tag
to the results of a search that you are looking at.  But it will use a
fresh version of the search, not the version in the buffer, which could
be minutes, hours, days or weeks old, depending on your Emacs buffer
management habits (or lack of them).

I think that '*' is definitely an awesome command, but I wonder if we
shouldn't have another command for the notmuch-search buffer which means
'tag all the threads that I can see in this buffer'.

If you have a crontab running 'notmuch new', you could end up tagging a
lot of things you would rather have a chance to review first.  I often
use '*' to tag:deleted a large number of mails once I have a query I
like, so deleting things sight unseen is an unpleasant thought.

I know that there is an emacs-region patch, which could probably be
extended to implement the behavior I'm talking about, but I have a hard
enough time adding keys to the keymaps, and alas, the time thing...

Maybe someone else will decide it's important enough to do, or has
already done it.

Enjoy,
-Mark

> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
> 



[PATCH 2/2] guess From address from Received headers

2010-04-06 Thread Dirk Hohndel

 When replying to a message notmuch tries to pick the correct From
 address by looking which one of a user's configured email addresses
 were included in To or Cc headers of the email that is being replied to.
 If none of the users email addresses are in the To or Cc headers we now
 try to guess from the first (chronologically, last) Received header
 which domain this email was received in and therefore which of the
 email addresses to use in a reply
 If that fails we still use the primary email as From email


Signed-off-by: Dirk Hohndel 
---
 notmuch-reply.c |   73 --
 1 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 6c15536..3c5b253 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -282,6 +282,69 @@ add_recipients_from_message (GMimeMessage *reply,
 return from_addr;
 }

+
+static const char *
+guess_from_received_header(notmuch_config_t *config, notmuch_message_t 
*message)
+{
+const char *received,*primary;
+char **other;
+char *by,*mta,*ptr,*token;
+char *domain=NULL;
+char *tld=NULL;
+const char *delim=". \t";
+size_t i,other_len;
+
+received = notmuch_message_get_header (message, "received");
+by = strstr(received," by ");
+if (by && *(by+4)) {
+   /* we know that there are 4 characters after by - either the 4th one
+* is '\0' (broken header) or it is the first letter of the hostname 
+* that last received this email - which we'll use to guess the right
+* from email address
+*/
+   mta = strdup(by+4);
+   if (mta == NULL)
+   return NULL;
+   /* After the MTA comes its IP address (or HELO response) in parenthesis.
+* so let's terminate the string there
+*/
+   if ((ptr = strchr(mta,'(')) == NULL) {
+   free (mta);
+   return NULL;
+   }
+   *ptr = '\0';
+   /* Now extract the last two components of the MTA host name
+* as domain and tld
+*/
+   token = mta;
+   while ((ptr = strsep(,delim)) != NULL) {
+   if (*ptr == '\0')
+   continue;
+   domain = tld;
+   tld = ptr;
+   }
+   if (domain) {
+   /* recombine domain and tld and look for it among the configured
+* email addresses
+*/
+   *(tld-1) = '.';
+   primary = notmuch_config_get_user_primary_email (config);
+   if (strcasestr (primary, domain)) {
+   free(mta);
+   return primary;
+   }
+   other = notmuch_config_get_user_other_email (config, _len);
+   for (i = 0; i < other_len; i++)
+   if (strcasestr (other[i], domain)) {
+   free(mta);
+   return other[i];
+   }
+   }
+   free(mta);
+}
+return NULL;
+}
+
 static int
 notmuch_reply_format_default(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query)
 {
@@ -312,9 +375,13 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t 
*config, notmuch_query_
g_mime_message_set_subject (reply, subject);

from_addr = add_recipients_from_message (reply, config, message);
-
-   if (from_addr == NULL)
-   from_addr = notmuch_config_get_user_primary_email (config);
+   
+   if (from_addr == NULL) {
+   from_addr = guess_from_received_header (config, message);
+   if (from_addr == NULL) {
+   from_addr = notmuch_config_get_user_primary_email (config);
+   }
+   }

from_addr = talloc_asprintf (ctx, "%s <%s>",
 notmuch_config_get_user_name (config),
-- 
1.6.6.1


-- 
Dirk Hohndel
Intel Open Source Technology Center


[PATCH 1/2] fix notmuch_message_file_get_header

2010-04-06 Thread Dirk Hohndel

 fix notmuch_message_file_get_header to always return the first instance
 of the header you are looking for


Signed-off-by: Dirk Hohndel 
---
 lib/message-file.c |   12 +---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/message-file.c b/lib/message-file.c
index 3a1a681..0c152a3 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -318,9 +318,15 @@ notmuch_message_file_get_header (notmuch_message_file_t 
*message,
match = (strcasecmp (header, header_desired) == 0);

decoded_value = g_mime_utils_header_decode_text (message->value.str);
-
-   g_hash_table_insert (message->headers, header, decoded_value);
-
+   if (g_hash_table_lookup (message->headers, header) == NULL) {
+   /* Only insert if we don't have a value for this header, yet.
+* This way we always return the FIRST instance of any header
+* we search for
+* FIXME: we should be returning ALL instances of a header
+*or at least provide a way to iterate over them
+*/
+   g_hash_table_insert (message->headers, header, decoded_value);
+   }
if (match)
return decoded_value;
 }
-- 
1.6.6.1


-- 
Dirk Hohndel
Intel Open Source Technology Center


[notmuch] vala, this is notmuch. notmuch, this is vala

2010-04-06 Thread Sebastian Spaeth
On Mon, 5 Apr 2010 14:50:04 +0100, Enrico Zini  wrote:
> Now I use "lbdb", which gets very slow as time goes. You idea creates a
> most definitely superior system.

You can actually use both :): Do check out the patch on the mailing list
to combine the notmuch address lookup with bbdb via EUDC. It works nice
for me. Although the notmuch address lookup works so well for me that I
basically never get a fallback to bbdb.

If pure email addresses is all you need (no real names yet), the above
code works well when integrated via EUDC.

Sebastian


[PATCH] Derive version numbers from git

2010-04-06 Thread Michal Sojka
On Tue, 06 Apr 2010, Carl Worth wrote:
> In trying to get notmuch to grow up a little bit, I've just added a
> version number (0.1 initially) and have started doing releases. My idea
> for now is to have 2-part versions for releases, and 3-part versions to
> indicate intermediate states within git.

Hi Carl,

first of all, thank you very much for the first release. I think, that
0.1 is good number to start with, but I do not like manual numbering of
intermediate states. Please, consider applying the following patch.

-Michal

- >8  >8 -
I often have several versions of notmuch compiled and it would be very
helpful to be able to distinguish between them. Git has a very nice
feature to make intermediate numbering automatic and unambiguous so
let's use it here.

For tagged versions, the version is the name of the tag, for
intermediate versions, the unique ID of the commit is appended to the
tag name.

diff --git a/Makefile.local b/Makefile.local
index 74f0f86..890f78a 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -7,11 +7,10 @@
 # digit when we reach particularly major milestones of usability.
 #
 # Between releases, (such as when compiling notmuch from the git
-# repository), we add a third digit, (0.1.1, 0.1.2, etc.), and
-# increment it occasionally, (such as after a big batch of commits are
-# merged.
+# repository), we let git to append identification of the actual
+# commit.
 PACKAGE=notmuch
-VERSION=0.1.1
+VERSION:=$(shell git describe --dirty)

 RELEASE_HOST=notmuchmail.org
 RELEASE_DIR=/srv/notmuchmail.org/www/releases


[PATCH] notmuch.el: Make notmuch-show buffer name first subject, instead of thread-id (supersedes V1--3)

2010-04-06 Thread Sebastian Spaeth
From: Jesse Rosenthal 

Change the buffer name to a uniquified subject of the thread (i.e. the
subject of the first message in the thread) instead of the thread-id. This
is more meaningful to the user, and will make it easier to scroll through
numerous open buffers.

Note that this patch adds an optional `buffer-name' argument to notmuch
show.

This version supersedes V1--3 of this patch. It ensures that the buffer
names are unique, and that the `notmuch-show' command can still be used
 interactively (fixing embarassing bugs in V2 and V3 which prevented that)

Signed-off-by: Jesse Rosenthal 
Signed-off-by: Sebastian Spaeth 
---
 emacs/notmuch-show.el |   11 ---
 emacs/notmuch.el  |   14 --
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index cc1f905..ed95afb 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -959,7 +959,7 @@ All currently available key bindings:
  (lambda()
(hl-line-mode 1) ))

-(defun notmuch-show (thread-id  parent-buffer query-context)
+(defun notmuch-show (thread-id  parent-buffer query-context 
buffer-name)
   "Run \"notmuch show\" with the given thread ID and display results.

 The optional PARENT-BUFFER is the notmuch-search buffer from
@@ -967,9 +967,14 @@ which this notmuch-show command was executed, (so that the 
next
 thread from that buffer can be show when done with this one).

 The optional QUERY-CONTEXT is a notmuch search term. Only messages from the 
thread
-matching this search term are shown if non-nil. "
+matching this search term are shown if non-nil.
+
+The optional BUFFER-NAME provides the neame of the buffer in which the message 
thread is shown. If it is nil (which occurs when the command is called 
interactively) the argument to the function is used. "
   (interactive "sNotmuch show: ")
-  (let ((buffer (get-buffer-create (concat "*notmuch-show-" thread-id "*"
+  (when (null buffer-name)
+(setq buffer-name (concat "*notmuch-" thread-id "*")))
+  (let* ((thread-buffer-name (generate-new-buffer-name buffer-name))
+(buffer (get-buffer-create thread-buffer-name)))
 (switch-to-buffer buffer)
 (notmuch-show-mode)
 (set (make-local-variable 'notmuch-show-parent-buffer) parent-buffer)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 5e479d6..ca0b6e0 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -404,9 +404,19 @@ Complete list of currently available key bindings:
 (defun notmuch-search-show-thread ()
   "Display the currently selected thread."
   (interactive)
-  (let ((thread-id (notmuch-search-find-thread-id)))
+  (let ((thread-id (notmuch-search-find-thread-id))
+   (subject (notmuch-search-find-subject))
+   buffer-name)
+(when (string-match "^[ \t]*$" subject)
+  (setq subject "[No Subject]"))
+(setq buffer-name (concat "*"
+ (truncate-string-to-width subject 32 nil nil t)
+ "*"))
 (if (> (length thread-id) 0)
-   (notmuch-show thread-id (current-buffer) notmuch-search-query-string)
+   (notmuch-show thread-id
+ (current-buffer)
+ notmuch-search-query-string
+ buffer-name)
   (error "End of search results"

 (defun notmuch-search-reply-to-thread ()
-- 
1.6.3.3



[notmuch] [PATCH V4] notmuch.el: Make notmuch-show buffer name first subject, instead of thread-id (supersedes V1--3)

2010-04-06 Thread Sebastian Spaeth
On Sat, 06 Mar 2010 09:20:21 -0500, Jesse Rosenthal  
wrote:
> Change the buffer name to a uniquified subject of the thread (i.e. the
> subject of the first message in the thread) instead of the thread-id. This
> is more meaningful to the user, and will make it easier to scroll through
> numerous open buffers.

I have been using this patch since it was posted and find it very
useful. However, it won't apply anymore due to the code shuffling. I'll
reply to this message and send a rebased version that applies to current
cworth/master.

Sebastian


[PATCH 2/2] notmuch.el: Colour cited regions and signatures with message-cited-text-face

2010-04-06 Thread Sebastian Spaeth
From: David Edmondson 

Patch from mail id:1266226909-19360-1-git-send-email-dme at dme.org with a fix 
in id:873a12hl3f.fsf at aw.hh.sledj.net

Signed-off-by: Sebastian Spaeth 
---
 emacs/notmuch-show.el |   18 ++
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index f172f6b..353b57d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -708,14 +708,16 @@ is what to put on the button."
(let* ((sig-start (match-beginning 0))
   (sig-end (match-end 0))
   (sig-lines (1- (count-lines sig-start end
- (if (<= sig-lines notmuch-show-signature-lines-max)
- (notmuch-show-region-to-button
-  sig-start
-  end
-  "signature"
-  indent
-  (format notmuch-show-signature-button-format sig-lines)
-  ))
+(if (<= sig-lines notmuch-show-signature-lines-max)
+  (progn
+(overlay-put (make-overlay sig-start end) 'face 
'message-cited-text-face)
+(notmuch-show-region-to-button
+ sig-start
+ end
+ "signature"
+ indent
+ (format notmuch-show-signature-button-format sig-lines)
+ )))

 (defun notmuch-show-markup-part (beg end depth)
   (if (re-search-forward notmuch-show-part-begin-regexp nil t)
-- 
1.6.3.3



[PATCH 1/2] notmuch.el: Allow citation suffixes to be shown as well as prefixes.

2010-04-06 Thread Sebastian Spaeth
From: David Edmondson 

In many conversations the last few lines of a citation are more
interesting than the first few lines, hence allow those to be shown if
desired.

Modify the face used for the citation button to distinguish it from
the surrounding citation.

Signed-off-by: Sebastian Spaeth 
---
 emacs/notmuch-show.el |   36 +---
 1 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index cc1f905..f172f6b 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -111,10 +111,20 @@ Can use up to one integer format parameter, i.e. %d")
   "Maximum length of signature that will be hidden by default.")

 (defvar notmuch-show-citation-lines-prefix 4
-  "Always show at least this many lines of a citation.
+  "Always show at least this many lines at the start of a citation.

-If there is one more line, show that, otherwise collapse
-remaining lines into a button.")
+If there is one more line than the sum of
+`notmuch-show-citation-lines-prefix' and
+`notmuch-show-citation-lines-suffix', show that, otherwise
+collapse remaining lines into a button.")
+
+(defvar notmuch-show-citation-lines-suffix 0
+  "Always show at least this many lines at the end of a citation.
+
+If there is one more line than the sum of
+`notmuch-show-citation-lines-prefix' and
+`notmuch-show-citation-lines-suffix', show that, otherwise
+collapse remaining lines into a button.")

 (defvar notmuch-show-message-begin-regexp"\fmessage{")
 (defvar notmuch-show-message-end-regexp  "\fmessage}")
@@ -679,16 +689,20 @@ is what to put on the button."
   (let* ((cite-start (match-beginning 0))
 (cite-end  (match-end 0))
 (cite-lines (count-lines cite-start cite-end)))
-   (when (> cite-lines (1+ notmuch-show-citation-lines-prefix))
+   (overlay-put (make-overlay cite-start cite-end) 'face 
'message-cited-text-face)
+   (when (> cite-lines (1+ (+ notmuch-show-citation-lines-prefix 
notmuch-show-citation-lines-suffix)))
  (goto-char cite-start)
  (forward-line notmuch-show-citation-lines-prefix)
- (notmuch-show-region-to-button
-  (point) cite-end
-  "citation"
-  indent
-  (format notmuch-show-citation-button-format
-  (- cite-lines notmuch-show-citation-lines-prefix))
-  
+ (let ((hidden-start (point)))
+   (goto-char cite-end)
+   (forward-line (- notmuch-show-citation-lines-suffix))
+   (notmuch-show-region-to-button
+hidden-start (point)
+"citation"
+indent
+(format notmuch-show-citation-button-format
+(- cite-lines notmuch-show-citation-lines-prefix 
notmuch-show-citation-lines-suffix))
+)
 (if (and (< (point) end)
 (re-search-forward signature-regexp end t))
(let* ((sig-start (match-beginning 0))
-- 
1.6.3.3



[notmuch] [PATCH] notmuch.el: Allow citation suffixes to be shown as well as prefixes.

2010-04-06 Thread Sebastian Spaeth
On Wed, 17 Feb 2010 10:51:51 +, David Edmondson  wrote:
> In many conversations the last few lines of a citation are more
> interesting than the first few lines, hence allow those to be shown if
> desired.
> 
> Modify the face used for the citation button to distinguish it from
> the surrounding citation.

I've been using this patch and don't want to lose it. However, as it
does not apply anymore due to the file moving, I'll reply with 2 updated
patches that produce nicer citations.

Sebastian


[PATCH] json: Avoid calling strlen(NULL)

2010-04-06 Thread David Edmondson
On Tue, 6 Apr 2010 18:17:44 +1000, Anthony Towns  wrote:
> OTOH, the code in json_quote_array to deal with that does the same
> thing (returns a literal string containing two quote marks), which
> seems wrong -- the normal code path is to talloc to get a newly
> allocated, editable string, that might be talloc_free'd later,
> wouldn't it make more sense just to let the str==NULL / len==0
> behaviour fall through into the normal case code?

This is a much nicer solution.

dme.
-- 
David Edmondson, http://dme.org


[PATCH 2/2] notmuch.el: Add support for reply-to sender

2010-04-06 Thread Sebastian Spaeth
From: Aneesh Kumar K.V 

Add key binding to do a reply-to sender. This is mapped to 'R'

Signed-off-by: Aneesh Kumar K.V 
Signed-off-by: Sebastian Spaeth 
---
 emacs/notmuch-show.el |   21 -
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index cc1f905..3d89861 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -63,7 +63,8 @@
 (define-key map "s" 'notmuch-search)
 (define-key map "m" 'message-mail)
 (define-key map "f" 'notmuch-show-forward-current)
-(define-key map "r" 'notmuch-show-reply)
+(define-key map "r" 'notmuch-show-reply-all)
+(define-key map "R" 'notmuch-show-reply)
 (define-key map "|" 'notmuch-show-pipe-message)
 (define-key map "w" 'notmuch-show-save-attachments)
 (define-key map "V" 'notmuch-show-view-raw-message)
@@ -360,10 +361,28 @@ buffer."
   mm-handle (> (notmuch-count-attachments mm-handle) 1
   (message "Done"))

+(defun notmuch-recipient-reply (recipient query-string)
+  (switch-to-buffer (generate-new-buffer "notmuch-draft"))
+  (call-process notmuch-command nil t nil "reply"
+   (concat "--recipient=" recipient) query-string)
+  (message-insert-signature)
+  (goto-char (point-min))
+  (if (re-search-forward "^$" nil t)
+  (progn
+   (insert "--text follows this line--")
+   (forward-line)))
+  (message-mode))
+
 (defun notmuch-show-reply ()
   "Begin composing a reply to the current message in a new buffer."
   (interactive)
   (let ((message-id (notmuch-show-get-message-id)))
+(notmuch-recipient-reply "sender" message-id)))
+
+(defun notmuch-show-reply-all ()
+  "Begin composing a reply to the current message in a new buffer."
+  (interactive)
+  (let ((message-id (notmuch-show-get-message-id)))
 (notmuch-reply message-id)))

 (defun notmuch-show-forward-current ()
-- 
1.6.3.3



[PATCH 1/2] notmuch-reply: Add support for replying only to sender

2010-04-06 Thread Sebastian Spaeth
From: Aneesh Kumar K.V 

This patch add --recipient=all|sender option

Signed-off-by: Aneesh Kumar K.V 
---
 notmuch-client.h |2 +
 notmuch-reply.c  |   55 -
 2 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index d36b9ec..3ca4b32 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -73,6 +73,8 @@
 #define STRNCMP_LITERAL(var, literal) \
 strncmp ((var), (literal), sizeof (literal) - 1)

+#define NOTMUCH_REPLY_ALL   0x1
+#define NOTMUCH_REPLY_SENDER_ONLY 0x2
 static inline void
 chomp_newline (char *str)
 {
diff --git a/notmuch-reply.c b/notmuch-reply.c
index 6c15536..e8a0820 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -232,20 +232,37 @@ reply_to_header_is_redundant (notmuch_message_t *message)
 static const char *
 add_recipients_from_message (GMimeMessage *reply,
 notmuch_config_t *config,
-notmuch_message_t *message)
+notmuch_message_t *message,
+int reply_options)
 {
-struct {
+struct reply_to_map {
const char *header;
const char *fallback;
GMimeRecipientType recipient_type;
-} reply_to_map[] = {
+} ;
+const char *from_addr = NULL;
+unsigned int i;
+struct reply_to_map *reply_to_map;
+
+struct reply_to_map reply_to_map_all[] = {
{ "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },
{ "to", NULL, GMIME_RECIPIENT_TYPE_TO  },
{ "cc", NULL, GMIME_RECIPIENT_TYPE_CC  },
-   { "bcc",NULL, GMIME_RECIPIENT_TYPE_BCC }
+   { "bcc",NULL, GMIME_RECIPIENT_TYPE_BCC },
+   {  NULL,NULL, 0 }
 };
-const char *from_addr = NULL;
-unsigned int i;
+
+/* we try from first and then reply-to */
+struct reply_to_map reply_to_map_sender[] = {
+   { "from", "reply-to", GMIME_RECIPIENT_TYPE_TO  },
+   {  NULL,NULL, 0 }
+};
+
+if (reply_options == NOTMUCH_REPLY_SENDER_ONLY) {
+   reply_to_map = reply_to_map_sender;
+} else {
+   reply_to_map = reply_to_map_all;
+}

 /* Some mailing lists munge the Reply-To header despite it being A Bad
  * Thing, see http://www.unicom.com/pw/reply-to-harmful.html
@@ -263,7 +280,7 @@ add_recipients_from_message (GMimeMessage *reply,
reply_to_map[0].fallback = NULL;
 }

-for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
+for (i = 0; reply_to_map[i].header; i++) {
const char *addr, *recipients;

recipients = notmuch_message_get_header (message,
@@ -283,7 +300,7 @@ add_recipients_from_message (GMimeMessage *reply,
 }

 static int
-notmuch_reply_format_default(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query)
+notmuch_reply_format_default(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query, int reply_options)
 {
 GMimeMessage *reply;
 notmuch_messages_t *messages;
@@ -311,7 +328,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t 
*config, notmuch_query_
subject = talloc_asprintf (ctx, "Re: %s", subject);
g_mime_message_set_subject (reply, subject);

-   from_addr = add_recipients_from_message (reply, config, message);
+   from_addr = add_recipients_from_message (reply, config, message, 
reply_options);

if (from_addr == NULL)
from_addr = notmuch_config_get_user_primary_email (config);
@@ -359,7 +376,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t 
*config, notmuch_query_

 /* 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)
+notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query, int reply_options)
 {
 GMimeMessage *reply;
 notmuch_messages_t *messages;
@@ -399,7 +416,7 @@ notmuch_reply_format_headers_only(void *ctx, 
notmuch_config_t *config, notmuch_q
g_mime_object_set_header (GMIME_OBJECT (reply),
  "References", references);

-   (void)add_recipients_from_message (reply, config, message);
+   (void)add_recipients_from_message (reply, config, message, 
reply_options);

g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",
   notmuch_config_get_user_primary_email (config));
@@ -423,8 +440,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 notmuch_database_t *notmuch;
 notmuch_query_t *query;
 char *opt, *query_string;
-int i, ret = 0;
-int (*reply_format_func)(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query);
+int i, ret = 0, reply_to = NOTMUCH_REPLY_ALL;
+int (*reply_format_func)(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query, int reply_options);

 reply_format_func = 

[notmuch] [PATCH -V2 1/2] notmuch-reply: Add support for replying only to sender

2010-04-06 Thread Sebastian Spaeth
I just rebased these two patches as the files have been moved around. I
use those patches and they work fine for me, by the way. Patches will
arrive in a second as reply to this message.

Sebastian


[PATCH] json: Avoid calling strlen(NULL)

2010-04-06 Thread David Edmondson
commit b65817262b3a275ecd0ef1898d92ec5508a9f810
Author: David Edmondson 
Date:   Tue Apr 6 08:24:00 2010 +0100

json: Avoid calling strlen(NULL)

MIME parts may have no filename, which previously resulted in calling
strlen(NULL).

Modified json.c
diff --git a/json.c b/json.c
index f90b0fa..b73f22a 100644
--- a/json.c
+++ b/json.c
@@ -105,5 +105,8 @@ json_quote_chararray(const void *ctx, const char *str, 
const size_t len)
 char *
 json_quote_str(const void *ctx, const char *str)
 {
+if (str == NULL)
+   return (char *)"\"\"";
+
 return (json_quote_chararray (ctx, str, strlen (str)));
 }


dme.
-- 
David Edmondson, http://dme.org


[PATCH] json: Avoid calling strlen(NULL)

2010-04-06 Thread David Edmondson
commit b65817262b3a275ecd0ef1898d92ec5508a9f810
Author: David Edmondson d...@dme.org
Date:   Tue Apr 6 08:24:00 2010 +0100

json: Avoid calling strlen(NULL)

MIME parts may have no filename, which previously resulted in calling
strlen(NULL).

Modified json.c
diff --git a/json.c b/json.c
index f90b0fa..b73f22a 100644
--- a/json.c
+++ b/json.c
@@ -105,5 +105,8 @@ json_quote_chararray(const void *ctx, const char *str, 
const size_t len)
 char *
 json_quote_str(const void *ctx, const char *str)
 {
+if (str == NULL)
+   return (char *)\\;
+
 return (json_quote_chararray (ctx, str, strlen (str)));
 }


dme.
-- 
David Edmondson, http://dme.org
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] [PATCH] notmuch.el: Allow citation suffixes to be shown as well as prefixes.

2010-04-06 Thread Sebastian Spaeth
On Wed, 17 Feb 2010 10:51:51 +, David Edmondson d...@dme.org wrote:
 In many conversations the last few lines of a citation are more
 interesting than the first few lines, hence allow those to be shown if
 desired.
 
 Modify the face used for the citation button to distinguish it from
 the surrounding citation.

I've been using this patch and don't want to lose it. However, as it
does not apply anymore due to the file moving, I'll reply with 2 updated
patches that produce nicer citations.

Sebastian
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 1/2] notmuch.el: Allow citation suffixes to be shown as well as prefixes.

2010-04-06 Thread Sebastian Spaeth
From: David Edmondson d...@dme.org

In many conversations the last few lines of a citation are more
interesting than the first few lines, hence allow those to be shown if
desired.

Modify the face used for the citation button to distinguish it from
the surrounding citation.

Signed-off-by: Sebastian Spaeth sebast...@sspaeth.de
---
 emacs/notmuch-show.el |   36 +---
 1 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index cc1f905..f172f6b 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -111,10 +111,20 @@ Can use up to one integer format parameter, i.e. %d)
   Maximum length of signature that will be hidden by default.)
 
 (defvar notmuch-show-citation-lines-prefix 4
-  Always show at least this many lines of a citation.
+  Always show at least this many lines at the start of a citation.
 
-If there is one more line, show that, otherwise collapse
-remaining lines into a button.)
+If there is one more line than the sum of
+`notmuch-show-citation-lines-prefix' and
+`notmuch-show-citation-lines-suffix', show that, otherwise
+collapse remaining lines into a button.)
+
+(defvar notmuch-show-citation-lines-suffix 0
+  Always show at least this many lines at the end of a citation.
+
+If there is one more line than the sum of
+`notmuch-show-citation-lines-prefix' and
+`notmuch-show-citation-lines-suffix', show that, otherwise
+collapse remaining lines into a button.)
 
 (defvar notmuch-show-message-begin-regexp\fmessage{)
 (defvar notmuch-show-message-end-regexp  \fmessage})
@@ -679,16 +689,20 @@ is what to put on the button.
   (let* ((cite-start (match-beginning 0))
 (cite-end  (match-end 0))
 (cite-lines (count-lines cite-start cite-end)))
-   (when ( cite-lines (1+ notmuch-show-citation-lines-prefix))
+   (overlay-put (make-overlay cite-start cite-end) 'face 
'message-cited-text-face)
+   (when ( cite-lines (1+ (+ notmuch-show-citation-lines-prefix 
notmuch-show-citation-lines-suffix)))
  (goto-char cite-start)
  (forward-line notmuch-show-citation-lines-prefix)
- (notmuch-show-region-to-button
-  (point) cite-end
-  citation
-  indent
-  (format notmuch-show-citation-button-format
-  (- cite-lines notmuch-show-citation-lines-prefix))
-  
+ (let ((hidden-start (point)))
+   (goto-char cite-end)
+   (forward-line (- notmuch-show-citation-lines-suffix))
+   (notmuch-show-region-to-button
+hidden-start (point)
+citation
+indent
+(format notmuch-show-citation-button-format
+(- cite-lines notmuch-show-citation-lines-prefix 
notmuch-show-citation-lines-suffix))
+)
 (if (and ( (point) end)
 (re-search-forward signature-regexp end t))
(let* ((sig-start (match-beginning 0))
-- 
1.6.3.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 2/2] notmuch.el: Colour cited regions and signatures with message-cited-text-face

2010-04-06 Thread Sebastian Spaeth
From: David Edmondson d...@dme.org

Patch from mail id:1266226909-19360-1-git-send-email-...@dme.org with a fix in 
id:873a12hl3f@aw.hh.sledj.net

Signed-off-by: Sebastian Spaeth sebast...@sspaeth.de
---
 emacs/notmuch-show.el |   18 ++
 1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index f172f6b..353b57d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -708,14 +708,16 @@ is what to put on the button.
(let* ((sig-start (match-beginning 0))
   (sig-end (match-end 0))
   (sig-lines (1- (count-lines sig-start end
- (if (= sig-lines notmuch-show-signature-lines-max)
- (notmuch-show-region-to-button
-  sig-start
-  end
-  signature
-  indent
-  (format notmuch-show-signature-button-format sig-lines)
-  ))
+(if (= sig-lines notmuch-show-signature-lines-max)
+  (progn
+(overlay-put (make-overlay sig-start end) 'face 
'message-cited-text-face)
+(notmuch-show-region-to-button
+ sig-start
+ end
+ signature
+ indent
+ (format notmuch-show-signature-button-format sig-lines)
+ )))
 
 (defun notmuch-show-markup-part (beg end depth)
   (if (re-search-forward notmuch-show-part-begin-regexp nil t)
-- 
1.6.3.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] [PATCH V4] notmuch.el: Make notmuch-show buffer name first subject, instead of thread-id (supersedes V1--3)

2010-04-06 Thread Sebastian Spaeth
On Sat, 06 Mar 2010 09:20:21 -0500, Jesse Rosenthal jrosent...@jhu.edu wrote:
 Change the buffer name to a uniquified subject of the thread (i.e. the
 subject of the first message in the thread) instead of the thread-id. This
 is more meaningful to the user, and will make it easier to scroll through
 numerous open buffers.

I have been using this patch since it was posted and find it very
useful. However, it won't apply anymore due to the code shuffling. I'll
reply to this message and send a rebased version that applies to current
cworth/master.

Sebastian
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] notmuch.el: Make notmuch-show buffer name first subject, instead of thread-id (supersedes V1--3)

2010-04-06 Thread Sebastian Spaeth
From: Jesse Rosenthal jrosent...@jhu.edu

Change the buffer name to a uniquified subject of the thread (i.e. the
subject of the first message in the thread) instead of the thread-id. This
is more meaningful to the user, and will make it easier to scroll through
numerous open buffers.

Note that this patch adds an optional `buffer-name' argument to notmuch
show.

This version supersedes V1--3 of this patch. It ensures that the buffer
names are unique, and that the `notmuch-show' command can still be used
 interactively (fixing embarassing bugs in V2 and V3 which prevented that)

Signed-off-by: Jesse Rosenthal jrosent...@jhu.edu
Signed-off-by: Sebastian Spaeth sebast...@sspaeth.de
---
 emacs/notmuch-show.el |   11 ---
 emacs/notmuch.el  |   14 --
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index cc1f905..ed95afb 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -959,7 +959,7 @@ All currently available key bindings:
  (lambda()
(hl-line-mode 1) ))
 
-(defun notmuch-show (thread-id optional parent-buffer query-context)
+(defun notmuch-show (thread-id optional parent-buffer query-context 
buffer-name)
   Run \notmuch show\ with the given thread ID and display results.
 
 The optional PARENT-BUFFER is the notmuch-search buffer from
@@ -967,9 +967,14 @@ which this notmuch-show command was executed, (so that the 
next
 thread from that buffer can be show when done with this one).
 
 The optional QUERY-CONTEXT is a notmuch search term. Only messages from the 
thread
-matching this search term are shown if non-nil. 
+matching this search term are shown if non-nil.
+
+The optional BUFFER-NAME provides the neame of the buffer in which the message 
thread is shown. If it is nil (which occurs when the command is called 
interactively) the argument to the function is used. 
   (interactive sNotmuch show: )
-  (let ((buffer (get-buffer-create (concat *notmuch-show- thread-id *
+  (when (null buffer-name)
+(setq buffer-name (concat *notmuch- thread-id *)))
+  (let* ((thread-buffer-name (generate-new-buffer-name buffer-name))
+(buffer (get-buffer-create thread-buffer-name)))
 (switch-to-buffer buffer)
 (notmuch-show-mode)
 (set (make-local-variable 'notmuch-show-parent-buffer) parent-buffer)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 5e479d6..ca0b6e0 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -404,9 +404,19 @@ Complete list of currently available key bindings:
 (defun notmuch-search-show-thread ()
   Display the currently selected thread.
   (interactive)
-  (let ((thread-id (notmuch-search-find-thread-id)))
+  (let ((thread-id (notmuch-search-find-thread-id))
+   (subject (notmuch-search-find-subject))
+   buffer-name)
+(when (string-match ^[ \t]*$ subject)
+  (setq subject [No Subject]))
+(setq buffer-name (concat *
+ (truncate-string-to-width subject 32 nil nil t)
+ *))
 (if ( (length thread-id) 0)
-   (notmuch-show thread-id (current-buffer) notmuch-search-query-string)
+   (notmuch-show thread-id
+ (current-buffer)
+ notmuch-search-query-string
+ buffer-name)
   (error End of search results
 
 (defun notmuch-search-reply-to-thread ()
-- 
1.6.3.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] vala, this is notmuch. notmuch, this is vala

2010-04-06 Thread Sebastian Spaeth
On Mon, 5 Apr 2010 14:50:04 +0100, Enrico Zini enr...@enricozini.org wrote:
 Now I use lbdb, which gets very slow as time goes. You idea creates a
 most definitely superior system.

You can actually use both :): Do check out the patch on the mailing list
to combine the notmuch address lookup with bbdb via EUDC. It works nice
for me. Although the notmuch address lookup works so well for me that I
basically never get a fallback to bbdb.

If pure email addresses is all you need (no real names yet), the above
code works well when integrated via EUDC.

Sebastian
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] Message parsing issue?

2010-04-06 Thread David Bremner
On Sat, 3 Apr 2010 18:25:40 +1100, Jason White ja...@jasonjgw.net wrote:

 The problem is that for certain messages, notmuch show treats the entire
 message, including, significantly, all of the headers, as the message body.
 
 An example is attached, with notmuch show output as the first file and the
 original message as the second.
 
 Suggestions are welcome.

One thing I noticed was that the message you sent (at least, if I got
the correct attachment), had X-Spam headers _before_ the From 
line. If I remove those headers then the message displays Ok.  It is
probably not worth putting too much effort into that display code since
it is in the process of being completely rewritten. Perhaps an extra
pass through formail can format you message headers a bit more nicely?

David
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] Bulk message tagging

2010-04-06 Thread Mark Anderson
On Mon, 5 Apr 2010 01:15:39 -0500, Xavier Maillard x...@gnu.org wrote:
 On Sun, 04 Apr 2010 07:38:03 -0400, Jesse Rosenthal jrosent...@jhu.edu 
 wrote:
  On Sun, 04 Apr 2010 06:37:53 +0200, Xavier Maillard x...@gnu.org wrote:
   Is there an easy way to mark a whole bunch of message (restricted
   in a region, result of a search, ...) ?
  
  In addition to the * command that was mentioned, there is a patch I
  wrote to tag messages in search view by region in emacs. You can find it
 
 Sounds interesting. * is good when your search criteria is
 perfect but you proposed patch is a good companion for all the
 rest.
 
 Sadly, git is not really something I know wll enough to play with
 all this stuff :(
 
 Xavier

Also, you will want to be careful with '*' in emacs.

It runs notmuch tag +tag search terms from buffer,
but the notmuch-search buffer can be woefully out of date.

I like to go through and add tags, archive, etc, lots of email.  Then I
'q' back to the search buffer, and I may realize that I want to tag
everything I can see.  '*' isn't really that command, it applies a tag
to the results of a search that you are looking at.  But it will use a
fresh version of the search, not the version in the buffer, which could
be minutes, hours, days or weeks old, depending on your Emacs buffer
management habits (or lack of them).

I think that '*' is definitely an awesome command, but I wonder if we
shouldn't have another command for the notmuch-search buffer which means
'tag all the threads that I can see in this buffer'.

If you have a crontab running 'notmuch new', you could end up tagging a
lot of things you would rather have a chance to review first.  I often
use '*' to tag:deleted a large number of mails once I have a query I
like, so deleting things sight unseen is an unpleasant thought.

I know that there is an emacs-region patch, which could probably be
extended to implement the behavior I'm talking about, but I have a hard
enough time adding keys to the keymaps, and alas, the time thing...

Maybe someone else will decide it's important enough to do, or has
already done it.

Enjoy,
-Mark

 ___
 notmuch mailing list
 notmuch@notmuchmail.org
 http://notmuchmail.org/mailman/listinfo/notmuch
 

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] Remove dangling opening curly bracket.

2010-04-06 Thread Servilio Afre Puentes
Signed-off-by: Servilio Afre Puentes servi...@gmail.com
---
 notmuch-reply.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 3798d60..8eb4754 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -383,7 +383,7 @@ notmuch_reply_format_default(void *ctx,
notmuch_config_t *config, notmuch_query_
if (from_addr == NULL)
from_addr = guess_from_received_header (config, message);

-   if (from_addr == NULL) {
+   if (from_addr == NULL)
from_addr = notmuch_config_get_user_primary_email (config);

from_addr = talloc_asprintf (ctx, %s %s,
-- 
1.7.0
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] [Sebastian Spaeth] Pull requests

2010-04-06 Thread micah anderson
On 2010-03-27, micah anderson wrote:
 On Thu, 25 Mar 2010 22:50:52 -0400, micah anderson mi...@riseup.net wrote:
  On Mon, 01 Mar 2010 15:57:00 +0100, Sebastian Spaeth 
  sebast...@sspaeth.de wrote:
  
   From git repository git://github.com/spaetz/notmuch-all-feature.git I
   would like to advocate the following branches for quick pulling. Each
   contains 1 or 2 patches. They have all been based on todays
   cworth/master, so it should be really painless.
  
  Thanks for pulling these all together! All the ones that you propose I
  also use and would really like these to be merged as well.
  
  The only other patch that I find absolutely crucial, that you do not
  include, is the 'Preserve folder information when indexing' patch which,
  although not perfect, does significantly change my life. 
 
 Glad you find it useful. Yes, having the folder information would indeed
 be nice. Is that patch working well for you? (Can you point me to the
 mail ID of the patch you are using? There have been several versions
 around).

The patch works really well for me. I also had difficulty figuring out
which was the latest. The thread is
thread:4ca0710d708e648c214ba3a67469f5bd, and the Message-ID is:
1265122868-12133-1-git-send-email-sojk...@fel.cvut.cz

I had to rebase the patch to get it to apply with the other features
that you have in your branch. I'm attaching that rebased patch to this
message.






pgpjTfePIOaPP.pgp
Description: PGP signature
commit 91e11a2a406683f1f80e19334da8124a25ec89fe
Author: Micah Anderson mi...@riseup.net
Date:   Thu Mar 25 23:07:10 2010 -0400

add folder patch, rebased

diff --git a/lib/database.cc b/lib/database.cc
index c91e97c..6364623 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -84,9 +84,9 @@ typedef struct {
  *	MESSAGE_ID:	The unique ID of the mail mess (see id above)
  *
  * In addition, terms from the content of the message are added with
- * from, to, attachment, and subject prefixes for use by the
- * user in searching. But the database doesn't really care itself
- * about any of these.
+ * from, to, attachment, subject and folder prefixes for use
+ * by the user in searching. But the database doesn't really care
+ * itself about any of these.
  *
  * The data portion of a mail document is empty.
  *
@@ -155,7 +155,8 @@ prefix_t PROBABILISTIC_PREFIX[]= {
 { from,			XFROM },
 { to,			XTO },
 { attachment,		XATTACHMENT },
-{ subject,		XSUBJECT}
+{ subject,		XSUBJECT},
+{ folder, 		XFOLDER}
 };
 
 int
@@ -1362,6 +1363,7 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
 notmuch_status_t
 notmuch_database_add_message (notmuch_database_t *notmuch,
 			  const char *filename,
+			  const char *folder_name,
 			  notmuch_message_t **message_ret)
 {
 notmuch_message_file_t *message_file;
@@ -1477,6 +1479,9 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 	date = notmuch_message_file_get_header (message_file, date);
 	_notmuch_message_set_date (message, date);
 
+	if (folder_name != NULL)
+		_notmuch_message_gen_terms (message, folder, folder_name);
+
 	_notmuch_message_index_file (message, filename);
 	} else {
 	ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 0d9cb0f..e475072 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -263,6 +263,7 @@ notmuch_database_get_directory (notmuch_database_t *database,
 notmuch_status_t
 notmuch_database_add_message (notmuch_database_t *database,
 			  const char *filename,
+			  const char *folder_name,
 			  notmuch_message_t **message);
 
 /* Remove a message from the given notmuch database.
diff --git a/notmuch-new.c b/notmuch-new.c
index 93da1d7..394d76c 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -21,6 +21,7 @@
 #include notmuch-client.h
 
 #include unistd.h
+#include glib.h
 
 typedef struct _filename_node {
 char *filename;
@@ -224,6 +225,35 @@ derive_tags_from_maildir_flags (notmuch_message_t *message,
 }
 }
 
+static char*
+_get_folder_base_name(const char *path)
+{
+gchar *full_folder_name = NULL;
+gchar *folder_base_name = NULL;
+
+/* Find name of folder containing the email. */
+full_folder_name = g_strdup(path);
+while (1) {
+	folder_base_name = g_path_get_basename(full_folder_name);
+
+	if (strcmp(folder_base_name, cur) == 0
+	|| strcmp(folder_base_name, new) == 0) {
+	gchar *parent_name = g_path_get_dirname(full_folder_name);
+	g_free(full_folder_name);
+	full_folder_name = parent_name;
+	} else
+	break;
+}
+
+g_free(full_folder_name);
+
+if (strcmp(folder_base_name, .) == 0) {
+	g_free(folder_base_name);
+	folder_base_name = NULL;
+}
+return folder_base_name;
+}
+
 /* Examine 'path' recursively as follows:
  *
  *   o Ask the filesystem for the mtime of 'path' (fs_mtime)
@@ -277,6 +307,7 @@ add_files_recursive (notmuch_database_t *notmuch,
 notmuch_filenames_t *db_subdirs = NULL;
 struct stat st;
 

[RFC] reordering and cleanup of thread authors

2010-04-06 Thread Dirk Hohndel

This is based in part on some discussion on IRC today.
When a thread is displayed in the search results, previously the authors
were always displayed in chronological order. But if only part of the
thread matches the query, that may or may not be the intuitive thing to
do.
Imagine the default +inbox query. Those mails in the thread that
match the query are actually new (whatever that means). And some
people seem to think that it would be much better to see those author
names first. For example, imagine a long and drawn out thread that once
was started by me; you have long read the older part of the thread and
removed the inbox tag. Whenever a new email comes in on this thread, the
author column in the search display will first show Dirk Hohndel - I
think it should first show the actual author(s) of the new mail(s).

The second cleanup that I've done in this context is to convert all
author names into the much easier to parse Firstname Lastname
format. Some broken mail systems (cough - Exchange - Cough) seem to
prefer Lastname, Firstname - which makes the comma separated list of
authors really hard to parse at one glance. Worse, it creates douplicate
entries if a person happens to show in both orders. So this does a
rather simplistic look for a comma, if it's there, reorder approach to
cleaning up the author name.

I don't think this is ready to be pulled. There was a strong request on
IRC to make the re-ordering of the author names configurable. I think
the cleanup of the names (First Last) should be configurable as well.
And of course I wonder about my implementation, given that I'm still
trying to wrap my mind around the current code base.

Thanks

/D

diff --git a/lib/message.cc b/lib/message.cc
index 721c9a6..ac0afd9 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -35,6 +35,7 @@ struct _notmuch_message {
 char *thread_id;
 char *in_reply_to;
 char *filename;
+char *author;
 notmuch_message_file_t *message_file;
 notmuch_message_list_t *replies;
 unsigned long flags;
@@ -110,6 +111,7 @@ _notmuch_message_create (const void *talloc_owner,
 message-in_reply_to = NULL;
 message-filename = NULL;
 message-message_file = NULL;
+message-author = NULL;
 
 message-replies = _notmuch_message_list_create (message);
 if (unlikely (message-replies == NULL)) {
@@ -533,6 +535,20 @@ notmuch_message_get_tags (notmuch_message_t *message)
 return _notmuch_convert_tags(message, i, end);
 }
 
+const char *
+notmuch_message_get_author (notmuch_message_t *message)
+{
+return message-author;
+}
+
+void
+notmuch_message_set_author (notmuch_message_t *message,
+   const char *author)
+{
+message-author = talloc_strdup(message, author);
+return;
+}
+
 void
 _notmuch_message_set_date (notmuch_message_t *message,
   const char *date)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 88da078..79638bb 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -771,6 +771,17 @@ notmuch_message_set_flag (notmuch_message_t *message,
 time_t
 notmuch_message_get_date  (notmuch_message_t *message);
 
+/* Set the author member of 'message' - this is the representation used
+ * when displaying the message
+ */
+void
+notmuch_message_set_author (notmuch_message_t *message, const char *author);
+
+/* Get the author member of 'message'
+ */
+const char *
+notmuch_message_get_author (notmuch_message_t *message);
+
 /* Get the value of the specified header from 'message'.
  *
  * The value will be read from the actual message file, not from the
diff --git a/lib/thread.cc b/lib/thread.cc
index 48c070e..c3c83a3 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -32,6 +32,7 @@ struct _notmuch_thread {
 char *subject;
 GHashTable *authors_hash;
 char *authors;
+char *nonmatched_authors;
 GHashTable *tags;
 
 notmuch_message_list_t *message_list;
@@ -69,8 +70,95 @@ _thread_add_author (notmuch_thread_t *thread,
thread-authors = talloc_asprintf (thread, %s, %s,
   thread-authors,
   author);
-else
+else {
thread-authors = talloc_strdup (thread, author);
+}
+}
+
+/*
+ * move authors of matched messages in the thread to 
+ * the front of the authors list, but keep them in
+ * oldest first order within their group
+ */
+static void
+_thread_move_matched_author (notmuch_thread_t *thread,
+const char *author)
+{
+char *authorscopy;
+char *currentauthor;
+int idx,nmstart,author_len,authors_len;
+
+if (thread-authors == NULL)
+   return;
+if (thread-nonmatched_authors == NULL)
+   thread-nonmatched_authors = thread-authors;
+author_len = strlen(author);
+authors_len = strlen(thread-authors);
+if (author_len == authors_len) {
+   /* just one author */
+   thread-nonmatched_authors += author_len;
+   return;
+}
+currentauthor =