annotate lisp/textmodes/org-mac-message.el @ 92893:5c84b9c7e7a2

*** empty log message ***
author Glenn Morris <rgm@gnu.org>
date Fri, 14 Mar 2008 02:40:21 +0000
parents a8351fbe7e61
children 6de0682bb52b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92887
a8351fbe7e61 Fix commentary.
Glenn Morris <rgm@gnu.org>
parents: 92868
diff changeset
1 ;;; org-mac-message.el --- Support for links to Apple Mail messages by Message-ID
a8351fbe7e61 Fix commentary.
Glenn Morris <rgm@gnu.org>
parents: 92868
diff changeset
2
92868
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
92887
a8351fbe7e61 Fix commentary.
Glenn Morris <rgm@gnu.org>
parents: 92868
diff changeset
4
a8351fbe7e61 Fix commentary.
Glenn Morris <rgm@gnu.org>
parents: 92868
diff changeset
5 ;; Author: John Wiegley <johnw@gnu.org>
92868
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
6 ;; Version: 1.2
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
7 ;; Keywords: outlines, hypermedia, calendar, wp
92887
a8351fbe7e61 Fix commentary.
Glenn Morris <rgm@gnu.org>
parents: 92868
diff changeset
8
92868
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
92887
a8351fbe7e61 Fix commentary.
Glenn Morris <rgm@gnu.org>
parents: 92868
diff changeset
10
92868
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
11 ;; Emacs is free software; you can redistribute it and/or modify
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
14 ;; any later version.
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
15
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
19 ;; GNU General Public License for more details.
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
20
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
24 ;; Boston, MA 02110-1301, USA.
92887
a8351fbe7e61 Fix commentary.
Glenn Morris <rgm@gnu.org>
parents: 92868
diff changeset
25
a8351fbe7e61 Fix commentary.
Glenn Morris <rgm@gnu.org>
parents: 92868
diff changeset
26 ;;; Code:
92868
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
27
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
28 (require 'org)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
29
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
30 (org-add-link-type "message" 'org-mac-message-open)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
31
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
32 (declare-function do-applescript "mac.c" (string))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
33 (unless (fboundp 'do-applescript)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
34 ;; Need to fake this using shell-command-to-string
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
35 (defun do-applescript (script)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
36 (let (start cmd return)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
37 (while (string-match "\n" script)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
38 (setq script (replace-match "\r" t t script)))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
39 (while (string-match "'" script start)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
40 (setq start (+ 2 (match-beginning 0))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
41 script (replace-match "\\'" t t script)))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
42 (setq cmd (concat "osascript -e '" script "'"))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
43 (setq return (shell-command-to-string cmd))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
44 (concat "\"" (org-trim return) "\""))))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
45
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
46 (defun org-mac-message-open (message-id)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
47 "Visit the message with the given Message-ID.
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
48 This will use the command `open' with the message url."
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
49 (start-process (concat "open message:" message-id) nil
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
50 "open" (concat "message://<" (substring message-id 2) ">")))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
51
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
52 (defun org-mac-message-insert-link ()
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
53 "Insert a link to the messages currently selected in Apple Mail.
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
54 This will use applescript to get the message-id and the subject of the
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
55 active mail in AppleMail and make a link out of it."
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
56 (interactive)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
57 (insert (org-mac-message-get-link)))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
58
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
59 (defun org-mac-message-get-link ()
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
60 "Insert a link to the messages currently selected in Apple Mail.
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
61 This will use applescript to get the message-id and the subject of the
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
62 active mail in AppleMail and make a link out of it."
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
63 (let ((subject (do-applescript "tell application \"Mail\"
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
64 set theMessages to selection
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
65 subject of beginning of theMessages
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
66 end tell"))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
67 (message-id (do-applescript "tell application \"Mail\"
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
68 set theMessages to selection
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
69 message id of beginning of theMessages
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
70 end tell")))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
71 (org-make-link-string
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
72 (concat "message://"
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
73 (substring message-id 1 (1- (length message-id))))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
74 (substring subject 1 (1- (length subject))))))
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
75
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
76 (provide 'org-mac-message)
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
77
aaf5c51ee1d3 New file
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
78 ;;; org-mac-message.el ends here