Re: [PATCH 4/4] emacs: Use the new JSON reply format.
authorDavid Edmondson <dme@dme.org>
Mon, 9 Jan 2012 08:50:00 +0000 (08:50 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:49 +0000 (09:41 -0800)
cf/27e317c77818ad59edf225bc31544b80d426d8 [new file with mode: 0644]

diff --git a/cf/27e317c77818ad59edf225bc31544b80d426d8 b/cf/27e317c77818ad59edf225bc31544b80d426d8
new file mode 100644 (file)
index 0000000..9327269
--- /dev/null
@@ -0,0 +1,180 @@
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1F02A431FD0\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Jan 2012 00:50:09 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id E5xuDGSkQFYc for <notmuch@notmuchmail.org>;\r
+       Mon,  9 Jan 2012 00:50:08 -0800 (PST)\r
+Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
+ [74.125.82.45])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 35DDE431FB6   for <notmuch@notmuchmail.org>; Mon,  9 Jan 2012 00:50:08 -0800\r
+ (PST)\r
+Received: by wgbds11 with SMTP id ds11so1220104wgb.2\r
+       for <notmuch@notmuchmail.org>; Mon, 09 Jan 2012 00:50:07 -0800 (PST)\r
+Received: by 10.180.96.7 with SMTP id do7mr3134120wib.16.1326099006980;\r
+       Mon, 09 Jan 2012 00:50:06 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+       (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+       by mx.google.com with ESMTPS id hv1sm5489465wib.1.2012.01.09.00.50.05\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 09 Jan 2012 00:50:05 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id CDEA1A346A; Mon,  9 Jan 2012 08:50:03 +0000 (GMT)\r
+To: Adam Wolfe Gordon <awg+notmuch@xvx.ca>, notmuch@notmuchmail.org,\r
+ awg@xvx.ca\r
+Subject: Re: [PATCH 4/4] emacs: Use the new JSON reply format.\r
+In-Reply-To: <1326009162-19524-5-git-send-email-awg+notmuch@xvx.ca>\r
+References: <1326009162-19524-1-git-send-email-awg+notmuch@xvx.ca>\r
+       <1326009162-19524-5-git-send-email-awg+notmuch@xvx.ca>\r
+User-Agent: Notmuch/0.10.2+151~gbf1dc2b (http://notmuchmail.org)\r
+       Emacs/24.0.92.1 (x86_64-pc-linux-gnu)\r
+From: David Edmondson <dme@dme.org>\r
+Date: Mon, 09 Jan 2012 08:50:00 +0000\r
+Message-ID: <cun62gl1cqv.fsf@hotblack-desiato.hh.sledj.net>\r
+MIME-Version: 1.0\r
+Content-Type: multipart/signed; boundary="=-=-=";\r
+       micalg=pgp-sha1; protocol="application/pgp-signature"\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 09 Jan 2012 08:50:09 -0000\r
+\r
+--=-=-=\r
+Content-Type: text/plain\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+On Sun,  8 Jan 2012 00:52:42 -0700, Adam Wolfe Gordon <awg+notmuch@xvx.ca> =\r
+wrote:\r
+> +(defun w3m-region (start end)) ;; From `w3m.el'.\r
+> +(defun notmuch-mua-quote-part (part)\r
+> +  (with-temp-buffer\r
+> +    (insert part)\r
+> +    (message-mode)\r
+> +    (fill-region (point-min) (point-max))\r
+> +    (goto-char (point-min))\r
+> +    (perform-replace "^" "> " nil t nil)\r
+> +    (set-buffer-modified-p nil)\r
+> +    (buffer-substring (point-min) (point-max))))\r
+\r
+Couldn't all of this be done directly in the reply buffer?\r
+\r
+> +(defun notmuch-mua-parse-html-part (part)\r
+> +  (with-temp-buffer\r
+> +    (insert part)\r
+> +    (w3m-region (point-min) (point-max))\r
+> +    (set-buffer-modified-p nil)\r
+> +    (buffer-substring (point-min) (point-max))))\r
+\r
+Blank lines between functions are the house style (as much as there is\r
+such a thing).\r
+\r
+Using w3m means that you should `require' it. What happens when a user\r
+doesn't have it? (Either the elisp or the command.)\r
+\r
+>  (defun notmuch-mua-reply (query-string &optional sender)\r
+> -  (let (headers\r
+> +  (let (reply\r
+> +    original\r
+> +    headers\r
+>      body\r
+> -    (args '("reply")))\r
+> +    (args '("reply" "--format=3Djson")))\r
+\r
+Initialised variables are generally shown before uninitialised. I know\r
+that you didn't do this 'wrong' and that it's an unrelated change, but\r
+it should be fixed. (To the people who say that should be a separate\r
+patch I say 'meh' - life is too short.)\r
+\r
+>      (if notmuch-show-process-crypto\r
+>      (setq args (append args '("--decrypt"))))\r
+>      (setq args (append args (list query-string)))\r
+> -    ;; This make assumptions about the output of `notmuch reply', but\r
+> -    ;; really only that the headers come first followed by a blank\r
+> -    ;; line and then the body.\r
+> +    ;; Get the reply object as JSON, and parse it into an elisp object.\r
+>      (with-temp-buffer\r
+>        (apply 'call-process (append (list notmuch-command nil (list t t) =\r
+nil) args))\r
+>        (goto-char (point-min))\r
+> -      (if (re-search-forward "^$" nil t)\r
+> -      (save-excursion\r
+> -        (save-restriction\r
+> -          (narrow-to-region (point-min) (point))\r
+> -          (goto-char (point-min))\r
+> -          (setq headers (mail-header-extract)))))\r
+> -      (forward-line 1)\r
+> -      (setq body (buffer-substring (point) (point-max))))\r
+> +      (setq reply (aref (json-read) 0)))\r
+> +\r
+> +    ;; Get the list of headers\r
+> +    (setq headers (cdr (assq 'headers (assq 'reply reply))))\r
+> +    ;; Construct the body of the reply.\r
+> +    (setq original (cdr (assq 'original reply)))\r
+\r
+The scope of (at least) `headers' and `original' could be tightened by\r
+moving them down to the following `let' (and converting it to `let*').\r
+\r
+> +\r
+> +    ;; Start with the prelude, based on the headers of the original mess=\r
+age.\r
+> +    (let ((original-headers (cdr (assq 'headers original))))\r
+> +      (setq body (format "On %s, %s wrote:\n"\r
+> +                     (cdr (assq 'date original-headers))\r
+> +                     (cdr (assq 'from original-headers)))))\r
+> +\r
+> +    ;; Extract the body parts and construct a reasonable quoted body.\r
+> +    (let* ((body-parts (cdr (assq 'body original)))\r
+> +       (find-parts (lambda (type) (delq nil (mapcar (lambda (part)\r
+> +                                                      (if (string=3D (cdr (assq 'content-type part)) type)\r
+> +                                                          (cdr (assq 'content part))))\r
+> +                                                    body-parts))))\r
+\r
+`find-parts' might be useful in other places. Maybe add it to notmuch-lib.e=\r
+l?\r
+\r
+> +       (plain-parts (apply find-parts '("text/plain")))\r
+> +       (html-parts (apply find-parts '("text/html"))))\r
+> +=20=20=20=20=20=20\r
+> +      (if (not (null plain-parts))\r
+> +      (mapc (lambda (part) (setq body (concat body (notmuch-mua-quote-part =\r
+part)))) plain-parts)\r
+> +    (mapc (lambda (part) (setq body (concat body (notmuch-mua-quote-part (n=\r
+otmuch-mua-parse-html-part part))))) html-parts)))\r
+\r
+If you have an 'else' clause, why test '(if (not ..' ?\r
+\r
+> +    (setq body (concat body "\n"))\r
+> +=09\r
+\r
+If it already ends with a carriage return, why do this?\r
+\r
+--=-=-=\r
+Content-Type: application/pgp-signature\r
+\r
+-----BEGIN PGP SIGNATURE-----\r
+Version: GnuPG v1.4.11 (GNU/Linux)\r
+\r
+iEYEARECAAYFAk8KqjgACgkQaezQq/BJZRYKjgCdFRk68a66Bwlk5yRAfXGvAgtG\r
+/akAn1yNHIX6CaeXPLKMRtwiSHBvYu8+\r
+=/FA4\r
+-----END PGP SIGNATURE-----\r
+--=-=-=--\r