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

2012-03-13 Thread Austin Clements
Quoth Adam Wolfe Gordon on Mar 11 at 10:05 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.

Hmm.  This patch looks the same as in v6, but your cover letter says
that you changed some things.


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

2012-03-13 Thread Adam Wolfe Gordon
On Tue, Mar 13, 2012 at 11:02, Austin Clements  wrote:
> Hmm. ?This patch looks the same as in v6, but your cover letter says
> that you changed some things.

Damn, indeed. Looks like I rebased the changes into the wrong commit,
so they weren't included in this series.

Might be best to ignore this version of the series - I'll get this
figured out tonight and send a new version.


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

2012-03-13 Thread Austin Clements
Quoth Adam Wolfe Gordon on Mar 11 at 10:05 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.

Hmm.  This patch looks the same as in v6, but your cover letter says
that you changed some things.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2012-03-13 Thread Adam Wolfe Gordon
On Tue, Mar 13, 2012 at 11:02, Austin Clements amdra...@mit.edu wrote:
 Hmm.  This patch looks the same as in v6, but your cover letter says
 that you changed some things.

Damn, indeed. Looks like I rebased the changes into the wrong commit,
so they weren't included in this series.

Might be best to ignore this version of the series - I'll get this
figured out tonight and send a new version.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[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 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))
-