1
;;; org-mu4e -- Support for links to mu4e messages/queries from within org-mode
3
;; Copyright (C) 2012 Dirk-Jan C. Binnema
5
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
6
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
7
;; Keywords: outlines, hypermedia, calendar, mail
10
;; This file is not part of GNU Emacs.
12
;; GNU Emacs is free software: you can redistribute it and/or modify
13
;; it under the terms of the GNU General Public License as published by
14
;; the Free Software Foundation, either version 3 of the License, or
15
;; (at your option) any later version.
17
;; GNU Emacs is distributed in the hope that it will be useful,
18
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
;; GNU General Public License for more details.
22
;; You should have received a copy of the GNU General Public License
23
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30
(eval-when-compile (require 'cl))
31
(eval-when-compile (require 'mu4e))
33
(defun org-mu4e-store-link ()
34
"Store a link to a mu4e query or message."
36
;; storing links to queries
37
((eq major-mode 'mu4e-hdrs-mode)
38
(let* ((query mu4e-last-expr)
40
(org-store-link-props :type "mu4e" :query query)
42
desc (org-make-link "mu4e:query:" query)
44
(org-add-link-props :link link :description desc)
47
;; storing links to messages
48
((eq major-mode 'mu4e-view-mode)
49
(let* ((msg mu4e-current-msg)
50
(msgid (or (plist-get msg :message-id) "<none>"))
51
(subject (or (plist-get msg :subject) "No subject"))
53
(org-store-link-props :type "mu4e" :link link
54
:message-id msgid :subject subject)
55
(setq link (org-make-link "mu4e:msgid:" msgid))
56
(org-add-link-props :link link :description subject)
59
(org-add-link-type "mu4e" 'org-mu4e-open)
60
(add-hook 'org-store-link-functions 'org-mu4e-store-link)
62
(defun org-mu4e-open (path)
63
"Open the mu4e message (for paths starting with 'msgid:') or run
64
the query (for paths starting with 'query:')."
67
((string-match "^msgid:\\(.+\\)" path)
68
(mu4e-view-message-with-msgid (match-string 1 path)))
69
((string-match "^query:\\(.+\\)" path)
70
(mu4e-search (match-string 1 path)))
71
(t (message "mu4e: unrecognized link type '%s'" path))))
74
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77
;;; org-mu4e.el ends here