1 ;;; org-mac-message.el - Support for links to Apple Mail messages by Message-ID
2 ;; Carstens outline-mode for keeping track of everything.
3 ;; Copyright (C) 2008 John Wiegley
5 ;; Author: John Wiegey <johnw@gnu.org>
7 ;; Keywords: outlines, hypermedia, calendar, wp
9 ;; This file is not part of GNU Emacs.
11 ;; This file is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 (org-add-link-type "message" 'org-mac-message-open
)
31 (unless (fboundp 'do-applescript
)
32 ;; Need to fake this using shell-command-to-string
33 (defun do-applescript (script)
35 (while (string-match "\n" script
)
36 (setq script
(replace-match "\r" t t script
)))
37 (while (string-match "'" script start
)
38 (setq start
(+ 2 match-beginning
0)
39 script
(replace-match "\\'" t t script
)))
40 (setq cmd
(concat "osascript -e '" script
"'"))
41 (setq return
(shell-command-to-string cmd
))
42 (concat "\"" (org-trim return
) "\""))))
44 (defun org-mac-message-open (message-id)
45 "Visit the nnml message with the given Message-ID."
46 (start-process (concat "open message:" message-id
) nil
47 "open" (concat "message:" message-id
)))
49 (defun org-mac-insert-message-link ()
51 (let ((subject (do-applescript "tell application \"Mail\"
52 set theMessages to selection
53 subject of beginning of theMessages
55 (message-id (do-applescript "tell application \"Mail\"
56 set theMessages to selection
57 message id of beginning of theMessages
59 (insert (org-make-link-string
61 (substring message-id
1 (1- (length message-id
))))
62 (substring subject
1 (1- (length subject
)))))))
64 (provide 'org-mac-message
)
66 ;;; org-mac-message.el ends here