Mercurial > emacs
comparison lisp/textmodes/org-mac-message.el @ 92868:aaf5c51ee1d3
New file
author | Carsten Dominik <dominik@science.uva.nl> |
---|---|
date | Thu, 13 Mar 2008 08:52:34 +0000 |
parents | |
children | a8351fbe7e61 |
comparison
equal
deleted
inserted
replaced
92867:1d52d52770d2 | 92868:aaf5c51ee1d3 |
---|---|
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 Free Software Foundation, Inc. | |
4 ;; | |
5 ;; Author: John Wiegey <johnw@gnu.org> | |
6 ;; Version: 1.2 | |
7 ;; Keywords: outlines, hypermedia, calendar, wp | |
8 ;; | |
9 ;; This file is part of GNU Emacs. | |
10 ;; | |
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. | |
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
26 | |
27 (require 'org) | |
28 | |
29 (org-add-link-type "message" 'org-mac-message-open) | |
30 | |
31 (declare-function do-applescript "mac.c" (string)) | |
32 (unless (fboundp 'do-applescript) | |
33 ;; Need to fake this using shell-command-to-string | |
34 (defun do-applescript (script) | |
35 (let (start cmd return) | |
36 (while (string-match "\n" script) | |
37 (setq script (replace-match "\r" t t script))) | |
38 (while (string-match "'" script start) | |
39 (setq start (+ 2 (match-beginning 0)) | |
40 script (replace-match "\\'" t t script))) | |
41 (setq cmd (concat "osascript -e '" script "'")) | |
42 (setq return (shell-command-to-string cmd)) | |
43 (concat "\"" (org-trim return) "\"")))) | |
44 | |
45 (defun org-mac-message-open (message-id) | |
46 "Visit the message with the given Message-ID. | |
47 This will use the command `open' with the message url." | |
48 (start-process (concat "open message:" message-id) nil | |
49 "open" (concat "message://<" (substring message-id 2) ">"))) | |
50 | |
51 (defun org-mac-message-insert-link () | |
52 "Insert a link to the messages currently selected in Apple Mail. | |
53 This will use applescript to get the message-id and the subject of the | |
54 active mail in AppleMail and make a link out of it." | |
55 (interactive) | |
56 (insert (org-mac-message-get-link))) | |
57 | |
58 (defun org-mac-message-get-link () | |
59 "Insert a link to the messages currently selected in Apple Mail. | |
60 This will use applescript to get the message-id and the subject of the | |
61 active mail in AppleMail and make a link out of it." | |
62 (let ((subject (do-applescript "tell application \"Mail\" | |
63 set theMessages to selection | |
64 subject of beginning of theMessages | |
65 end tell")) | |
66 (message-id (do-applescript "tell application \"Mail\" | |
67 set theMessages to selection | |
68 message id of beginning of theMessages | |
69 end tell"))) | |
70 (org-make-link-string | |
71 (concat "message://" | |
72 (substring message-id 1 (1- (length message-id)))) | |
73 (substring subject 1 (1- (length subject)))))) | |
74 | |
75 (provide 'org-mac-message) | |
76 | |
77 ;;; org-mac-message.el ends here |