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