ol-notmuch.el (4872B)
1 ;;; ol-notmuch.el --- Links to notmuch messages -*- lexical-binding:t -*- 2 3 ;; Copyright (C) 2010-2011 Matthieu Lemerre 4 ;; Copyright (C) 2010-2021 The Org Contributors 5 ;; Copyright (C) 2021-2024 Jonas Bernoulli 6 7 ;; Author: Matthieu Lemerre <racin@free.fr> 8 ;; Maintainer: Jonas Bernoulli <emacs.ol-notmuch@jonas.bernoulli.dev> 9 ;; Homepage: https://git.sr.ht/~tarsius/ol-notmuch 10 ;; Keywords: hypermedia mail 11 12 ;; Package-Requires: ( 13 ;; (emacs "25.1") 14 ;; (compat "29.1.4.1") 15 ;; (notmuch "0.37") 16 ;; (org "9.6.5")) 17 18 ;; SPDX-License-Identifier: GPL-3.0-or-later 19 20 ;; This file is free software: you can redistribute it and/or modify 21 ;; it under the terms of the GNU General Public License as published 22 ;; by the Free Software Foundation, either version 3 of the License, 23 ;; or (at your option) any later version. 24 ;; 25 ;; This file is distributed in the hope that it will be useful, 26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 28 ;; GNU General Public License for more details. 29 ;; 30 ;; You should have received a copy of the GNU General Public License 31 ;; along with this file. If not, see <https://www.gnu.org/licenses/>. 32 33 ;;; Commentary: 34 35 ;; This file implements links to notmuch messages and "searches". A 36 ;; search is a query to be performed by notmuch; it is the equivalent 37 ;; to folders in other mail clients. Similarly, mails are referred to 38 ;; by a query, so both a link can refer to several mails. 39 40 ;; Links have one of the following forms: 41 ;; - notmuch:<search terms> 42 ;; - notmuch-search:<search terms>. 43 44 ;; The first form opens the queries in `notmuch-show-mode', whereas the 45 ;; second link opens it in `notmuch-search-mode'. Note that queries are 46 ;; performed at the time the link is opened, and the result may be 47 ;; different from when the link was stored. 48 49 ;;; Code: 50 51 (require 'compat) 52 53 (require 'notmuch) 54 (require 'ol) 55 56 ;;; Message links 57 58 (defcustom org-notmuch-open-function #'org-notmuch-follow-link 59 "Function used to follow notmuch links. 60 Should accept a notmuch search string as the sole argument." 61 :group 'org-notmuch 62 :type 'function) 63 64 ;;;###autoload 65 (with-eval-after-load 'org 66 (org-link-set-parameters "notmuch" 67 :store #'org-notmuch-store-link 68 :follow #'org-notmuch-open)) 69 70 ;;;###autoload 71 (defun org-notmuch-store-link () 72 "Store a link to one or more notmuch messages." 73 (when (memq major-mode '(notmuch-show-mode notmuch-tree-mode)) 74 ;; The value is passed around using variable `org-store-link-plist'. 75 (org-link-store-props 76 :type "notmuch" 77 :message-id (notmuch-show-get-message-id t) 78 :subject (notmuch-show-get-subject) 79 :from (notmuch-show-get-from) 80 :to (notmuch-show-get-to) 81 :date (org-trim (notmuch-show-get-date))) 82 (org-link-add-props :link (org-link-email-description "notmuch:id:%m")) 83 (org-link-add-props :description (org-link-email-description)) 84 org-store-link-plist)) 85 86 ;;;###autoload 87 (defun org-notmuch-open (path _) 88 "Follow a notmuch message link specified by PATH." 89 (funcall org-notmuch-open-function path)) 90 91 (defun org-notmuch-follow-link (search) 92 "Follow a notmuch link to SEARCH. 93 Can link to more than one message, if so all matching messages are shown." 94 (notmuch-show search)) 95 96 ;;; Search links 97 98 ;;;###autoload 99 (with-eval-after-load 'org 100 (org-link-set-parameters "notmuch-search" 101 :store #'org-notmuch-search-store-link 102 :follow #'org-notmuch-search-open)) 103 104 ;;;###autoload 105 (defun org-notmuch-search-store-link () 106 "Store a link to a notmuch search." 107 (when (eq major-mode 'notmuch-search-mode) 108 (org-link-store-props 109 :type "notmuch-search" 110 :link (concat "notmuch-search:" notmuch-search-query-string) 111 :description (concat "Notmuch search: " notmuch-search-query-string)))) 112 113 ;;;###autoload 114 (defun org-notmuch-search-open (path _) 115 "Follow a notmuch search link specified by PATH." 116 (notmuch-search path)) 117 118 ;;; Tree links 119 120 ;;;###autoload 121 (with-eval-after-load 'org 122 (org-link-set-parameters "notmuch-tree" 123 :store #'org-notmuch-tree-store-link 124 :follow #'org-notmuch-tree-open)) 125 126 ;;;###autoload 127 (defun org-notmuch-tree-store-link () 128 "Store a link to a notmuch tree." 129 (when (eq major-mode 'notmuch-tree-mode) 130 (org-link-store-props 131 :type "notmuch-tree" 132 :link (concat "notmuch-tree:" (notmuch-tree-get-query)) 133 :description (concat "Notmuch tree: " (notmuch-tree-get-query))))) 134 135 ;;;###autoload 136 (defun org-notmuch-tree-open (path _) 137 "Follow a notmuch tree link specified by PATH." 138 (notmuch-tree path)) 139 140 ;;; _ 141 (provide 'ol-notmuch) 142 ;; Local Variables: 143 ;; indent-tabs-mode: nil 144 ;; End: 145 ;;; ol-notmuch.el ends here