--- /dev/null
+Return-Path: <aaronecay@gmail.com>\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 8A934429E3B\r
+ for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:27:13 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, 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 q5rYiFjpNWdO for <notmuch@notmuchmail.org>;\r
+ Mon, 16 Jan 2012 13:27:12 -0800 (PST)\r
+Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com\r
+ [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 786A2429E35\r
+ for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:27:12 -0800 (PST)\r
+Received: by qcqw6 with SMTP id w6so2242389qcq.26\r
+ for <notmuch@notmuchmail.org>; Mon, 16 Jan 2012 13:27:11 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+ h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
+ :mime-version:content-type:content-transfer-encoding;\r
+ bh=7ozNwxr4ptHJcRgJOFsK+WnK5/i3LcgBNPSr5IBOkEQ=;\r
+ b=a2k/7kc3MbNDxXdyOejkZKgZ44FzxwMYTmktQXZHKa4raM/Svc9XpMXglPW3/WWWKn\r
+ ixKkZYfxrc18WMRoyMWFxk2cA75ReBDX5Tz3SHWXr3WFiQrrBorouzUoONOkeECU0HEV\r
+ e/a/MkUu1riA4DmqenJCMiZQxwy1OApQomo5c=\r
+Received: by 10.224.184.73 with SMTP id cj9mr12792938qab.80.1326749230699;\r
+ Mon, 16 Jan 2012 13:27:10 -0800 (PST)\r
+Received: from localhost (vpl458.wlan.library.upenn.edu. [130.91.141.203])\r
+ by mx.google.com with ESMTPS id\r
+ dh10sm39226003qab.19.2012.01.16.13.27.09\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Mon, 16 Jan 2012 13:27:09 -0800 (PST)\r
+From: Aaron Ecay <aaronecay@gmail.com>\r
+To: David Edmondson <dme@dme.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] emacs: Improved printing support.\r
+In-Reply-To: <1325599946-5936-1-git-send-email-dme@dme.org>\r
+References: <1325240897-27525-1-git-send-email-dme@dme.org>\r
+ <1325599946-5936-1-git-send-email-dme@dme.org>\r
+User-Agent: Notmuch/0.11+62~ge41b0d3 (http://notmuchmail.org) Emacs/24.0.92.1\r
+ (i386-apple-darwin10.8.0)\r
+Date: Mon, 16 Jan 2012 16:27:06 -0500\r
+Message-ID: <m2vcobbaol.fsf@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\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, 16 Jan 2012 21:27:13 -0000\r
+\r
+I don=E2=80=99t have (easy access to) a printer, so I haven=E2=80=99t actua=\r
+lly exercised\r
+the printing functionality of this patch.\r
+\r
+In general, the patch LGTM. Specific comments below.\r
+\r
+On Tue, 3 Jan 2012 14:12:26 +0000, David Edmondson <dme@dme.org> wrote:\r
+> Add various functions to print notmuch messages and tie them together\r
+> with a simple frontend. No keybinding is currently made to encourage\r
+> paper saving.\r
+> ---\r
+>=20\r
+> Fix the lack of shell quoting for muttprint. Rename the ps-print\r
+> buffers to have a relevant name.\r
+>=20\r
+> emacs/Makefile.local | 3 +-\r
+> emacs/notmuch-print.el | 79 ++++++++++++++++++++++++++++++++++++++++++=\r
+++++++\r
+> emacs/notmuch-show.el | 51 +++++++++++++++++++++++++++++++\r
+> 3 files changed, 132 insertions(+), 1 deletions(-)\r
+> create mode 100644 emacs/notmuch-print.el\r
+>=20\r
+> diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
+\r
+[...]\r
+\r
+> --- /dev/null\r
+> +++ b/emacs/notmuch-print.el\r
+> @@ -0,0 +1,79 @@\r
+> +;; notmuch-print.el --- printing messages from notmuch.\r
+> +;;\r
+> +;; Copyright =C2=A9 David Edmondson\r
+> +;;\r
+> +;; This file is part of Notmuch.\r
+> +;;\r
+> +;; Notmuch is free software: you can redistribute it and/or modify it\r
+> +;; under the terms of the GNU General Public License as published by\r
+> +;; the Free Software Foundation, either version 3 of the License, or\r
+> +;; (at your option) any later version.\r
+> +;;\r
+> +;; Notmuch is distributed in the hope that it will be useful, but\r
+> +;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
+> +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+> +;; General Public License for more details.\r
+> +;;\r
+> +;; You should have received a copy of the GNU General Public License\r
+> +;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.\r
+> +;;\r
+> +;; Authors: David Edmondson <dme@dme.org>\r
+> +\r
+> +(defcustom notmuch-print-mechanism 'notmuch-print-lpr\r
+> + "How should printing be done?"\r
+> + :group 'notmuch\r
+> + :type '(choice\r
+> + (function :tag "Use lpr" notmuch-print-lpr)\r
+> + (function :tag "Use ps-print" notmuch-print-ps-print)\r
+> + (function :tag "Use ps-print then evince" notmuch-print-ps-print/evin=\r
+ce)\r
+> + (function :tag "Use muttprint" notmuch-print-muttprint)\r
+> + (function :tag "Use muttprint then evince" notmuch-print-muttprint/ev=\r
+ince)\r
+> + (function :tag "Using a custom function")))\r
+> +\r
+> +(defmacro notmuch-print-with-file (filename &rest body)\r
+> + `(with-temp-buffer\r
+> + (insert-file-contents ,filename)\r
+> + (set-buffer-modified-p nil)\r
+> + ,@body))\r
+> +\r
+> +(defun notmuch-print-lpr (filename msg)\r
+> + (notmuch-print-with-file filename\r
+> + (lpr-buffer)))\r
+> +\r
+> +(defun notmuch-print-ps-print (filename msg)\r
+> + (let ((subject (plist-get (notmuch-show-get-prop :headers msg) :Subjec=\r
+t)))\r
+> + (notmuch-print-with-file filename\r
+> + (rename-buffer subject t)\r
+> + (ps-print-buffer))))\r
+> +\r
+> +(defun notmuch-print-ps-print/evince (filename msg)\r
+> + (let ((ps-file (make-temp-file "notmuch"))\r
+> + (subject (plist-get (notmuch-show-get-prop :headers msg) :Subject)))\r
+> + (notmuch-print-with-file filename\r
+> + (rename-buffer subject t)\r
+> + (ps-print-buffer ps-file)\r
+> + (async-shell-command (concat "evince " ps-file)))))\r
+> +\r
+> +(defun notmuch-print-muttprint (filename msg)\r
+> + (shell-command\r
+> + (concat "muttprint "\r
+> + "--file " (shell-quote-argument filename) " "\r
+> + ;; Show the tags.\r
+> + "--printed-headers 'Date_To_From_CC_Newsgroups_*Subject*_/Tags/'")))\r
+> +\r
+> +(defun notmuch-print-muttprint/evince (filename msg)\r
+> + (let ((ps-file (make-temp-file "notmuch")))\r
+> + (call-process-shell-command\r
+> + (concat "muttprint "\r
+> + "--file " (shell-quote-argument filename) " "\r
+> + ;; Show the tags.\r
+> + "--printed-headers 'Date_To_From_CC_Newsgroups_*Subject*_/Tags/' "\r
+> + "--printer 'TO_FILE:" (shell-quote-argument ps-file) "'"))\r
+> + (async-shell-command (concat "evince " ps-file))))\r
+> +\r
+> +(defun notmuch-print-message (filename msg)\r
+> + (funcall notmuch-print-mechanism filename msg))\r
+> +\r
+> +;;\r
+\r
+The above is just a stray comment line, right?\r
+\r
+> +\r
+> +(provide 'notmuch-print)\r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index 5502efd..55ccfc5 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -34,6 +34,7 @@\r
+> (require 'notmuch-wash)\r
+> (require 'notmuch-mua)\r
+> (require 'notmuch-crypto)\r
+> +(require 'notmuch-print)\r
+>=20=20\r
+> (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))\r
+> (declare-function notmuch-fontify-headers "notmuch" nil)\r
+> @@ -186,6 +187,51 @@ indentation."\r
+> mm-handle (> (notmuch-count-attachments mm-handle) 1))))\r
+> (message "Done"))\r
+>=20=20\r
+> +(defun notmuch-show-with-message-as-text (fn)\r
+> + "Apply function `fn' to a text representation of the current\r
+> +message."\r
+\r
+I think the docstring should say what agrs get passed to =E2=80=98fn=E2=80=\r
+=99. Also,\r
+function arguments should be referred to with capital letters, and the\r
+first line should be a complete sentence. I=E2=80=99d recommend =E2=80=9CA=\r
+pply FN to\r
+(...the rest unchanged)=E2=80=9D for brevity in the first line.\r
+\r
+(For anyone who is curious, these and other conventions are documented\r
+in section D.6 of the Elisp manual.)\r
+\r
+> +\r
+> + ;; Remake the header to ensure that all information is available.\r
+> + (let* ((to (notmuch-show-get-to))\r
+> + (cc (notmuch-show-get-cc))\r
+> + (from (notmuch-show-get-from))\r
+> + (subject (notmuch-show-get-subject))\r
+> + (date (notmuch-show-get-date))\r
+> + (tags (notmuch-show-get-tags))\r
+> + (depth (notmuch-show-get-depth))\r
+> +\r
+> + (header (concat\r
+> + "Subject: " subject "\n"\r
+> + "To: " to "\n"\r
+> + (if (not (string=3D cc ""))\r
+> + (concat "Cc: " cc "\n")\r
+> + "")\r
+> + "From: " from "\n"\r
+> + "Date: " date "\n"\r
+> + (if tags\r
+> + (concat "Tags: "\r
+> + (mapconcat '(lambda (tag) tag) tags ", ") "\n")\r
+\r
+#'identity instead of the lambda\r
+\r
+> + "")))\r
+> + (all (buffer-substring (notmuch-show-message-top)\r
+> + (notmuch-show-message-bottom)))\r
+> +\r
+> + (file (make-temp-file "notmuch")))\r
+> + (with-temp-file file\r
+> + (insert all)\r
+> + (indent-rigidly (point-min) (point-max) (- depth))\r
+> + ;; Remove the original header.\r
+> + (goto-char (point-min))\r
+> + (re-search-forward "^$" (point-max) nil)\r
+> + (delete-region (point-min) (point))\r
+> + (insert header))\r
+> + (funcall fn file (notmuch-show-get-message-properties))\r
+> + (delete-file file)))\r
+\r
+Why does this function write to a file? It seems that, of the print\r
+methods, two (ps-print and lpr) don=E2=80=99t use the file at all. One\r
+(ps-print/evince) creates yet another file, without depending on the\r
+first. The other muttprint functions do use the file. So:\r
+- This function would be more general if it didn=E2=80=99t handle file-writ=\r
+ing\r
+ itself, but rather let each consumer of text-ified messages handle\r
+ that if needed.\r
+- It would be cleaner if print backends that don=E2=80=99t crucially depend=\r
+ on\r
+ the existence of a file didn=E2=80=99t create one at all. If muttprint c=\r
+an\r
+ accept a message on stdin (it looks from the source like it can; it\r
+ gives me some error message about Iconv Perl modules when I try to run\r
+ it, so I can=E2=80=99t be sure), maybe writing to a file isn=E2=80=99t ne=\r
+cessary at\r
+ all.\r
+\r
+> +\r
+> +(defun notmuch-show-print-message ()\r
+> + "Print the current message."\r
+> + (interactive)\r
+> + (notmuch-show-with-message-as-text 'notmuch-print-message))\r
+> +\r
+> (defun notmuch-show-fontify-header ()\r
+> (let ((face (cond\r
+> ((looking-at "[Tt]o:")\r
+> @@ -760,6 +806,8 @@ current buffer, if possible."\r
+> (overlay-put headers-overlay 'priority 10))\r
+> (overlay-put (make-overlay body-start body-end) 'invisible message-i=\r
+nvis-spec)\r
+>=20=20\r
+> + (plist-put msg :depth depth)\r
+> +\r
+> ;; Save the properties for this message. Currently this saves the\r
+> ;; entire message (augmented it with other stuff), which seems\r
+> ;; like overkill. We might save a reduced subset (for example, not\r
+> @@ -1111,6 +1159,9 @@ Some useful entries are:\r
+> (defun notmuch-show-get-to ()\r
+> (notmuch-show-get-header :To))\r
+>=20=20\r
+> +(defun notmuch-show-get-depth ()\r
+> + (notmuch-show-get-prop :depth))\r
+> +\r
+> (defun notmuch-show-set-tags (tags)\r
+> "Set the tags of the current message."\r
+> (notmuch-show-set-prop :tags tags)\r
+> --=20\r
+> 1.7.7.3\r
+>=20\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r
+\r
+--=20\r
+Aaron Ecay\r