[PATCH] build: Require gmime >= 2.6.7

2012-03-11 Thread David Bremner
From: Thomas Jost 

gmime-2.6 had a bug [1] which made it impossible to tell why a signature
verification failed when the signer key was unavailable (empty "sigstatus" field
in the JSON output). Since 00b5623d the corresponding test is marked as broken
when using gmime-2.6 (2.4 is fine).

This bug has been fixed in gmime 2.6.5, which is now the minimal gmime-2.6
version required for building notmuch (gmime-2.4 is still available). As a
consequence the version check in test/crypto can be removed.

[Added by db]

Although less unambigously a bug, Gmime 2.6 prior to 2.6.7 also was
more strict about parsing, and rejected messages with initial "From "
headers.  This restriction is relaxed in [2].  For reasons explained in [3],
we want to keep this more relaxed parsing for now.

[1] https://bugzilla.gnome.org/show_bug.cgi?id=668085

[2] 
http://git.gnome.org/browse/gmime/commit/?id=d311f576baf750476e06e9a1367a2dc1793ea7eb

[3] id:"1331385931-1610-1-git-send-email-david at tethera.net"
---

As an alternative to applying [3], I could apply this modified version of
Thomas's patch. 


 configure   |4 +++-
 test/crypto |2 --
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index dedb7d8..ee0ae73 100755
--- a/configure
+++ b/configure
@@ -273,9 +273,11 @@ if [ ${have_xapian} = "0" ]; then
 errors=$((errors + 1))
 fi

+# If using GMime 2.6, we need to have a version >= 2.6.5 to avoid a
+# crypto bug. We need 2.6.7 for permissive "From " header handling.
 printf "Checking for GMime development files... "
 have_gmime=0
-for gmimepc in gmime-2.6 gmime-2.4; do
+for gmimepc in 'gmime-2.6 >= 2.6.7' gmime-2.4; do
 if pkg-config --exists $gmimepc; then
printf "Yes ($gmimepc).\n"
have_gmime=1
diff --git a/test/crypto b/test/crypto
index 1dbb60a..6723ef8 100755
--- a/test/crypto
+++ b/test/crypto
@@ -104,8 +104,6 @@ test_expect_equal \
 "$expected"

 test_begin_subtest "signature verification with signer key unavailable"
-# this is broken with current versions of gmime-2.6
-(ldd $(which notmuch) | grep -Fq gmime-2.6) && test_subtest_known_broken
 # move the gnupghome temporarily out of the way
 mv "${GNUPGHOME}"{,.bak}
 output=$(notmuch show --format=json --verify subject:"test signed message 001" 
\
-- 
1.7.9.1



[PATCH v6 06/10] schemata: Add documentation for JSON reply format.

2012-03-11 Thread Adam Wolfe Gordon
On Sun, Mar 11, 2012 at 18:36, Austin Clements  wrote:
> Oops. ?Looks like I left references to various old JSON functions in
> the schemata file. ?I'll submit a patch to fix those up, but you might
> as well use the correct function names in the new documentation.

Erk, I missed this review as I was making up the latest version of the
series. I guess I'll have to send another, but I'll wait for reviews
on the other patches first.


[PATCH v7 10/10] emacs: Use the new JSON reply format and message-cite-original

2012-03-11 Thread Adam Wolfe Gordon
Use the new JSON reply format to create replies in emacs. Quote HTML
parts nicely by using mm-display-part to turn them into displayable
text, then quoting them with message-cite-original. This is very
useful for users who regularly receive HTML-only email.

Use message-mode's message-cite-original function to create the
quoted body for reply messages. In order to make this act like the
existing notmuch defaults, you will need to set the following in
your emacs configuration:

message-citation-line-format "On %a, %d %b %Y, %f wrote:"
message-citation-line-function 'message-insert-formatted-citation-line

The tests have been updated to reflect the (ugly) emacs default.
---
 emacs/notmuch-lib.el |   11 
 emacs/notmuch-mua.el |  136 +++---
 test/emacs   |8 ++--
 3 files changed, 110 insertions(+), 45 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 7e3f110..8bac596 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -206,6 +206,17 @@ the user hasn't set this variable with the old or new 
value."
  (setq seq (nconc (delete elem seq) (list elem))
 seq))

+(defun notmuch-parts-filter-by-type (parts type)
+  "Given a list of message parts, return a list containing the ones matching
+the given type."
+  (remove-if-not
+   (lambda (part) (notmuch-match-content-type (plist-get part :content-type) 
type))
+   parts))
+
+(defun notmuch-plist-to-alist (plist)
+  (loop for (key value . rest) on plist by #'cddr
+   collect (cons (substring (symbol-name key) 1) value)))
+
 ;; Compatibility functions for versions of emacs before emacs 23.
 ;;
 ;; Both functions here were copied from emacs 23 with the following copyright:
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 13244eb..5adf4d8 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -19,11 +19,15 @@
 ;;
 ;; Authors: David Edmondson 

+(require 'json)
 (require 'message)
+(require 'format-spec)

 (require 'notmuch-lib)
 (require 'notmuch-address)

+(eval-when-compile (require 'cl))
+
 ;;

 (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
@@ -72,54 +76,104 @@ list."
(push header message-hidden-headers)))
notmuch-mua-hidden-headers))

+(defun notmuch-mua-get-displayed-part (part query-string)
+  (with-temp-buffer
+(if (plist-get part :content)
+   (insert (plist-get part :content))
+  (call-process notmuch-command nil t nil "show" "--format=raw"
+   (format "--part=%s" (plist-get part :id))
+   query-string))
+
+(let ((handle (mm-make-handle (current-buffer) (list (plist-get part 
:content-type
+ (end-of-orig (point-max)))
+  (mm-display-part handle)
+  (delete-region (point-min) end-of-orig)
+  (buffer-substring (point-min) (point-max)
+
+(defun notmuch-mua-get-quotable-parts (parts)
+  (loop for part in parts
+   if (notmuch-match-content-type (plist-get part :content-type) 
"multipart/alternative")
+ collect (let* ((subparts (plist-get part :content))
+   (types (mapcar (lambda (part) (plist-get part 
:content-type)) subparts))
+   (chosen-type (car (notmuch-multipart/alternative-choose 
types
+  (loop for part in (reverse subparts)
+if (notmuch-match-content-type (plist-get part 
:content-type) chosen-type)
+return part))
+   else if (notmuch-match-content-type (plist-get part :content-type) 
"multipart/*")
+ append (notmuch-mua-get-quotable-parts (plist-get part :content))
+   else if (notmuch-match-content-type (plist-get part :content-type) 
"text/*")
+ collect part))
+
 (defun notmuch-mua-reply (query-string  sender reply-all)
-  (let (headers
-   body
-   (args '("reply")))
-(if notmuch-show-process-crypto
-   (setq args (append args '("--decrypt"
+  (let ((args '("reply" "--format=json"))
+   (json-object-type 'plist)
+   (json-array-type 'list)
+   (json-false 'nil)
+   reply
+   original)
+(when notmuch-show-process-crypto
+  (setq args (append args '("--decrypt"
+
 (if reply-all
(setq args (append args '("--reply-to=all")))
   (setq args (append args '("--reply-to=sender"
 (setq args (append args (list query-string)))
-;; This make assumptions about the output of `notmuch reply', but
-;; really only that the headers come first followed by a blank
-;; line and then the body.
+
+;; Get the reply object as JSON, and parse it into an elisp object.
 (with-temp-buffer
   (apply 'call-process (append (list notmuch-command nil (list t t) nil) 
args))
   (goto-char (point-min))
-  (if (re-search-forward "^$" nil t)
- (save-excursion
-   (save-restriction
- (narrow-to-region (point-min) (point))
- (goto-char (point-min))
-  

[PATCH v7 09/10] test: Add broken tests for new emacs reply functionality

2012-03-11 Thread Adam Wolfe Gordon
Add tests for creating nice replies to multipart messages, including
those with HTML parts. These tests are expected to fail for now.
---
 test/emacs |   97 
 1 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/test/emacs b/test/emacs
index 29a489c..01afdb6 100755
--- a/test/emacs
+++ b/test/emacs
@@ -273,6 +273,103 @@ On 01 Jan 2000 12:00:00 -, Notmuch Test Suite 
 w
 EOF
 test_expect_equal_file OUTPUT EXPECTED

+test_begin_subtest "Reply within emacs to a multipart/mixed message"
+test_subtest_known_broken
+test_emacs '(notmuch-show "id:20091118002059.067214ed at hikari")
+   (notmuch-show-reply)
+   (test-output)'
+cat 
+Fcc: ${MAIL_DIR}/sent
+--text follows this line--
+Adrian Perez de Castro  writes:
+
+> Hello to all,
+>
+> I have just heard about Not Much today in some random Linux-related news
+> site (LWN?), my name is Adrian Perez and I work as systems administrator
+> (although I can do some code as well :P). I have always thought that the
+> ideas behind Sup were great, but after some time using it, I got tired of
+> the oddities that it has. I also do not like doing things like having to
+> install Ruby just for reading and sorting mails. Some time ago I thought
+> about doing something like Not Much and in fact I played a bit with the
+> Python+Xapian and the Python+Whoosh combinations, because I find relaxing
+> to code things in Python when I am not working and also it is installed
+> by default on most distribution. I got to have some mailboxes indexed and
+> basic searching working a couple of months ago. Lately I have been very
+> busy and had no time for coding, and them... boom! Not Much appears -- and
+> it is almost exactly what I was trying to do, but faster. I have been
+> playing a bit with Not Much today, and I think it has potential.
+>
+> Also, I would like to share one idea I had in mind, that you might find
+> interesting: One thing I have found very annoying is having to re-tag my
+> mail when the indexes get b0rked (it happened a couple of times to me while
+> using Sup), so I was planning to mails as read/unread and adding the tags
+> not just to the index, but to the mail text itself, e.g. by adding a
+> "X-Tags" header field or by reusing the "Keywords" one. This way, the index
+> could be totally recreated by re-reading the mail directories, and this
+> would also allow to a tools like OfflineIMAP [1] to get the mails into a
+> local maildir, tagging and indexing the mails with the e-mail reader and
+> then syncing back the messages with the "X-Tags" header to the IMAP server.
+> This would allow to use the mail reader from a different computer and still
+> have everything tagged finely.
+>
+> Best regards,
+>
+>
+> ---
+> [1] http://software.complete.org/software/projects/show/offlineimap
+>
+> -- 
+> Adrian Perez de Castro 
+> Igalia - Free Software Engineering
+> ___
+> notmuch mailing list
+> notmuch at notmuchmail.org
+> http://notmuchmail.org/mailman/listinfo/notmuch
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest "Reply within emacs to a multipart/alternative message"
+test_subtest_known_broken
+test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a at 
mail.gmail.com")
+   (notmuch-show-reply)
+   (test-output)'
+cat  I saw the announcement this morning, and was very excited, as I had been
+> hoping sup would be turned into a library,
+> since I like the concept more than the UI (I'd rather an emacs interface).
+>
+> I did a preliminary compile which worked out fine, but
+> sysconf(_SC_SC_GETPW_R_SIZE_MAX) returns -1 on
+> FreeBSD, so notmuch_config_open segfaulted.
+>
+> Attached is a patch that supplies a default buffer size of 64 in cases where
+> -1 is returned.
+>
+> http://www.opengroup.org/austin/docs/austin_328.txt - seems to indicate this
+> is acceptable behavior,
+> and 
http://mail-index.netbsd.org/pkgsrc-bugs/2006/06/07/msg016808.htmlspecifically
+> uses 64 as the
+> buffer size.
+> ___
+> notmuch mailing list
+> notmuch at notmuchmail.org
+> http://notmuchmail.org/mailman/listinfo/notmuch
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
 test_begin_subtest "Quote MML tags in reply"
 message_id='test-emacs-mml-quoting at message.id'
 add_message [id]="$message_id" \
-- 
1.7.5.4



[PATCH v7 08/10] emacs: Factor out useful functions into notmuch-lib

2012-03-11 Thread Adam Wolfe Gordon
Move a few functions related to handling multipart/alternative parts
into notmuch-lib.el, so they can be used by future reply code.
---
 emacs/notmuch-lib.el  |   33 +
 emacs/notmuch-show.el |   24 ++--
 2 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index d315f76..7e3f110 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -21,6 +21,8 @@

 ;; This is an part of an emacs-based interface to the notmuch mail system.

+(eval-when-compile (require 'cl))
+
 (defvar notmuch-command "notmuch"
   "Command to run the notmuch binary.")

@@ -173,6 +175,37 @@ the user hasn't set this variable with the old or new 
value."
   (list 'when (< emacs-major-version 23)
form))

+(defun notmuch-split-content-type (content-type)
+  "Split content/type into 'content' and 'type'"
+  (split-string content-type "/"))
+
+(defun notmuch-match-content-type (t1 t2)
+  "Return t if t1 and t2 are matching content types, taking wildcards into 
account"
+  (let ((st1 (notmuch-split-content-type t1))
+   (st2 (notmuch-split-content-type t2)))
+(if (or (string= (cadr st1) "*")
+   (string= (cadr st2) "*"))
+   (string= (car st1) (car st2))
+  (string= t1 t2
+
+(defvar notmuch-multipart/alternative-discouraged
+  '(
+;; Avoid HTML parts.
+"text/html"
+;; multipart/related usually contain a text/html part and some associated 
graphics.
+"multipart/related"
+))
+
+(defun notmuch-multipart/alternative-choose (types)
+  "Return a list of preferred types from the given list of types"
+  ;; Based on `mm-preferred-alternative-precedence'.
+  (let ((seq types))
+(dolist (pref (reverse notmuch-multipart/alternative-discouraged))
+  (dolist (elem (copy-sequence seq))
+   (when (string-match pref elem)
+ (setq seq (nconc (delete elem seq) (list elem))
+seq))
+
 ;; Compatibility functions for versions of emacs before emacs 23.
 ;;
 ;; Both functions here were copied from emacs 23 with the following copyright:
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 4a60631..ed938bf 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -542,30 +542,13 @@ current buffer, if possible."
(mm-display-part handle)
t))

-(defvar notmuch-show-multipart/alternative-discouraged
-  '(
-;; Avoid HTML parts.
-"text/html"
-;; multipart/related usually contain a text/html part and some associated 
graphics.
-"multipart/related"
-))
-
 (defun notmuch-show-multipart/*-to-list (part)
   (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
  (plist-get part :content)))

-(defun notmuch-show-multipart/alternative-choose (types)
-  ;; Based on `mm-preferred-alternative-precedence'.
-  (let ((seq types))
-(dolist (pref (reverse notmuch-show-multipart/alternative-discouraged))
-  (dolist (elem (copy-sequence seq))
-   (when (string-match pref elem)
- (setq seq (nconc (delete elem seq) (list elem))
-seq))
-
 (defun notmuch-show-insert-part-multipart/alternative (msg part content-type 
nth depth declared-type)
   (notmuch-show-insert-part-header nth declared-type content-type nil)
-  (let ((chosen-type (car (notmuch-show-multipart/alternative-choose 
(notmuch-show-multipart/*-to-list part
+  (let ((chosen-type (car (notmuch-multipart/alternative-choose 
(notmuch-show-multipart/*-to-list part
(inner-parts (plist-get part :content))
(start (point)))
 ;; This inserts all parts of the chosen type rather than just one,
@@ -808,9 +791,6 @@ current buffer, if possible."

 ;; Functions for determining how to handle MIME parts.

-(defun notmuch-show-split-content-type (content-type)
-  (split-string content-type "/"))
-
 (defun notmuch-show-handlers-for (content-type)
   "Return a list of content handlers for a part of type CONTENT-TYPE."
   (let (result)
@@ -821,7 +801,7 @@ current buffer, if possible."
  (list (intern (concat "notmuch-show-insert-part-*/*"))
(intern (concat
 "notmuch-show-insert-part-"
-(car (notmuch-show-split-content-type content-type))
+(car (notmuch-split-content-type content-type))
 "/*"))
(intern (concat "notmuch-show-insert-part-" content-type
 result))
-- 
1.7.5.4



[PATCH v7 07/10] man: Add --decrypt to reply flags

2012-03-11 Thread Adam Wolfe Gordon
---
 man/man1/notmuch-reply.1 |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/man/man1/notmuch-reply.1 b/man/man1/notmuch-reply.1
index 36b60cb..e21559a 100644
--- a/man/man1/notmuch-reply.1
+++ b/man/man1/notmuch-reply.1
@@ -68,6 +68,16 @@ values from the first that contains something other than 
only the
 user's addresses.
 .RE
 .RE
+.RS
+.TP 4
+.B \-\-decrypt
+
+Decrypt any MIME encrypted parts found in the selected content
+(ie. "multipart/encrypted" parts). Status of the decryption will be
+reported (currently only supported with --format=json) and the
+multipart/encrypted part will be replaced by the decrypted
+content.
+.RE

 See \fBnotmuch-search-terms\fR(7)
 for details of the supported syntax for .
-- 
1.7.5.4



[PATCH v7 06/10] man: Update notmuch-reply man page for JSON format.

2012-03-11 Thread Adam Wolfe Gordon
---
 man/man1/notmuch-reply.1 |   10 --
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/man/man1/notmuch-reply.1 b/man/man1/notmuch-reply.1
index 7ed7f0f..debc505 100644
--- a/man/man1/notmuch-reply.1
+++ b/man/man1/notmuch-reply.1
@@ -37,12 +37,17 @@ Supported options for
 include
 .RS
 .TP 4
-.BR \-\-format= ( default | headers\-only )
+.BR \-\-format= ( default | json | headers\-only )
 .RS
 .TP 4
 .BR default
 Includes subject and quoted message body.
 .TP
+.BR json
+Produces JSON output containing headers for a reply message and the
+contents of the original message. This output can be used by a client
+to create a reply message intelligently.
+.TP
 .BR headers\-only
 Only produces In\-Reply\-To, References, To, Cc, and Bcc headers.
 .RE
@@ -73,7 +78,8 @@ with a search string matching a single message, (such as
 id:), but it can be useful to reply to several messages at
 once. For example, when a series of patches are sent in a single
 thread, replying to the entire thread allows for the reply to comment
-on issue found in multiple patches.
+on issues found in multiple patches. The default format supports
+replying to multiple messages at once, but the JSON format does not.
 .RE
 .RE

-- 
1.7.5.4



[PATCH v7 05/10] schemata: Add documentation for JSON reply format.

2012-03-11 Thread Adam Wolfe Gordon
---
 devel/schemata |   27 +--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/devel/schemata b/devel/schemata
index 24ad775..b1073a9 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -77,8 +77,9 @@ part = {
 content?:   string
 }

-# The headers of a message (format_headers_json with raw headers) or
-# a part (format_headers_message_part_json with pretty-printed headers)
+# The headers of a message (format_headers_json with raw headers
+# and reply = FALSE) or a part (format_headers_message_part_json
+# with pretty-printed headers)
 headers = {
 Subject:string,
 From:   string,
@@ -136,3 +137,25 @@ thread = {
   # matched and unmatched
 subject:string
 }
+
+notmuch reply schema
+
+
+reply = {
+# The headers of the constructed reply (format_headers_json with
+# raw headers and reply = TRUE)
+reply-headers: reply_headers,
+
+# As in the show format (format_message_json)
+original: message
+}
+
+reply_headers = {
+Subject:string,
+From:   string,
+To?:string,
+Cc?:string,
+Bcc?:   string,
+In-reply-to:string,
+References: string
+}
-- 
1.7.5.4



[PATCH v7 04/10] reply: Add a JSON reply format.

2012-03-11 Thread Adam Wolfe Gordon
This new JSON format for replies includes headers generated for a
reply message as well as the headers of the original message.  Using
this data, a client can intelligently create a reply. For example, the
emacs client will be able to create replies with quoted HTML parts by
parsing the HTML parts.
---
 notmuch-client.h |   14 ++
 notmuch-reply.c  |   49 +
 notmuch-show.c   |   29 +
 test/multipart   |1 -
 4 files changed, 80 insertions(+), 13 deletions(-)

diff --git a/notmuch-client.h b/notmuch-client.h
index f4a62cc..270daff 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -62,13 +62,13 @@
 #define STRINGIFY(s) STRINGIFY_(s)
 #define STRINGIFY_(s) #s

-struct mime_node;
+typedef struct mime_node mime_node_t;
 struct notmuch_show_params;

 typedef struct notmuch_show_format {
 const char *message_set_start;
 void (*part) (const void *ctx,
- struct mime_node *node, int indent,
+ mime_node_t *node, int indent,
  const struct notmuch_show_params *params);
 const char *message_start;
 void (*message) (const void *ctx,
@@ -191,6 +191,12 @@ show_message_body (notmuch_message_t *message,
 notmuch_status_t
 show_one_part (const char *filename, int part);

+void
+format_part_json (const void *ctx, mime_node_t *node, notmuch_bool_t first);
+
+void
+format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t 
reply);
+
 char *
 json_quote_chararray (const void *ctx, const char *str, const size_t len);

@@ -288,7 +294,7 @@ debugger_is_active (void);
  * parts.  Message-type parts have one child, multipart-type parts
  * have multiple children, and leaf parts have zero children.
  */
-typedef struct mime_node {
+struct mime_node {
 /* The MIME object of this part.  This will be a GMimeMessage,
  * GMimePart, GMimeMultipart, or a subclass of one of these.
  *
@@ -351,7 +357,7 @@ typedef struct mime_node {
  * number to assign it (or -1 if unknown). */
 int next_child;
 int next_part_num;
-} mime_node_t;
+};

 /* Construct a new MIME node pointing to the root message part of
  * message.  If cryptoctx is non-NULL, it will be used to verify
diff --git a/notmuch-reply.c b/notmuch-reply.c
index f1478cc..e2b6c25 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -604,6 +604,51 @@ notmuch_reply_format_default(void *ctx,
 return 0;
 }

+static int
+notmuch_reply_format_json(void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all)
+{
+GMimeMessage *reply;
+notmuch_messages_t *messages;
+notmuch_message_t *message;
+mime_node_t *node;
+
+if (notmuch_query_count_messages (query) != 1) {
+   fprintf (stderr, "Error: search term did not match precisely one 
message.\n");
+   return 1;
+}
+
+messages = notmuch_query_search_messages (query);
+message = notmuch_messages_get (messages);
+if (mime_node_open (ctx, message, params->cryptoctx, params->decrypt,
+   ) != NOTMUCH_STATUS_SUCCESS)
+   return 1;
+
+reply = create_reply_message (ctx, config, message, reply_all);
+if (!reply)
+   return 1;
+
+/* The headers of the reply message we've created */
+printf ("{\"reply-headers\": ");
+format_headers_json (ctx, reply, TRUE);
+g_object_unref (G_OBJECT (reply));
+reply = NULL;
+
+/* Start the original */
+printf (", \"original\": ");
+
+format_part_json (ctx, node, TRUE);
+
+/* End */
+printf ("}\n");
+notmuch_message_destroy (message);
+
+return 0;
+}
+
 /* This format is currently tuned for a git send-email --notmuch hook */
 static int
 notmuch_reply_format_headers_only(void *ctx,
@@ -666,6 +711,7 @@ notmuch_reply_format_headers_only(void *ctx,

 enum {
 FORMAT_DEFAULT,
+FORMAT_JSON,
 FORMAT_HEADERS_ONLY,
 };

@@ -685,6 +731,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
 notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, , "format", 'f',
  (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
+ { "json", FORMAT_JSON },
  { "headers-only", FORMAT_HEADERS_ONLY },
  { 0, 0 } } },
{ NOTMUCH_OPT_KEYWORD, _all, "reply-to", 'r',
@@ -703,6 +750,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])

 if (format == FORMAT_HEADERS_ONLY)
reply_format_func = notmuch_reply_format_headers_only;
+else if (format == FORMAT_JSON)
+   reply_format_func = notmuch_reply_format_json;
 else
reply_format_func = notmuch_reply_format_default;

diff --git a/notmuch-show.c b/notmuch-show.c
index 05d51b2..cb3a427 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -291,8 

[PATCH v7 03/10] TODO: Add replying to multiple messages

2012-03-11 Thread Adam Wolfe Gordon
---
 devel/TODO |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/devel/TODO b/devel/TODO
index 4dda6f4..7b750af 100644
--- a/devel/TODO
+++ b/devel/TODO
@@ -141,6 +141,14 @@ Simplify notmuch-reply to simply print the headers (we 
have the
 original values) rather than calling GMime (which encodes) and adding
 the confusing gmime-filter-headers.c code (which decodes).

+Properly handle replying to multiple messages. Currently, the JSON
+reply format only supports a single message, but the default reply
+format accepts searches returning multiple messages. The expected
+behavior of replying to multiple messages is not obvious, and there
+are multiple ideas that might make sense. Some consensus needs to be
+reached on this issue, and then both reply formats should be updated
+to be consistent.
+
 notmuch library
 ---
 Add support for custom flag<->tag mappings. In the notmuch
-- 
1.7.5.4



[PATCH v7 02/10] reply: Factor out reply creation

2012-03-11 Thread Adam Wolfe Gordon
Factor out the creation of a reply message based on an original
message so it can be shared by different reply formats.
---
 notmuch-reply.c |  104 --
 1 files changed, 62 insertions(+), 42 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 6b244e6..f1478cc 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -505,6 +505,61 @@ guess_from_received_header (notmuch_config_t *config, 
notmuch_message_t *message
 return NULL;
 }

+static GMimeMessage *
+create_reply_message(void *ctx,
+notmuch_config_t *config,
+notmuch_message_t *message,
+notmuch_bool_t reply_all)
+{
+const char *subject, *from_addr = NULL;
+const char *in_reply_to, *orig_references, *references;
+
+/* The 1 means we want headers in a "pretty" order. */
+GMimeMessage *reply = g_mime_message_new (1);
+if (reply == NULL) {
+   fprintf (stderr, "Out of memory\n");
+   return NULL;
+}
+
+subject = notmuch_message_get_header (message, "subject");
+if (subject) {
+   if (strncasecmp (subject, "Re:", 3))
+   subject = talloc_asprintf (ctx, "Re: %s", subject);
+   g_mime_message_set_subject (reply, subject);
+}
+
+from_addr = add_recipients_from_message (reply, config,
+message, reply_all);
+
+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),
+from_addr);
+g_mime_object_set_header (GMIME_OBJECT (reply),
+ "From", from_addr);
+
+in_reply_to = talloc_asprintf (ctx, "<%s>",
+  notmuch_message_get_message_id (message));
+
+g_mime_object_set_header (GMIME_OBJECT (reply),
+ "In-Reply-To", in_reply_to);
+
+orig_references = notmuch_message_get_header (message, "references");
+references = talloc_asprintf (ctx, "%s%s%s",
+ orig_references ? orig_references : "",
+ orig_references ? " " : "",
+ in_reply_to);
+g_mime_object_set_header (GMIME_OBJECT (reply),
+ "References", references);
+
+return reply;
+}
+
 static int
 notmuch_reply_format_default(void *ctx,
 notmuch_config_t *config,
@@ -515,8 +570,6 @@ notmuch_reply_format_default(void *ctx,
 GMimeMessage *reply;
 notmuch_messages_t *messages;
 notmuch_message_t *message;
-const char *subject, *from_addr = NULL;
-const char *in_reply_to, *orig_references, *references;
 const notmuch_show_format_t *format = _reply;

 for (messages = notmuch_query_search_messages (query);
@@ -525,49 +578,16 @@ notmuch_reply_format_default(void *ctx,
 {
message = notmuch_messages_get (messages);

-   /* The 1 means we want headers in a "pretty" order. */
-   reply = g_mime_message_new (1);
-   if (reply == NULL) {
-   fprintf (stderr, "Out of memory\n");
-   return 1;
-   }
+   reply = create_reply_message (ctx, config, message, reply_all);

-   subject = notmuch_message_get_header (message, "subject");
-   if (subject) {
-   if (strncasecmp (subject, "Re:", 3))
-   subject = talloc_asprintf (ctx, "Re: %s", subject);
-   g_mime_message_set_subject (reply, subject);
+   /* If reply creation failed, we're out of memory, so don't
+* bother trying any more messages.
+*/
+   if (!reply) {
+   notmuch_message_destroy (message);
+   return 1;
}

-   from_addr = add_recipients_from_message (reply, config, message,
-reply_all);
-
-   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),
-from_addr);
-   g_mime_object_set_header (GMIME_OBJECT (reply),
- "From", from_addr);
-
-   in_reply_to = talloc_asprintf (ctx, "<%s>",
-notmuch_message_get_message_id (message));
-
-   g_mime_object_set_header (GMIME_OBJECT (reply),
- "In-Reply-To", in_reply_to);
-
-   orig_references = notmuch_message_get_header (message, "references");
-   references = talloc_asprintf (ctx, "%s%s%s",
- 

[PATCH v7 01/10] test: Add broken test for the new JSON reply format.

2012-03-11 Thread Adam Wolfe Gordon
---
 test/multipart |   53 +++
 test/test-lib  | 1242 
 2 files changed, 1295 insertions(+), 0 deletions(-)
 create mode 100755 test/test-lib

diff --git a/test/multipart b/test/multipart
index 53782c6..80d6e88 100755
--- a/test/multipart
+++ b/test/multipart
@@ -589,6 +589,59 @@ Non-text part: text/html
 EOF
 test_expect_equal_file OUTPUT EXPECTED

+test_begin_subtest "'notmuch reply' to a multipart message with json format"
+test_subtest_known_broken
+notmuch reply --format=json 'id:87liy5ap00.fsf at yoom.home.cworth.org' | 
notmuch_json_show_sanitize >OUTPUT
+cat ",
+ "References": " <87liy5ap00.fsf at yoom.home.cworth.org>"},
+ "original": {"id": "X",
+ "match": false,
+ "excluded": false,
+ "filename": "Y",
+ "timestamp": 978709437,
+ "date_relative": "2001-01-05",
+ "tags": ["attachment","inbox","signed","unread"],
+ "headers": {"Subject": "Multipart message",
+ "From": "Carl Worth ",
+ "To": "cworth at cworth.org",
+ "Date": "Fri,
+ 05 Jan 2001 15:43:57 +"},
+ "body": [{"id": 1,
+ "content-type": "multipart/signed",
+ "content": [{"id": 2,
+ "content-type": "multipart/mixed",
+ "content": [{"id": 3,
+ "content-type": "message/rfc822",
+ "content": [{"headers": {"Subject": "html message",
+ "From": "Carl Worth ",
+ "To": "cworth at cworth.org",
+ "Date": "Fri,
+ 05 Jan 2001 15:42:57 +"},
+ "body": [{"id": 4,
+ "content-type": "multipart/alternative",
+ "content": [{"id": 5,
+ "content-type": "text/html"},
+ {"id": 6,
+ "content-type": "text/plain",
+ "content": "This is an embedded message,
+ with a multipart/alternative part.\n"}]}]}]},
+ {"id": 7,
+ "content-type": "text/plain",
+ "filename": "Y",
+ "content": "This is a text attachment.\n"},
+ {"id": 8,
+ "content-type": "text/plain",
+ "content": "And this message is signed.\n\n-Carl\n"}]},
+ {"id": 9,
+ "content-type": "application/pgp-signature"}]}]}}
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
 test_begin_subtest "'notmuch show --part' does not corrupt a part with CRLF 
pair"
 notmuch show --format=raw --part=3 id:base64-part-with-crlf > crlf.out
 echo -n -e "\xEF\x0D\x0A" > crlf.expected
diff --git a/test/test-lib b/test/test-lib
new file mode 100755
index 000..8158328
--- /dev/null
+++ b/test/test-lib
@@ -0,0 +1,1242 @@
+#
+# 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 [ ${BASH_VERSINFO[0]} -lt 4 ]; then
+echo "Error: The notmuch test suite requires a bash version >= 4.0"
+echo "due to use of associative arrays within the test suite."
+echo "Please try again with a newer bash (or help us fix the"
+echo "test suite to be more portable). Thanks."
+exit 1
+fi
+
+# if --tee was passed, write the output not only to the terminal, but
+# additionally to the file test-results/$BASENAME.out, too.
+case "$GIT_TEST_TEE_STARTED, $* " in
+done,*)
+   # do not redirect again
+   ;;
+*' --tee '*|*' --va'*)
+   mkdir -p test-results
+   BASE=test-results/$(basename "$0" .sh)
+   (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
+echo $? > $BASE.exit) | tee $BASE.out
+   test "$(cat $BASE.exit)" = 0
+   exit
+   ;;
+esac
+
+# Keep the original TERM for say_color and test_emacs
+ORIGINAL_TERM=$TERM
+
+# For repeatability, reset the environment to known value.
+LANG=C
+LC_ALL=C
+PAGER=cat
+TZ=UTC
+TERM=dumb
+export LANG LC_ALL PAGER TERM TZ
+GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
+TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}}
+
+# Protect ourselves from common misconfiguration to export
+# CDPATH into the environment
+unset CDPATH
+
+unset GREP_OPTIONS
+
+# Convenience
+#
+# A regexp to match 5 and 40 hexdigits
+_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
+_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
+
+_x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
+_x32="$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04"
+
+# Each test should start with something like this, after copyright notices:
+#
+# test_description='Description of this test...
+# This test checks if command xyzzy does the right thing...
+# '
+# . ./test-lib.sh
+[ "x$ORIGINAL_TERM" != "xdumb" ] && (
+   TERM=$ORIGINAL_TERM &&
+ 

[PATCH v7 00/10] Reply enhancements

2012-03-11 Thread Adam Wolfe Gordon
Hi everyone,

This is a new version of my reply series [1] that addresses Jani's and
Austin's reviews and fixes a couple of bugs I found in using the patches.

Summary of the changes:

* The patch that disallows replying to multiple messages with the default
  format has been dropped, as Jani and Austin agreed that there's no
  reason this should be changed now. The JSON format sill only allows
  replying to a single message.

* The emacs reply code now shares code to get message content with show.
  This should mean better handling of character sets and other things.

* I noticed that reply supports a --decrypt option, and the emacs interface
  actually does use it. I've documented the option in the reply man page.
  If someone can test that replying to encrypted messages actually works in
  emacs, that would be great - I have no way to test this.

[1] id:"1329893199-21630-1-git-send-email-awg+notmuch at xvx.ca"

Adam Wolfe Gordon (10):
  test: Add broken test for the new JSON reply format.
  reply: Factor out reply creation
  TODO: Add replying to multiple messages
  reply: Add a JSON reply format.
  schemata: Add documentation for JSON reply format.
  man: Update notmuch-reply man page for JSON format.
  man: Add --decrypt to reply flags
  emacs: Factor out useful functions into notmuch-lib
  test: Add broken tests for new emacs reply functionality
  emacs: Use the new JSON reply format and message-cite-original

 devel/TODO   |8 +
 devel/schemata   |   27 +-
 emacs/notmuch-lib.el |   44 ++
 emacs/notmuch-mua.el |  136 --
 emacs/notmuch-show.el|   24 +-
 man/man1/notmuch-reply.1 |   18 +-
 notmuch-client.h |   14 +-
 notmuch-reply.c  |  153 --
 notmuch-show.c   |   29 +-
 test/emacs   |  101 -
 test/multipart   |   52 ++
 test/test-lib| 1242 ++
 12 files changed, 1726 insertions(+), 122 deletions(-)
 create mode 100755 test/test-lib

-- 
1.7.5.4



[PATCH 0/3] argument parsing additions

2012-03-11 Thread Jani Nikula
On Sat, 10 Mar 2012 11:23:15 +, Mark Walters  
wrote:
> On Sat, 10 Mar 2012 00:33:27 +0200, Jani Nikula  wrote:
> > Hi Mark -
> > 
> > I'm not sure which is worse, criticizing or rewriting other people's
> > patches. I already did the former, and now I'm doing the
> > latter. Apologies for both. I didn't really mean to write these patches,
> > but it turned out to be more fun writing a proper reply in C than in
> > English.
> > 
> > Patch 1 adds --arg=true and --arg=false support for booleans. It's not
> > strictly required for the --entire-thread support in patch 3, which uses
> > the extension of keyword arguments from patch 2, but it's for
> > consistency across boolean arguments.
> 
> Hi 
> 
> I like patch 1: I have an almost identical to my version (in the series
> I just sent to the list
> id:"1331377533-30262-1-git-send-email-markwalters1009 at gmail.com>
> X-Mailer: git-send-email 1.7.9.1"). 

id:"1331377533-30262-1-git-send-email-markwalters1009 at gmail.com" (fixed
reference)

Either of the patches should be pushed forward. The command line
interface is sound, in line with notmuch style, and allows boolean
parameters defaulting to true that you can switch off. And it needs no
changes to argument parser users.

> I am not sure about patch 2 and patch 3. Do you have a use case for
> --option except when option is a boolean?

For the sake of example, if some command produced some unformatted
output by default, you could enable some formatting with --format and
specify details with --format=foo or --format=bar. But admittedly it's a
bit contrived.

And using that for the bool case is also abusing it.

> Otherwise I think I prefer either my
> approach (abusing a notmuch_bool_t) or just adding an option
> NOTMUCH_OPT_BOOLEAN_AS_INT which does boolean parsing but returns an
> int. I guess I am saying that I think allowing boolean options which can
> sometimes default to true and sometimes to false is more useful than
> allowing --option for arbitrary keywords (*).
> 
> What do you think? 

I think we're somewhere between overengineering and bikeshedding, and we
should just fix the issue at hand with the "boolean" -1 value hack. Your
v2 series accomplishes what's needed. Let's go with it, and consider a
more general approach if another case comes up. (I actually wrote
patches to add generic support for getting info about which arguments
were set in the command line, but I think it's more trouble than its
worth.)


BR,
Jani.


> 
> Best wishes 
> 
> Mark
> 
> (*) Indeed, I was thinking of the former as a possibility for the
> exclude code, but I am erring towards just using keywords so I can allow
> more options as you suggested.
> 
> 
> > 
> > Please let me know what you think.
> > 
> > BR,
> > Jani.
> > 
> > 
> > Jani Nikula (3):
> >   command-line-arguments: allow true and false keywords for booleans
> >   command-line-arguments: support keyword arguments with default value
> >   cli: allow switching off entire thread mode in notmuch show json
> > format
> > 
> >  command-line-arguments.c |   45 
> > +++--
> >  command-line-arguments.h |1 +
> >  notmuch-show.c   |   12 ++--
> >  3 files changed, 50 insertions(+), 8 deletions(-)
> > 
> > -- 
> > 1.7.5.4
> > 


[PATCH v6] emacs: Use the new JSON reply format and message-cite-original

2012-03-11 Thread Austin Clements
Quoth Adam Wolfe Gordon on Feb 21 at 11:46 pm:
> Use the new JSON reply format to create replies in emacs. Quote HTML
> parts nicely by using mm-display-part to turn them into displayable
> text, then quoting them with message-cite-original. This is very
> useful for users who regularly receive HTML-only email.
> 
> Use message-mode's message-cite-original function to create the
> quoted body for reply messages. In order to make this act like the
> existing notmuch defaults, you will need to set the following in
> your emacs configuration:
> 
> message-citation-line-format "On %a, %d %b %Y, %f wrote:"
> message-citation-line-function 'message-insert-formatted-citation-line
> 
> The tests have been updated to reflect the (ugly) emacs default.
> ---
>  emacs/notmuch-lib.el |   11 
>  emacs/notmuch-mua.el |  136 ++---
>  test/emacs   |8 ++--
>  3 files changed, 109 insertions(+), 46 deletions(-)
> 
> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
> index 7e3f110..8bac596 100644
> --- a/emacs/notmuch-lib.el
> +++ b/emacs/notmuch-lib.el
> @@ -206,6 +206,17 @@ the user hasn't set this variable with the old or new 
> value."
> (setq seq (nconc (delete elem seq) (list elem))
>  seq))
>  
> +(defun notmuch-parts-filter-by-type (parts type)
> +  "Given a list of message parts, return a list containing the ones matching
> +the given type."
> +  (remove-if-not
> +   (lambda (part) (notmuch-match-content-type (plist-get part :content-type) 
> type))
> +   parts))
> +
> +(defun notmuch-plist-to-alist (plist)
> +  (loop for (key value . rest) on plist by #'cddr
> + collect (cons (substring (symbol-name key) 1) value)))
> +
>  ;; Compatibility functions for versions of emacs before emacs 23.
>  ;;
>  ;; Both functions here were copied from emacs 23 with the following 
> copyright:
> diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
> index 4be7c13..5adf4d8 100644
> --- a/emacs/notmuch-mua.el
> +++ b/emacs/notmuch-mua.el
> @@ -19,11 +19,15 @@
>  ;;
>  ;; Authors: David Edmondson 
>  
> +(require 'json)
>  (require 'message)
> +(require 'format-spec)
>  
>  (require 'notmuch-lib)
>  (require 'notmuch-address)
>  
> +(eval-when-compile (require 'cl))
> +
>  ;;
>  
>  (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
> @@ -72,56 +76,104 @@ list."
>   (push header message-hidden-headers)))
>   notmuch-mua-hidden-headers))
>  
> +(defun notmuch-mua-get-displayed-part (part query-string)
> +  (with-temp-buffer
> +(if (plist-get part :content)
> + (insert (plist-get part :content))
> +  (call-process notmuch-command nil t nil "show" "--format=raw"
> + (format "--part=%s" (plist-get part :id))
> + query-string))
> +
> +(let ((handle (mm-make-handle (current-buffer) (list (plist-get part 
> :content-type
> +   (end-of-orig (point-max)))
> +  (mm-display-part handle)
> +  (delete-region (point-min) end-of-orig)
> +  (buffer-substring (point-min) (point-max)

Even if it's not possible to completely reuse the show mechanisms
here, it would be nice to reuse the easy ones.  In particular,
notmuch-show-get-bodypart-content looks like it could easily be lifted
to the lib with the addition of a process-crypto argument.  It would
be slightly less efficient, but even now there's some important logic
in notmuch-show-get-bodypart-content that's missing here regarding
encoding handling.

> +
> +(defun notmuch-mua-get-quotable-parts (parts)
> +  (loop for part in parts
> + if (notmuch-match-content-type (plist-get part :content-type) 
> "multipart/alternative")
> +   collect (let* ((subparts (plist-get part :content))
> + (types (mapcar (lambda (part) (plist-get part 
> :content-type)) subparts))
> + (chosen-type (car (notmuch-multipart/alternative-choose 
> types
> +(loop for part in (reverse subparts)
> +  if (notmuch-match-content-type (plist-get part 
> :content-type) chosen-type)
> +  return part))
> + else if (notmuch-match-content-type (plist-get part :content-type) 
> "multipart/*")
> +   append (notmuch-mua-get-quotable-parts (plist-get part :content))
> + else if (notmuch-match-content-type (plist-get part :content-type) 
> "text/*")
> +   collect part))
> +
>  (defun notmuch-mua-reply (query-string  sender reply-all)
> -  (let (headers
> - body
> - (args '("reply")))
> -(if notmuch-show-process-crypto
> - (setq args (append args '("--decrypt"
> +  (let ((args '("reply" "--format=json"))
> + (json-object-type 'plist)
> + (json-array-type 'list)
> + (json-false 'nil)

These should be bound just around the setq reply below since they're
global controls (I highly doubt anything else this function calls
would invoke the JSON parser, but we shouldn't tempt dynamic scoping).

> + reply
> +  

[PATCH v4] test: emacs: new test "notmuch-search: change tags of all matching messages"

2012-03-11 Thread Tomi Ollila
On Wed,  7 Mar 2012 20:49:52 +0100, Pieter Praet  wrote:
> * test/emacs-search:
> 
>   - New subtest "notmuch-search: change tags of all matching messages":
> `notmuch-search-tag-all' (bound to "*") adds and removes tags
> to/from all messages which match the query used to populate the
> current search buffer.
> ---
> 
> Moved to a separate file to prevent a merge conflict when applied in
> conjunction with the patches listed @ id:"877gz4dnl2.fsf at praet.org".

Hi Pieter!

I did the following script:

--8<8<8<8<8<8<8<8<8<8<8<--

#!/bin/sh

while read line
do
case $line in id:*) notmuch show --format=mbox "$line"
esac
done < "$0" | git am 
exit 0

id:"1329684990-12504-2-git-send-email-pieter at praet.org"
id:"1329684990-12504-3-git-send-email-pieter at praet.org"
id:"1329684990-12504-4-git-send-email-pieter at praet.org"

id:"1330122640-18895-2-git-send-email-pieter at praet.org"
id:"1330122640-18895-3-git-send-email-pieter at praet.org"

id:"1331149792-17192-1-git-send-email-pieter at praet.org"

--8<8<8<8<8<8<8<8<8<8<8<--

When executed on top of current master (c46764030d, 0.11.1-1-293-gc467640)
last patch (1331149792-17192-1..., this I'm replying to) fails as:

error: patch failed: test/notmuch-test:54
error: test/notmuch-test: patch does not apply


In order to get clear picture of the changes you wish to get
reviewed please provide cleanly applicable patchset.

The best possible way to inform what is to be reviewed
is

1) List of message id:s of the patches, in order those
   are to be applied.

2) Sha1 of the commit where this patchset applies cleanly
   (In this case I will do review even though it would not
apply on top of current master (at that time) anymore --
but *I* would not expect it to to be pushed until rebased
patchset is sent again).

BR,

Tomi


[PATCH v6 06/10] schemata: Add documentation for JSON reply format.

2012-03-11 Thread Austin Clements
Oops.  Looks like I left references to various old JSON functions in
the schemata file.  I'll submit a patch to fix those up, but you might
as well use the correct function names in the new documentation.

Quoth Adam Wolfe Gordon on Feb 21 at 11:46 pm:
> ---
>  devel/schemata |   27 +--
>  1 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/devel/schemata b/devel/schemata
> index d90d4c6..ee8cfc0 100644
> --- a/devel/schemata
> +++ b/devel/schemata
> @@ -74,8 +74,9 @@ part = {
>  content?:   string# pre-fetched body content
>  }
>  
> -# The headers of a message (format_headers_json with raw headers) or
> -# a part (format_headers_message_part_json with pretty-printed headers)
> +# The headers of a message (format_headers_json with raw headers
> +# and reply = FALSE) or a part (format_headers_message_part_json
> +# with pretty-printed headers)

There's only format_headers_json now and it outputs pretty-printed
headers.

>  headers = {
>  Subject:string,
>  From:   string,
> @@ -133,3 +134,25 @@ thread = {
># matched and unmatched
>  subject:string
>  }
> +
> +notmuch reply schema
> +
> +
> +reply = {
> +# The headers of the constructed reply (format_headers_json with
> +# raw headers and reply = TRUE)
> +reply-headers: reply_headers,
> +
> +# As in the show format (format_message_json)

format_part_json

> +original: message
> +}
> +
> +reply_headers = {
> +Subject:string,
> +From:   string,
> +To?:string,
> +Cc?:string,
> +Bcc?:   string,
> +In-reply-to:string,
> +References: string
> +}


[PATCH v6 03/10] reply: Require that only one message is returned

2012-03-11 Thread Austin Clements
Quoth Jani Nikula on Mar 10 at  1:00 am:
> On Tue, 21 Feb 2012 23:46:32 -0700, Adam Wolfe Gordon  
> wrote:
> > As the semantics of replying to multiple messages have not yet been
> > defined well, make notmuch reply require that the search given returns
> > only a single message.
> 
> Is there any real reason, apart from consistency between
> --format=default and --format=json, to disable the current multiple
> message reply? Also "notmuch show" has format specific features and
> limitations.
> 
> I agree the semantics should be clarified, and eventually multiple
> message reply should be uniformly supported by all formats, including
> --format=json, but IMHO this patch should be dropped (and the TODO patch
> amended accordingly).

I agree with Jani.  We might as well leave the existing format as it
is and say in the TODO that we should both fix multiple reply and
support it in the JSON format.

> BR,
> Jani.


[PATCH v2 3/8] show: Allow formatters to return errors

2012-03-11 Thread Austin Clements
On Tue, 06 Mar 2012 21:22:55 +, Mark Walters  
wrote:
> On Tue,  6 Mar 2012 18:48:39 +, Austin Clements  
> wrote:
> > Formatter errors are propagated to the exit status of notmuch show.
> > 
> > This isn't used by the JSON or text formatters, but it will be useful
> > for the raw format, which is pickier.
> 
> I am not very familiar with this part of the code but the whole series
> looks fine to me.
> 
> My only minor comment is that I like Tom's suggestion (in
> id:"m2399qrtat.fsf at guru.guru-group.fi") of having NOTMUCH_STATUS_FAILURE
> (= 1) to make the error handling look cleaner. Alternatively (or

We could introduce a generic failure, though it couldn't be equal to 1
without breaking binary compatibility.  I'm not sure a generic failure
would make things much better, though; as far as I can tell, error
handling in C is doomed to ugliness.

> possibly as well) the functions do_show and do_show_messages could pass
> the actual error back up to notmuch_show_command and then that function
> could convert return 0/1 as appropriate.

I would be happy to be convinced either way.  It's the way it is because
I didn't bother changing it and because I think it's reasonable to think
of do_show and do_show_messages as extensions of notmuch_show_command.

> As usual I am quite happy to be overruled!
> 
> Best wishes
> 
> Mark
> 


nmfirehose - a crude nmbug companion tool

2012-03-11 Thread Jani Nikula

Hi all -

There was some talk on IRC about maintaining a development branch
containing the "maybe ready" patches [1] to better expose them to
real-life use before merging to master.

I set out to automate this a little, and ended up with nmfirehose. It's
a shell script that can be used to grab a bunch of patches from the
notmuch mail store based on queries, and apply them to a repository. In
particular, it can grab the "maybe ready" patches and apply them against
notmuch master.

Inevitable conflicts are handled by applying patches in oldest first
order, and dropping any conflicting series. An email thread approximates
a patch series; more than one patch series in a thread are folded into
one series.

Patches are applied incrementally, on top of each other by default, but
there's also support for non-incremental per-series apply against master
to see if there are conflicts. This is useful for the "review"
query. Conflicting patches can be automatically tagged if so desired
(but I don't recommend pushing these to nmbug without human review).

How well any of this works very much depends on how accurately the patch
messages are tagged.

Some examples (run within a notmuch git repo, with up-to-date nmbug tags
in the database):

# take nmbug maybe-ready patches and apply them against origin/master
$ nmfirehose

# use local branch firehose and force use it even if existing
$ nmfirehose -l firehose -F

# keep going after conflicts without reverting whole series
$ nmfirehose -k

# check each series in review queue against master, and tag conflicting
$ nmfirehose -q review -n -t

# help
$ nmfirehose -h

I originally planned on putting this to cron and pushing the result
(supported out-of-the-box) to some public repo, but in the end I think
people can use this locally just as well, at the pace they want.

The script tries not to screw up anything in your notmuch repo, but be
careful nonetheless.

Script attached; comments welcome. Is this worth adding to contrib?


BR,
Jani.

[1] http://nmbug.tethera.net/status/
-- next part --
A non-text attachment was scrubbed...
Name: nmfirehose
Type: application/octet-stream
Size: 5862 bytes
Desc: nmfirehose
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20120311/b0cf503f/attachment.obj>


Re: [PATCH v4] test: emacs: new test notmuch-search: change tags of all matching messages

2012-03-11 Thread Tomi Ollila
On Wed,  7 Mar 2012 20:49:52 +0100, Pieter Praet pie...@praet.org wrote:
 * test/emacs-search:
 
   - New subtest notmuch-search: change tags of all matching messages:
 `notmuch-search-tag-all' (bound to *) adds and removes tags
 to/from all messages which match the query used to populate the
 current search buffer.
 ---
 
 Moved to a separate file to prevent a merge conflict when applied in
 conjunction with the patches listed @ id:877gz4dnl2@praet.org.

Hi Pieter!

I did the following script:

--88888888888--

#!/bin/sh

while read line
do
case $line in id:*) notmuch show --format=mbox $line
esac
done  $0 | git am 
exit 0

id:1329684990-12504-2-git-send-email-pie...@praet.org
id:1329684990-12504-3-git-send-email-pie...@praet.org
id:1329684990-12504-4-git-send-email-pie...@praet.org

id:1330122640-18895-2-git-send-email-pie...@praet.org
id:1330122640-18895-3-git-send-email-pie...@praet.org

id:1331149792-17192-1-git-send-email-pie...@praet.org

--88888888888--

When executed on top of current master (c46764030d, 0.11.1-1-293-gc467640)
last patch (1331149792-17192-1..., this I'm replying to) fails as:

error: patch failed: test/notmuch-test:54
error: test/notmuch-test: patch does not apply


In order to get clear picture of the changes you wish to get
reviewed please provide cleanly applicable patchset.

The best possible way to inform what is to be reviewed
is

1) List of message id:s of the patches, in order those
   are to be applied.

2) Sha1 of the commit where this patchset applies cleanly
   (In this case I will do review even though it would not
apply on top of current master (at that time) anymore --
but *I* would not expect it to to be pushed until rebased
patchset is sent again).

BR,

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


Re: [PATCH 0/3] argument parsing additions

2012-03-11 Thread Jani Nikula
On Sat, 10 Mar 2012 11:23:15 +, Mark Walters markwalters1...@gmail.com 
wrote:
 On Sat, 10 Mar 2012 00:33:27 +0200, Jani Nikula j...@nikula.org wrote:
  Hi Mark -
  
  I'm not sure which is worse, criticizing or rewriting other people's
  patches. I already did the former, and now I'm doing the
  latter. Apologies for both. I didn't really mean to write these patches,
  but it turned out to be more fun writing a proper reply in C than in
  English.
  
  Patch 1 adds --arg=true and --arg=false support for booleans. It's not
  strictly required for the --entire-thread support in patch 3, which uses
  the extension of keyword arguments from patch 2, but it's for
  consistency across boolean arguments.
 
 Hi 
 
 I like patch 1: I have an almost identical to my version (in the series
 I just sent to the list
 id:1331377533-30262-1-git-send-email-markwalters1...@gmail.com
 X-Mailer: git-send-email 1.7.9.1). 

id:1331377533-30262-1-git-send-email-markwalters1...@gmail.com (fixed
reference)

Either of the patches should be pushed forward. The command line
interface is sound, in line with notmuch style, and allows boolean
parameters defaulting to true that you can switch off. And it needs no
changes to argument parser users.

 I am not sure about patch 2 and patch 3. Do you have a use case for
 --option except when option is a boolean?

For the sake of example, if some command produced some unformatted
output by default, you could enable some formatting with --format and
specify details with --format=foo or --format=bar. But admittedly it's a
bit contrived.

And using that for the bool case is also abusing it.

 Otherwise I think I prefer either my
 approach (abusing a notmuch_bool_t) or just adding an option
 NOTMUCH_OPT_BOOLEAN_AS_INT which does boolean parsing but returns an
 int. I guess I am saying that I think allowing boolean options which can
 sometimes default to true and sometimes to false is more useful than
 allowing --option for arbitrary keywords (*).
 
 What do you think? 

I think we're somewhere between overengineering and bikeshedding, and we
should just fix the issue at hand with the boolean -1 value hack. Your
v2 series accomplishes what's needed. Let's go with it, and consider a
more general approach if another case comes up. (I actually wrote
patches to add generic support for getting info about which arguments
were set in the command line, but I think it's more trouble than its
worth.)


BR,
Jani.


 
 Best wishes 
 
 Mark
 
 (*) Indeed, I was thinking of the former as a possibility for the
 exclude code, but I am erring towards just using keywords so I can allow
 more options as you suggested.
 
 
  
  Please let me know what you think.
  
  BR,
  Jani.
  
  
  Jani Nikula (3):
command-line-arguments: allow true and false keywords for booleans
command-line-arguments: support keyword arguments with default value
cli: allow switching off entire thread mode in notmuch show json
  format
  
   command-line-arguments.c |   45 
  +++--
   command-line-arguments.h |1 +
   notmuch-show.c   |   12 ++--
   3 files changed, 50 insertions(+), 8 deletions(-)
  
  -- 
  1.7.5.4
  
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] man: update SEE ALSO references in man pages

2012-03-11 Thread Jani Nikula
Drop references to notmuch-part(1). Reference all man pages. Fix man
page section of notmuch-dump(1).
---
 man/man1/notmuch-config.1   |5 ++---
 man/man1/notmuch-count.1|8 
 man/man1/notmuch-dump.1 |8 
 man/man1/notmuch-new.1  |8 
 man/man1/notmuch-reply.1|8 
 man/man1/notmuch-restore.1  |8 
 man/man1/notmuch-search.1   |8 
 man/man1/notmuch-show.1 |8 
 man/man1/notmuch-tag.1  |8 
 man/man1/notmuch.1  |7 +++
 man/man5/notmuch-hooks.5|8 
 man/man7/notmuch-search-terms.7 |5 ++---
 12 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/man/man1/notmuch-config.1 b/man/man1/notmuch-config.1
index e62577c..d22988a 100644
--- a/man/man1/notmuch-config.1
+++ b/man/man1/notmuch-config.1
@@ -137,9 +137,8 @@ Specifies the location of the notmuch configuration file. 
Notmuch will
 use ${HOME}/.notmuch\-config if this variable is not set.
 .SH SEE ALSO
 
-\fBnotmuch\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
-\fBnotmuch-part\fR(1), \fBnotmuch-reply\fR(1),
+\fBnotmuch\fR(1), \fBnotmuch-count\fR(1), \fBnotmuch-dump\fR(1),
+\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-reply\fR(1),
 \fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
 \fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
 \fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-count.1 b/man/man1/notmuch-count.1
index 805a8ae..f593065 100644
--- a/man/man1/notmuch-count.1
+++ b/man/man1/notmuch-count.1
@@ -51,7 +51,7 @@ Do not exclude the messages matching search.exclude_tags in 
the config file.
 .SH SEE ALSO
 
 \fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-dump\fR(1),
-\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-reply\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-dump.1 b/man/man1/notmuch-dump.1
index bd7e274..4e24392 100644
--- a/man/man1/notmuch-dump.1
+++ b/man/man1/notmuch-dump.1
@@ -31,7 +31,7 @@ for details of the supported syntax for search-terms.
 .SH SEE ALSO
 
 \fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-reply\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-new.1 b/man/man1/notmuch-new.1
index ccee738..19cef3d 100644
--- a/man/man1/notmuch-new.1
+++ b/man/man1/notmuch-new.1
@@ -64,7 +64,7 @@ Prevents hooks from being run.
 .SH SEE ALSO
 
 \fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-hooks\fR(5), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-reply\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-reply.1 b/man/man1/notmuch-reply.1
index 7ed7f0f..0fb68b4 100644
--- a/man/man1/notmuch-reply.1
+++ b/man/man1/notmuch-reply.1
@@ -80,7 +80,7 @@ on issue found in multiple patches.
 .SH SEE ALSO
 
 \fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-dump\fR(5), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
-\fBnotmuch-part\fR(1), \fBnotmuch-restore\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),
+\fBnotmuch-restore\fR(1), \fBnotmuch-search\fR(1),
+\fBnotmuch-search-terms\fR(7), \fBnotmuch-show\fR(1),
+\fBnotmuch-tag\fR(1)
diff --git a/man/man1/notmuch-restore.1 b/man/man1/notmuch-restore.1
index 8bd59e4..bcb765c 100644
--- a/man/man1/notmuch-restore.1
+++ b/man/man1/notmuch-restore.1
@@ -39,7 +39,7 @@ details.
 .SH SEE ALSO
 
 \fBnotmuch\fR(1), \fBnotmuch-config\fR(1), \fBnotmuch-count\fR(1),
-\fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1), \fBnotmuch-part\fR(1),
-\fBnotmuch-reply\fR(1), \fBnotmuch-dump\fR(1),
-\fBnotmuch-search\fR(1), \fBnotmuch-search-terms\fR(7),
-\fBnotmuch-show\fR(1), \fBnotmuch-tag\fR(1)
+\fBnotmuch-dump\fR(1), \fBnotmuch-hooks\fR(5), \fBnotmuch-new\fR(1),

Re: [PATCH v2 3/8] show: Allow formatters to return errors

2012-03-11 Thread Austin Clements
On Tue, 06 Mar 2012 21:22:55 +, Mark Walters markwalters1...@gmail.com 
wrote:
 On Tue,  6 Mar 2012 18:48:39 +, Austin Clements amdra...@mit.edu wrote:
  Formatter errors are propagated to the exit status of notmuch show.
  
  This isn't used by the JSON or text formatters, but it will be useful
  for the raw format, which is pickier.
 
 I am not very familiar with this part of the code but the whole series
 looks fine to me.
 
 My only minor comment is that I like Tom's suggestion (in
 id:m2399qrtat@guru.guru-group.fi) of having NOTMUCH_STATUS_FAILURE
 (= 1) to make the error handling look cleaner. Alternatively (or

We could introduce a generic failure, though it couldn't be equal to 1
without breaking binary compatibility.  I'm not sure a generic failure
would make things much better, though; as far as I can tell, error
handling in C is doomed to ugliness.

 possibly as well) the functions do_show and do_show_messages could pass
 the actual error back up to notmuch_show_command and then that function
 could convert return 0/1 as appropriate.

I would be happy to be convinced either way.  It's the way it is because
I didn't bother changing it and because I think it's reasonable to think
of do_show and do_show_messages as extensions of notmuch_show_command.

 As usual I am quite happy to be overruled!
 
 Best wishes
 
 Mark
 
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v6 03/10] reply: Require that only one message is returned

2012-03-11 Thread Austin Clements
Quoth Jani Nikula on Mar 10 at  1:00 am:
 On Tue, 21 Feb 2012 23:46:32 -0700, Adam Wolfe Gordon awg+notm...@xvx.ca 
 wrote:
  As the semantics of replying to multiple messages have not yet been
  defined well, make notmuch reply require that the search given returns
  only a single message.
 
 Is there any real reason, apart from consistency between
 --format=default and --format=json, to disable the current multiple
 message reply? Also notmuch show has format specific features and
 limitations.
 
 I agree the semantics should be clarified, and eventually multiple
 message reply should be uniformly supported by all formats, including
 --format=json, but IMHO this patch should be dropped (and the TODO patch
 amended accordingly).

I agree with Jani.  We might as well leave the existing format as it
is and say in the TODO that we should both fix multiple reply and
support it in the JSON format.

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


Re: [PATCH v6 06/10] schemata: Add documentation for JSON reply format.

2012-03-11 Thread Austin Clements
Oops.  Looks like I left references to various old JSON functions in
the schemata file.  I'll submit a patch to fix those up, but you might
as well use the correct function names in the new documentation.

Quoth Adam Wolfe Gordon on Feb 21 at 11:46 pm:
 ---
  devel/schemata |   27 +--
  1 files changed, 25 insertions(+), 2 deletions(-)
 
 diff --git a/devel/schemata b/devel/schemata
 index d90d4c6..ee8cfc0 100644
 --- a/devel/schemata
 +++ b/devel/schemata
 @@ -74,8 +74,9 @@ part = {
  content?:   string# pre-fetched body content
  }
  
 -# The headers of a message (format_headers_json with raw headers) or
 -# a part (format_headers_message_part_json with pretty-printed headers)
 +# The headers of a message (format_headers_json with raw headers
 +# and reply = FALSE) or a part (format_headers_message_part_json
 +# with pretty-printed headers)

There's only format_headers_json now and it outputs pretty-printed
headers.

  headers = {
  Subject:string,
  From:   string,
 @@ -133,3 +134,25 @@ thread = {
# matched and unmatched
  subject:string
  }
 +
 +notmuch reply schema
 +
 +
 +reply = {
 +# The headers of the constructed reply (format_headers_json with
 +# raw headers and reply = TRUE)
 +reply-headers: reply_headers,
 +
 +# As in the show format (format_message_json)

format_part_json

 +original: message
 +}
 +
 +reply_headers = {
 +Subject:string,
 +From:   string,
 +To?:string,
 +Cc?:string,
 +Bcc?:   string,
 +In-reply-to:string,
 +References: string
 +}
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH v6] emacs: Use the new JSON reply format and message-cite-original

2012-03-11 Thread Austin Clements
Quoth Adam Wolfe Gordon on Feb 21 at 11:46 pm:
 Use the new JSON reply format to create replies in emacs. Quote HTML
 parts nicely by using mm-display-part to turn them into displayable
 text, then quoting them with message-cite-original. This is very
 useful for users who regularly receive HTML-only email.
 
 Use message-mode's message-cite-original function to create the
 quoted body for reply messages. In order to make this act like the
 existing notmuch defaults, you will need to set the following in
 your emacs configuration:
 
 message-citation-line-format On %a, %d %b %Y, %f wrote:
 message-citation-line-function 'message-insert-formatted-citation-line
 
 The tests have been updated to reflect the (ugly) emacs default.
 ---
  emacs/notmuch-lib.el |   11 
  emacs/notmuch-mua.el |  136 ++---
  test/emacs   |8 ++--
  3 files changed, 109 insertions(+), 46 deletions(-)
 
 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
 index 7e3f110..8bac596 100644
 --- a/emacs/notmuch-lib.el
 +++ b/emacs/notmuch-lib.el
 @@ -206,6 +206,17 @@ the user hasn't set this variable with the old or new 
 value.
 (setq seq (nconc (delete elem seq) (list elem))
  seq))
  
 +(defun notmuch-parts-filter-by-type (parts type)
 +  Given a list of message parts, return a list containing the ones matching
 +the given type.
 +  (remove-if-not
 +   (lambda (part) (notmuch-match-content-type (plist-get part :content-type) 
 type))
 +   parts))
 +
 +(defun notmuch-plist-to-alist (plist)
 +  (loop for (key value . rest) on plist by #'cddr
 + collect (cons (substring (symbol-name key) 1) value)))
 +
  ;; Compatibility functions for versions of emacs before emacs 23.
  ;;
  ;; Both functions here were copied from emacs 23 with the following 
 copyright:
 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
 index 4be7c13..5adf4d8 100644
 --- a/emacs/notmuch-mua.el
 +++ b/emacs/notmuch-mua.el
 @@ -19,11 +19,15 @@
  ;;
  ;; Authors: David Edmondson d...@dme.org
  
 +(require 'json)
  (require 'message)
 +(require 'format-spec)
  
  (require 'notmuch-lib)
  (require 'notmuch-address)
  
 +(eval-when-compile (require 'cl))
 +
  ;;
  
  (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
 @@ -72,56 +76,104 @@ list.
   (push header message-hidden-headers)))
   notmuch-mua-hidden-headers))
  
 +(defun notmuch-mua-get-displayed-part (part query-string)
 +  (with-temp-buffer
 +(if (plist-get part :content)
 + (insert (plist-get part :content))
 +  (call-process notmuch-command nil t nil show --format=raw
 + (format --part=%s (plist-get part :id))
 + query-string))
 +
 +(let ((handle (mm-make-handle (current-buffer) (list (plist-get part 
 :content-type
 +   (end-of-orig (point-max)))
 +  (mm-display-part handle)
 +  (delete-region (point-min) end-of-orig)
 +  (buffer-substring (point-min) (point-max)

Even if it's not possible to completely reuse the show mechanisms
here, it would be nice to reuse the easy ones.  In particular,
notmuch-show-get-bodypart-content looks like it could easily be lifted
to the lib with the addition of a process-crypto argument.  It would
be slightly less efficient, but even now there's some important logic
in notmuch-show-get-bodypart-content that's missing here regarding
encoding handling.

 +
 +(defun notmuch-mua-get-quotable-parts (parts)
 +  (loop for part in parts
 + if (notmuch-match-content-type (plist-get part :content-type) 
 multipart/alternative)
 +   collect (let* ((subparts (plist-get part :content))
 + (types (mapcar (lambda (part) (plist-get part 
 :content-type)) subparts))
 + (chosen-type (car (notmuch-multipart/alternative-choose 
 types
 +(loop for part in (reverse subparts)
 +  if (notmuch-match-content-type (plist-get part 
 :content-type) chosen-type)
 +  return part))
 + else if (notmuch-match-content-type (plist-get part :content-type) 
 multipart/*)
 +   append (notmuch-mua-get-quotable-parts (plist-get part :content))
 + else if (notmuch-match-content-type (plist-get part :content-type) 
 text/*)
 +   collect part))
 +
  (defun notmuch-mua-reply (query-string optional sender reply-all)
 -  (let (headers
 - body
 - (args '(reply)))
 -(if notmuch-show-process-crypto
 - (setq args (append args '(--decrypt
 +  (let ((args '(reply --format=json))
 + (json-object-type 'plist)
 + (json-array-type 'list)
 + (json-false 'nil)

These should be bound just around the setq reply below since they're
global controls (I highly doubt anything else this function calls
would invoke the JSON parser, but we shouldn't tempt dynamic scoping).

 + reply
 + original)
 +(when notmuch-show-process-crypto
 +  (setq args (append args '(--decrypt
 +
  (if 

[PATCH] build: Require gmime = 2.6.7

2012-03-11 Thread David Bremner
From: Thomas Jost schno...@schnouki.net

gmime-2.6 had a bug [1] which made it impossible to tell why a signature
verification failed when the signer key was unavailable (empty sigstatus field
in the JSON output). Since 00b5623d the corresponding test is marked as broken
when using gmime-2.6 (2.4 is fine).

This bug has been fixed in gmime 2.6.5, which is now the minimal gmime-2.6
version required for building notmuch (gmime-2.4 is still available). As a
consequence the version check in test/crypto can be removed.

[Added by db]

Although less unambigously a bug, Gmime 2.6 prior to 2.6.7 also was
more strict about parsing, and rejected messages with initial From 
headers.  This restriction is relaxed in [2].  For reasons explained in [3],
we want to keep this more relaxed parsing for now.

[1] https://bugzilla.gnome.org/show_bug.cgi?id=668085

[2] 
http://git.gnome.org/browse/gmime/commit/?id=d311f576baf750476e06e9a1367a2dc1793ea7eb

[3] id:1331385931-1610-1-git-send-email-da...@tethera.net
---

As an alternative to applying [3], I could apply this modified version of
Thomas's patch. 


 configure   |4 +++-
 test/crypto |2 --
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index dedb7d8..ee0ae73 100755
--- a/configure
+++ b/configure
@@ -273,9 +273,11 @@ if [ ${have_xapian} = 0 ]; then
 errors=$((errors + 1))
 fi
 
+# If using GMime 2.6, we need to have a version = 2.6.5 to avoid a
+# crypto bug. We need 2.6.7 for permissive From  header handling.
 printf Checking for GMime development files... 
 have_gmime=0
-for gmimepc in gmime-2.6 gmime-2.4; do
+for gmimepc in 'gmime-2.6 = 2.6.7' gmime-2.4; do
 if pkg-config --exists $gmimepc; then
printf Yes ($gmimepc).\n
have_gmime=1
diff --git a/test/crypto b/test/crypto
index 1dbb60a..6723ef8 100755
--- a/test/crypto
+++ b/test/crypto
@@ -104,8 +104,6 @@ test_expect_equal \
 $expected
 
 test_begin_subtest signature verification with signer key unavailable
-# this is broken with current versions of gmime-2.6
-(ldd $(which notmuch) | grep -Fq gmime-2.6)  test_subtest_known_broken
 # move the gnupghome temporarily out of the way
 mv ${GNUPGHOME}{,.bak}
 output=$(notmuch show --format=json --verify subject:test signed message 001 
\
-- 
1.7.9.1

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


[PATCH v7 00/10] Reply enhancements

2012-03-11 Thread Adam Wolfe Gordon
Hi everyone,

This is a new version of my reply series [1] that addresses Jani's and
Austin's reviews and fixes a couple of bugs I found in using the patches.

Summary of the changes:

* The patch that disallows replying to multiple messages with the default
  format has been dropped, as Jani and Austin agreed that there's no
  reason this should be changed now. The JSON format sill only allows
  replying to a single message.

* The emacs reply code now shares code to get message content with show.
  This should mean better handling of character sets and other things.

* I noticed that reply supports a --decrypt option, and the emacs interface
  actually does use it. I've documented the option in the reply man page.
  If someone can test that replying to encrypted messages actually works in
  emacs, that would be great - I have no way to test this.

[1] id:1329893199-21630-1-git-send-email-awg+notm...@xvx.ca

Adam Wolfe Gordon (10):
  test: Add broken test for the new JSON reply format.
  reply: Factor out reply creation
  TODO: Add replying to multiple messages
  reply: Add a JSON reply format.
  schemata: Add documentation for JSON reply format.
  man: Update notmuch-reply man page for JSON format.
  man: Add --decrypt to reply flags
  emacs: Factor out useful functions into notmuch-lib
  test: Add broken tests for new emacs reply functionality
  emacs: Use the new JSON reply format and message-cite-original

 devel/TODO   |8 +
 devel/schemata   |   27 +-
 emacs/notmuch-lib.el |   44 ++
 emacs/notmuch-mua.el |  136 --
 emacs/notmuch-show.el|   24 +-
 man/man1/notmuch-reply.1 |   18 +-
 notmuch-client.h |   14 +-
 notmuch-reply.c  |  153 --
 notmuch-show.c   |   29 +-
 test/emacs   |  101 -
 test/multipart   |   52 ++
 test/test-lib| 1242 ++
 12 files changed, 1726 insertions(+), 122 deletions(-)
 create mode 100755 test/test-lib

-- 
1.7.5.4

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


[PATCH v7 01/10] test: Add broken test for the new JSON reply format.

2012-03-11 Thread Adam Wolfe Gordon
---
 test/multipart |   53 +++
 test/test-lib  | 1242 
 2 files changed, 1295 insertions(+), 0 deletions(-)
 create mode 100755 test/test-lib

diff --git a/test/multipart b/test/multipart
index 53782c6..80d6e88 100755
--- a/test/multipart
+++ b/test/multipart
@@ -589,6 +589,59 @@ Non-text part: text/html
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
+test_begin_subtest 'notmuch reply' to a multipart message with json format
+test_subtest_known_broken
+notmuch reply --format=json 'id:87liy5ap00@yoom.home.cworth.org' | 
notmuch_json_show_sanitize OUTPUT
+cat EOF EXPECTED
+{reply-headers: {Subject: Re: Multipart message,
+ From: Notmuch Test Suite test_su...@notmuchmail.org,
+ To: Carl Worth cwo...@cworth.org,
+ cwo...@cworth.org,
+ In-reply-to: 87liy5ap00@yoom.home.cworth.org,
+ References:  87liy5ap00@yoom.home.cworth.org},
+ original: {id: X,
+ match: false,
+ excluded: false,
+ filename: Y,
+ timestamp: 978709437,
+ date_relative: 2001-01-05,
+ tags: [attachment,inbox,signed,unread],
+ headers: {Subject: Multipart message,
+ From: Carl Worth cwo...@cworth.org,
+ To: cwo...@cworth.org,
+ Date: Fri,
+ 05 Jan 2001 15:43:57 +},
+ body: [{id: 1,
+ content-type: multipart/signed,
+ content: [{id: 2,
+ content-type: multipart/mixed,
+ content: [{id: 3,
+ content-type: message/rfc822,
+ content: [{headers: {Subject: html message,
+ From: Carl Worth cwo...@cworth.org,
+ To: cwo...@cworth.org,
+ Date: Fri,
+ 05 Jan 2001 15:42:57 +},
+ body: [{id: 4,
+ content-type: multipart/alternative,
+ content: [{id: 5,
+ content-type: text/html},
+ {id: 6,
+ content-type: text/plain,
+ content: This is an embedded message,
+ with a multipart/alternative part.\n}]}]}]},
+ {id: 7,
+ content-type: text/plain,
+ filename: Y,
+ content: This is a text attachment.\n},
+ {id: 8,
+ content-type: text/plain,
+ content: And this message is signed.\n\n-Carl\n}]},
+ {id: 9,
+ content-type: application/pgp-signature}]}]}}
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
 test_begin_subtest 'notmuch show --part' does not corrupt a part with CRLF 
pair
 notmuch show --format=raw --part=3 id:base64-part-with-crlf  crlf.out
 echo -n -e \xEF\x0D\x0A  crlf.expected
diff --git a/test/test-lib b/test/test-lib
new file mode 100755
index 000..8158328
--- /dev/null
+++ b/test/test-lib
@@ -0,0 +1,1242 @@
+#
+# 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 [ ${BASH_VERSINFO[0]} -lt 4 ]; then
+echo Error: The notmuch test suite requires a bash version = 4.0
+echo due to use of associative arrays within the test suite.
+echo Please try again with a newer bash (or help us fix the
+echo test suite to be more portable). Thanks.
+exit 1
+fi
+
+# if --tee was passed, write the output not only to the terminal, but
+# additionally to the file test-results/$BASENAME.out, too.
+case $GIT_TEST_TEE_STARTED, $*  in
+done,*)
+   # do not redirect again
+   ;;
+*' --tee '*|*' --va'*)
+   mkdir -p test-results
+   BASE=test-results/$(basename $0 .sh)
+   (GIT_TEST_TEE_STARTED=done ${SHELL-sh} $0 $@ 21;
+echo $?  $BASE.exit) | tee $BASE.out
+   test $(cat $BASE.exit) = 0
+   exit
+   ;;
+esac
+
+# Keep the original TERM for say_color and test_emacs
+ORIGINAL_TERM=$TERM
+
+# For repeatability, reset the environment to known value.
+LANG=C
+LC_ALL=C
+PAGER=cat
+TZ=UTC
+TERM=dumb
+export LANG LC_ALL PAGER TERM TZ
+GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u}
+TEST_EMACS=${TEST_EMACS:-${EMACS:-emacs}}
+
+# Protect ourselves from common misconfiguration to export
+# CDPATH into the environment
+unset CDPATH
+
+unset GREP_OPTIONS
+
+# Convenience
+#
+# A regexp to match 5 and 40 hexdigits
+_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
+_x40=$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05
+
+_x04='[0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
+_x32=$_x04$_x04$_x04$_x04$_x04$_x04$_x04$_x04
+
+# Each test should start with something like this, after copyright notices:
+#
+# test_description='Description of this test...
+# This test checks if command xyzzy does the right thing...
+# '
+# . ./test-lib.sh
+[ x$ORIGINAL_TERM != xdumb ]  (
+   TERM=$ORIGINAL_TERM 
+   export TERM 
+   [ -t 1 ] 
+   tput bold /dev/null 21 
+   tput setaf 1 /dev/null 21 
+   

[PATCH v7 03/10] TODO: Add replying to multiple messages

2012-03-11 Thread Adam Wolfe Gordon
---
 devel/TODO |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/devel/TODO b/devel/TODO
index 4dda6f4..7b750af 100644
--- a/devel/TODO
+++ b/devel/TODO
@@ -141,6 +141,14 @@ Simplify notmuch-reply to simply print the headers (we 
have the
 original values) rather than calling GMime (which encodes) and adding
 the confusing gmime-filter-headers.c code (which decodes).
 
+Properly handle replying to multiple messages. Currently, the JSON
+reply format only supports a single message, but the default reply
+format accepts searches returning multiple messages. The expected
+behavior of replying to multiple messages is not obvious, and there
+are multiple ideas that might make sense. Some consensus needs to be
+reached on this issue, and then both reply formats should be updated
+to be consistent.
+
 notmuch library
 ---
 Add support for custom flag-tag mappings. In the notmuch
-- 
1.7.5.4

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


[PATCH v7 05/10] schemata: Add documentation for JSON reply format.

2012-03-11 Thread Adam Wolfe Gordon
---
 devel/schemata |   27 +--
 1 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/devel/schemata b/devel/schemata
index 24ad775..b1073a9 100644
--- a/devel/schemata
+++ b/devel/schemata
@@ -77,8 +77,9 @@ part = {
 content?:   string
 }
 
-# The headers of a message (format_headers_json with raw headers) or
-# a part (format_headers_message_part_json with pretty-printed headers)
+# The headers of a message (format_headers_json with raw headers
+# and reply = FALSE) or a part (format_headers_message_part_json
+# with pretty-printed headers)
 headers = {
 Subject:string,
 From:   string,
@@ -136,3 +137,25 @@ thread = {
   # matched and unmatched
 subject:string
 }
+
+notmuch reply schema
+
+
+reply = {
+# The headers of the constructed reply (format_headers_json with
+# raw headers and reply = TRUE)
+reply-headers: reply_headers,
+
+# As in the show format (format_message_json)
+original: message
+}
+
+reply_headers = {
+Subject:string,
+From:   string,
+To?:string,
+Cc?:string,
+Bcc?:   string,
+In-reply-to:string,
+References: string
+}
-- 
1.7.5.4

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


[PATCH v7 06/10] man: Update notmuch-reply man page for JSON format.

2012-03-11 Thread Adam Wolfe Gordon
---
 man/man1/notmuch-reply.1 |   10 --
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/man/man1/notmuch-reply.1 b/man/man1/notmuch-reply.1
index 7ed7f0f..debc505 100644
--- a/man/man1/notmuch-reply.1
+++ b/man/man1/notmuch-reply.1
@@ -37,12 +37,17 @@ Supported options for
 include
 .RS
 .TP 4
-.BR \-\-format= ( default | headers\-only )
+.BR \-\-format= ( default | json | headers\-only )
 .RS
 .TP 4
 .BR default
 Includes subject and quoted message body.
 .TP
+.BR json
+Produces JSON output containing headers for a reply message and the
+contents of the original message. This output can be used by a client
+to create a reply message intelligently.
+.TP
 .BR headers\-only
 Only produces In\-Reply\-To, References, To, Cc, and Bcc headers.
 .RE
@@ -73,7 +78,8 @@ with a search string matching a single message, (such as
 id:message-id), but it can be useful to reply to several messages at
 once. For example, when a series of patches are sent in a single
 thread, replying to the entire thread allows for the reply to comment
-on issue found in multiple patches.
+on issues found in multiple patches. The default format supports
+replying to multiple messages at once, but the JSON format does not.
 .RE
 .RE
 
-- 
1.7.5.4

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


[PATCH v7 09/10] test: Add broken tests for new emacs reply functionality

2012-03-11 Thread Adam Wolfe Gordon
Add tests for creating nice replies to multipart messages, including
those with HTML parts. These tests are expected to fail for now.
---
 test/emacs |   97 
 1 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/test/emacs b/test/emacs
index 29a489c..01afdb6 100755
--- a/test/emacs
+++ b/test/emacs
@@ -273,6 +273,103 @@ On 01 Jan 2000 12:00:00 -, Notmuch Test Suite 
test_su...@notmuchmail.org w
 EOF
 test_expect_equal_file OUTPUT EXPECTED
 
+test_begin_subtest Reply within emacs to a multipart/mixed message
+test_subtest_known_broken
+test_emacs '(notmuch-show id:20091118002059.067214ed@hikari)
+   (notmuch-show-reply)
+   (test-output)'
+cat EOF EXPECTED
+From: Notmuch Test Suite test_su...@notmuchmail.org
+To: Adrian Perez de Castro ape...@igalia.com, notmuch@notmuchmail.org
+Subject: Re: [notmuch] Introducing myself
+In-Reply-To: 20091118002059.067214ed@hikari
+Fcc: ${MAIL_DIR}/sent
+--text follows this line--
+Adrian Perez de Castro ape...@igalia.com writes:
+
+ Hello to all,
+
+ I have just heard about Not Much today in some random Linux-related news
+ site (LWN?), my name is Adrian Perez and I work as systems administrator
+ (although I can do some code as well :P). I have always thought that the
+ ideas behind Sup were great, but after some time using it, I got tired of
+ the oddities that it has. I also do not like doing things like having to
+ install Ruby just for reading and sorting mails. Some time ago I thought
+ about doing something like Not Much and in fact I played a bit with the
+ Python+Xapian and the Python+Whoosh combinations, because I find relaxing
+ to code things in Python when I am not working and also it is installed
+ by default on most distribution. I got to have some mailboxes indexed and
+ basic searching working a couple of months ago. Lately I have been very
+ busy and had no time for coding, and them... boom! Not Much appears -- and
+ it is almost exactly what I was trying to do, but faster. I have been
+ playing a bit with Not Much today, and I think it has potential.
+
+ Also, I would like to share one idea I had in mind, that you might find
+ interesting: One thing I have found very annoying is having to re-tag my
+ mail when the indexes get b0rked (it happened a couple of times to me while
+ using Sup), so I was planning to mails as read/unread and adding the tags
+ not just to the index, but to the mail text itself, e.g. by adding a
+ X-Tags header field or by reusing the Keywords one. This way, the index
+ could be totally recreated by re-reading the mail directories, and this
+ would also allow to a tools like OfflineIMAP [1] to get the mails into a
+ local maildir, tagging and indexing the mails with the e-mail reader and
+ then syncing back the messages with the X-Tags header to the IMAP server.
+ This would allow to use the mail reader from a different computer and still
+ have everything tagged finely.
+
+ Best regards,
+
+
+ ---
+ [1] http://software.complete.org/software/projects/show/offlineimap
+
+ -- 
+ Adrian Perez de Castro ape...@igalia.com
+ Igalia - Free Software Engineering
+ ___
+ notmuch mailing list
+ notmuch@notmuchmail.org
+ http://notmuchmail.org/mailman/listinfo/notmuch
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
+test_begin_subtest Reply within emacs to a multipart/alternative message
+test_subtest_known_broken
+test_emacs '(notmuch-show 
id:cf0c4d610911171136h1713aa59w9cf9aa31f052a...@mail.gmail.com)
+   (notmuch-show-reply)
+   (test-output)'
+cat EOF EXPECTED
+From: Notmuch Test Suite test_su...@notmuchmail.org
+To: Alex Botero-Lowry alex.boterolo...@gmail.com, notmuch@notmuchmail.org
+Subject: Re: [notmuch] preliminary FreeBSD support
+In-Reply-To: cf0c4d610911171136h1713aa59w9cf9aa31f052a...@mail.gmail.com
+Fcc: ${MAIL_DIR}/sent
+--text follows this line--
+Alex Botero-Lowry alex.boterolo...@gmail.com writes:
+
+ I saw the announcement this morning, and was very excited, as I had been
+ hoping sup would be turned into a library,
+ since I like the concept more than the UI (I'd rather an emacs interface).
+
+ I did a preliminary compile which worked out fine, but
+ sysconf(_SC_SC_GETPW_R_SIZE_MAX) returns -1 on
+ FreeBSD, so notmuch_config_open segfaulted.
+
+ Attached is a patch that supplies a default buffer size of 64 in cases where
+ -1 is returned.
+
+ http://www.opengroup.org/austin/docs/austin_328.txt - seems to indicate this
+ is acceptable behavior,
+ and 
http://mail-index.netbsd.org/pkgsrc-bugs/2006/06/07/msg016808.htmlspecifically
+ uses 64 as the
+ buffer size.
+ ___
+ notmuch mailing list
+ notmuch@notmuchmail.org
+ http://notmuchmail.org/mailman/listinfo/notmuch
+EOF
+test_expect_equal_file OUTPUT EXPECTED
+
 test_begin_subtest Quote MML tags in reply
 message_id='test-emacs-mml-quot...@message.id'
 add_message 

[PATCH v7 10/10] emacs: Use the new JSON reply format and message-cite-original

2012-03-11 Thread Adam Wolfe Gordon
Use the new JSON reply format to create replies in emacs. Quote HTML
parts nicely by using mm-display-part to turn them into displayable
text, then quoting them with message-cite-original. This is very
useful for users who regularly receive HTML-only email.

Use message-mode's message-cite-original function to create the
quoted body for reply messages. In order to make this act like the
existing notmuch defaults, you will need to set the following in
your emacs configuration:

message-citation-line-format On %a, %d %b %Y, %f wrote:
message-citation-line-function 'message-insert-formatted-citation-line

The tests have been updated to reflect the (ugly) emacs default.
---
 emacs/notmuch-lib.el |   11 
 emacs/notmuch-mua.el |  136 +++---
 test/emacs   |8 ++--
 3 files changed, 110 insertions(+), 45 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 7e3f110..8bac596 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -206,6 +206,17 @@ the user hasn't set this variable with the old or new 
value.
  (setq seq (nconc (delete elem seq) (list elem))
 seq))
 
+(defun notmuch-parts-filter-by-type (parts type)
+  Given a list of message parts, return a list containing the ones matching
+the given type.
+  (remove-if-not
+   (lambda (part) (notmuch-match-content-type (plist-get part :content-type) 
type))
+   parts))
+
+(defun notmuch-plist-to-alist (plist)
+  (loop for (key value . rest) on plist by #'cddr
+   collect (cons (substring (symbol-name key) 1) value)))
+
 ;; Compatibility functions for versions of emacs before emacs 23.
 ;;
 ;; Both functions here were copied from emacs 23 with the following copyright:
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 13244eb..5adf4d8 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -19,11 +19,15 @@
 ;;
 ;; Authors: David Edmondson d...@dme.org
 
+(require 'json)
 (require 'message)
+(require 'format-spec)
 
 (require 'notmuch-lib)
 (require 'notmuch-address)
 
+(eval-when-compile (require 'cl))
+
 ;;
 
 (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)
@@ -72,54 +76,104 @@ list.
(push header message-hidden-headers)))
notmuch-mua-hidden-headers))
 
+(defun notmuch-mua-get-displayed-part (part query-string)
+  (with-temp-buffer
+(if (plist-get part :content)
+   (insert (plist-get part :content))
+  (call-process notmuch-command nil t nil show --format=raw
+   (format --part=%s (plist-get part :id))
+   query-string))
+
+(let ((handle (mm-make-handle (current-buffer) (list (plist-get part 
:content-type
+ (end-of-orig (point-max)))
+  (mm-display-part handle)
+  (delete-region (point-min) end-of-orig)
+  (buffer-substring (point-min) (point-max)
+
+(defun notmuch-mua-get-quotable-parts (parts)
+  (loop for part in parts
+   if (notmuch-match-content-type (plist-get part :content-type) 
multipart/alternative)
+ collect (let* ((subparts (plist-get part :content))
+   (types (mapcar (lambda (part) (plist-get part 
:content-type)) subparts))
+   (chosen-type (car (notmuch-multipart/alternative-choose 
types
+  (loop for part in (reverse subparts)
+if (notmuch-match-content-type (plist-get part 
:content-type) chosen-type)
+return part))
+   else if (notmuch-match-content-type (plist-get part :content-type) 
multipart/*)
+ append (notmuch-mua-get-quotable-parts (plist-get part :content))
+   else if (notmuch-match-content-type (plist-get part :content-type) 
text/*)
+ collect part))
+
 (defun notmuch-mua-reply (query-string optional sender reply-all)
-  (let (headers
-   body
-   (args '(reply)))
-(if notmuch-show-process-crypto
-   (setq args (append args '(--decrypt
+  (let ((args '(reply --format=json))
+   (json-object-type 'plist)
+   (json-array-type 'list)
+   (json-false 'nil)
+   reply
+   original)
+(when notmuch-show-process-crypto
+  (setq args (append args '(--decrypt
+
 (if reply-all
(setq args (append args '(--reply-to=all)))
   (setq args (append args '(--reply-to=sender
 (setq args (append args (list query-string)))
-;; This make assumptions about the output of `notmuch reply', but
-;; really only that the headers come first followed by a blank
-;; line and then the body.
+
+;; Get the reply object as JSON, and parse it into an elisp object.
 (with-temp-buffer
   (apply 'call-process (append (list notmuch-command nil (list t t) nil) 
args))
   (goto-char (point-min))
-  (if (re-search-forward ^$ nil t)
- (save-excursion
-   (save-restriction
- (narrow-to-region (point-min) (point))
- (goto-char (point-min))
- 

Re: [PATCH v6 06/10] schemata: Add documentation for JSON reply format.

2012-03-11 Thread Adam Wolfe Gordon
On Sun, Mar 11, 2012 at 18:36, Austin Clements amdra...@mit.edu wrote:
 Oops.  Looks like I left references to various old JSON functions in
 the schemata file.  I'll submit a patch to fix those up, but you might
 as well use the correct function names in the new documentation.

Erk, I missed this review as I was making up the latest version of the
series. I guess I'll have to send another, but I'll wait for reviews
on the other patches first.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch