92887
|
1 ;;; org-mac-message.el --- Support for links to Apple Mail messages by Message-ID
|
|
2
|
92868
|
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
|
92887
|
4
|
|
5 ;; Author: John Wiegley <johnw@gnu.org>
|
92868
|
6 ;; Version: 1.2
|
|
7 ;; Keywords: outlines, hypermedia, calendar, wp
|
92887
|
8
|
92868
|
9 ;; This file is part of GNU Emacs.
|
92887
|
10
|
92868
|
11 ;; Emacs 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)
|
|
14 ;; any later version.
|
|
15
|
|
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.
|
|
20
|
|
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.
|
92887
|
25
|
|
26 ;;; Code:
|
92868
|
27
|
|
28 (require 'org)
|
|
29
|
|
30 (org-add-link-type "message" 'org-mac-message-open)
|
|
31
|
|
32 (declare-function do-applescript "mac.c" (string))
|
|
33 (unless (fboundp 'do-applescript)
|
|
34 ;; Need to fake this using shell-command-to-string
|
|
35 (defun do-applescript (script)
|
|
36 (let (start cmd return)
|
|
37 (while (string-match "\n" script)
|
|
38 (setq script (replace-match "\r" t t script)))
|
|
39 (while (string-match "'" script start)
|
|
40 (setq start (+ 2 (match-beginning 0))
|
|
41 script (replace-match "\\'" t t script)))
|
|
42 (setq cmd (concat "osascript -e '" script "'"))
|
|
43 (setq return (shell-command-to-string cmd))
|
|
44 (concat "\"" (org-trim return) "\""))))
|
|
45
|
|
46 (defun org-mac-message-open (message-id)
|
|
47 "Visit the message with the given Message-ID.
|
|
48 This will use the command `open' with the message url."
|
|
49 (start-process (concat "open message:" message-id) nil
|
|
50 "open" (concat "message://<" (substring message-id 2) ">")))
|
|
51
|
|
52 (defun org-mac-message-insert-link ()
|
|
53 "Insert a link to the messages currently selected in Apple Mail.
|
|
54 This will use applescript to get the message-id and the subject of the
|
|
55 active mail in AppleMail and make a link out of it."
|
|
56 (interactive)
|
|
57 (insert (org-mac-message-get-link)))
|
|
58
|
|
59 (defun org-mac-message-get-link ()
|
|
60 "Insert a link to the messages currently selected in Apple Mail.
|
|
61 This will use applescript to get the message-id and the subject of the
|
|
62 active mail in AppleMail and make a link out of it."
|
|
63 (let ((subject (do-applescript "tell application \"Mail\"
|
|
64 set theMessages to selection
|
|
65 subject of beginning of theMessages
|
|
66 end tell"))
|
|
67 (message-id (do-applescript "tell application \"Mail\"
|
|
68 set theMessages to selection
|
|
69 message id of beginning of theMessages
|
|
70 end tell")))
|
|
71 (org-make-link-string
|
|
72 (concat "message://"
|
|
73 (substring message-id 1 (1- (length message-id))))
|
|
74 (substring subject 1 (1- (length subject))))))
|
|
75
|
|
76 (provide 'org-mac-message)
|
|
77
|
|
78 ;;; org-mac-message.el ends here
|