1 ;;; notmuch-print.el --- printing messages from notmuch.
3 ;; Copyright © David Edmondson
5 ;; This file is part of Notmuch.
7 ;; Notmuch is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; Notmuch is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Notmuch. If not, see <https://www.gnu.org/licenses/>.
20 ;; Authors: David Edmondson <dme@dme.org>
24 (require 'notmuch-lib)
26 (declare-function notmuch-show-get-prop "notmuch-show" (prop &optional props))
28 (defcustom notmuch-print-mechanism 'notmuch-print-lpr
29 "How should printing be done?"
32 (function :tag "Use lpr" notmuch-print-lpr)
33 (function :tag "Use ps-print" notmuch-print-ps-print)
34 (function :tag "Use ps-print then evince" notmuch-print-ps-print/evince)
35 (function :tag "Use muttprint" notmuch-print-muttprint)
36 (function :tag "Use muttprint then evince" notmuch-print-muttprint/evince)
37 (function :tag "Using a custom function")))
41 (defun notmuch-print-run-evince (file)
42 "View FILE using 'evince'."
43 (start-process "evince" nil "evince" file))
45 (defun notmuch-print-run-muttprint (&optional output)
46 "Pass the contents of the current buffer to 'muttprint'.
48 Optional OUTPUT allows passing a list of flags to muttprint."
49 (apply #'call-process-region (point-min) (point-max)
54 "--printed-headers" "Date_To_From_CC_Newsgroups_*Subject*_/Tags/"
57 ;; User-visible functions:
59 (defun notmuch-print-lpr (msg)
60 "Print a message buffer using lpr."
63 (defun notmuch-print-ps-print (msg)
64 "Print a message buffer using the ps-print package."
65 (let ((subject (notmuch-prettify-subject
66 (plist-get (notmuch-show-get-prop :headers msg) :Subject))))
67 (rename-buffer subject t)
70 (defun notmuch-print-ps-print/evince (msg)
71 "Preview a message buffer using ps-print and evince."
72 (let ((ps-file (make-temp-file "notmuch"))
73 (subject (notmuch-prettify-subject
74 (plist-get (notmuch-show-get-prop :headers msg) :Subject))))
75 (rename-buffer subject t)
76 (ps-print-buffer ps-file)
77 (notmuch-print-run-evince ps-file)))
79 (defun notmuch-print-muttprint (msg)
80 "Print a message using muttprint."
81 (notmuch-print-run-muttprint))
83 (defun notmuch-print-muttprint/evince (msg)
84 "Preview a message buffer using muttprint and evince."
85 (let ((ps-file (make-temp-file "notmuch")))
86 (notmuch-print-run-muttprint (list "--printer" (concat "TO_FILE:" ps-file)))
87 (notmuch-print-run-evince ps-file)))
89 (defun notmuch-print-message (msg)
90 "Print a message using the user-selected mechanism."
91 (set-buffer-modified-p nil)
92 (funcall notmuch-print-mechanism msg))
94 (provide 'notmuch-print)
96 ;;; notmuch-print.el ends here