Commit | Line | Data |
---|---|---|
20908596 CD |
1 | ;;; org-wl.el --- Support for links to Wanderlust messages from within Org-mode |
2 | ||
5df4f04c | 3 | ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
1e4f816a | 4 | ;; Free Software Foundation, Inc. |
20908596 CD |
5 | |
6 | ;; Author: Tokuya Kameshima <kames at fa2 dot so-net dot ne dot jp> | |
7 | ;; Keywords: outlines, hypermedia, calendar, wp | |
8 | ;; Homepage: http://orgmode.org | |
5dec9555 | 9 | ;; Version: 6.33x |
20908596 CD |
10 | ;; |
11 | ;; This file is part of GNU Emacs. | |
12 | ;; | |
b1fc2b50 | 13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
20908596 | 14 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
15 | ;; the Free Software Foundation, either version 3 of the License, or |
16 | ;; (at your option) any later version. | |
20908596 CD |
17 | |
18 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
20908596 CD |
25 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
26 | ;; | |
27 | ;;; Commentary: | |
28 | ||
29 | ;; This file implements links to Wanderlust messages from within Org-mode. | |
30 | ;; Org-mode loads this module by default - if this is not what you want, | |
31 | ;; configure the variable `org-modules'. | |
32 | ||
33 | ;;; Code: | |
34 | ||
35 | (require 'org) | |
36 | ||
37 | (defgroup org-wl nil | |
38 | "Options concerning the Wanderlust link." | |
39 | :tag "Org Startup" | |
40 | :group 'org-link) | |
41 | ||
42 | (defcustom org-wl-link-to-refile-destination t | |
43 | "Create a link to the refile destination if the message is marked as refile." | |
44 | :group 'org-wl | |
45 | :type 'boolean) | |
46 | ||
47 | ;; Declare external functions and variables | |
48 | (declare-function elmo-folder-exists-p "ext:elmo" (folder) t) | |
49 | (declare-function elmo-message-entity-field "ext:elmo-msgdb" | |
50 | (entity field &optional type)) | |
51 | (declare-function elmo-message-field "ext:elmo" | |
52 | (folder number field &optional type) t) | |
53 | (declare-function elmo-msgdb-overview-get-entity "ext:elmo" (id msgdb) t) | |
54 | ;; Backward compatibility to old version of wl | |
55 | (declare-function wl "ext:wl" () t) | |
56 | (declare-function wl-summary-buffer-msgdb "ext:wl-folder" () t) | |
20908596 CD |
57 | (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary" |
58 | (&optional id)) | |
59 | (declare-function wl-summary-line-from "ext:wl-summary" ()) | |
60 | (declare-function wl-summary-line-subject "ext:wl-summary" ()) | |
61 | (declare-function wl-summary-message-number "ext:wl-summary" ()) | |
62 | (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg)) | |
63 | (declare-function wl-summary-registered-temp-mark "ext:wl-action" (number)) | |
64 | (declare-function wl-folder-goto-folder-subr "ext:wl-folder" | |
65 | (&optional folder sticky)) | |
20908596 CD |
66 | (defvar wl-init) |
67 | (defvar wl-summary-buffer-elmo-folder) | |
68 | (defvar wl-summary-buffer-folder-name) | |
69 | ||
70 | ;; Install the link type | |
71 | (org-add-link-type "wl" 'org-wl-open) | |
72 | (add-hook 'org-store-link-functions 'org-wl-store-link) | |
73 | ||
74 | ;; Implementation | |
75 | (defun org-wl-store-link () | |
76 | "Store a link to a WL folder or message." | |
77 | (when (eq major-mode 'wl-summary-mode) | |
78 | (let* ((msgnum (wl-summary-message-number)) | |
79 | (mark-info (wl-summary-registered-temp-mark msgnum)) | |
80 | (folder-name | |
81 | (if (and org-wl-link-to-refile-destination | |
82 | mark-info | |
83 | (equal (nth 1 mark-info) "o")) ; marked as refile | |
84 | (nth 2 mark-info) | |
85 | wl-summary-buffer-folder-name)) | |
86 | (message-id (elmo-message-field wl-summary-buffer-elmo-folder | |
87 | msgnum 'message-id)) | |
88 | (wl-message-entity | |
89 | (if (fboundp 'elmo-message-entity) | |
90 | (elmo-message-entity | |
91 | wl-summary-buffer-elmo-folder msgnum) | |
92 | (elmo-msgdb-overview-get-entity | |
93 | msgnum (wl-summary-buffer-msgdb)))) | |
5dec9555 CD |
94 | (from (let ((from-field (elmo-message-entity-field wl-message-entity |
95 | 'from))) | |
96 | (if (listp from-field) | |
97 | (car from-field) | |
98 | from-field))) | |
20908596 CD |
99 | (to (let ((to-field (elmo-message-entity-field wl-message-entity |
100 | 'to))) | |
101 | (if (listp to-field) | |
102 | (car to-field) | |
103 | to-field))) | |
104 | (subject (let (wl-thr-indent-string wl-parent-message-entity) | |
105 | (wl-summary-line-subject))) | |
106 | desc link) | |
107 | (org-store-link-props :type "wl" :from from :to to | |
108 | :subject subject :message-id message-id) | |
109 | (setq message-id (org-remove-angle-brackets message-id)) | |
110 | (setq desc (org-email-link-description)) | |
111 | (setq link (org-make-link "wl:" folder-name | |
112 | "#" message-id)) | |
113 | (org-add-link-props :link link :description desc) | |
114 | link))) | |
115 | ||
116 | (defun org-wl-open (path) | |
117 | "Follow the WL message link specified by PATH." | |
118 | (require 'wl) | |
119 | (unless wl-init (wl)) | |
120 | ;; XXX: The imap-uw's MH folder names start with "%#". | |
121 | (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path)) | |
122 | (error "Error in Wanderlust link")) | |
123 | (let ((folder (match-string 1 path)) | |
124 | (article (match-string 3 path))) | |
621f83e4 CD |
125 | (if (not (elmo-folder-exists-p (org-no-warnings |
126 | (wl-folder-get-elmo-folder folder)))) | |
20908596 CD |
127 | (error "No such folder: %s" folder)) |
128 | (let ((old-buf (current-buffer)) | |
129 | (old-point (point-marker))) | |
130 | (wl-folder-goto-folder-subr folder) | |
131 | (save-excursion | |
132 | ;; XXX: `wl-folder-goto-folder-subr' moves point to the | |
133 | ;; beginning of the current line. So, restore the point | |
134 | ;; in the old buffer. | |
135 | (set-buffer old-buf) | |
136 | (goto-char old-point)) | |
20908596 CD |
137 | (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets |
138 | article)) | |
139 | (wl-summary-redisplay))))) | |
140 | ||
141 | (provide 'org-wl) | |
142 | ||
88ac7b50 | 143 | ;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a |
b349f79f | 144 | |
20908596 | 145 | ;;; org-wl.el ends here |