1 ;;; org-wl.el --- Support for links to Wanderlust messages from within Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Tokuya Kameshima <kames at fa2 dot so-net dot ne dot jp>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;; This file implements links to Wanderlust messages from within Org-mode.
29 ;; Org-mode loads this module by default - if this is not what you want,
30 ;; configure the variable `org-modules'.
37 "Options concerning the Wanderlust link."
41 (defcustom org-wl-link-to-refile-destination t
42 "Create a link to the refile destination if the message is marked as refile."
46 ;; Declare external functions and variables
47 (declare-function elmo-folder-exists-p
"ext:elmo" (folder) t
)
48 (declare-function elmo-message-entity-field
"ext:elmo-msgdb"
49 (entity field
&optional type
))
50 (declare-function elmo-message-field
"ext:elmo"
51 (folder number field
&optional type
) t
)
52 (declare-function elmo-msgdb-overview-get-entity
"ext:elmo" (id msgdb
) t
)
53 ;; Backward compatibility to old version of wl
54 (declare-function wl
"ext:wl" () t
)
55 (declare-function wl-summary-buffer-msgdb
"ext:wl-folder" () t
)
56 ;(declare-function wl-folder-get-elmo-folder "ext:wl-folder"
57 ; (entity &optional no-cache))
58 (declare-function wl-summary-goto-folder-subr
"ext:wl-summary"
59 (&optional name scan-type other-window sticky interactive
61 (declare-function wl-summary-jump-to-msg-by-message-id
"ext:wl-summary"
63 (declare-function wl-summary-line-from
"ext:wl-summary" ())
64 (declare-function wl-summary-line-subject
"ext:wl-summary" ())
65 (declare-function wl-summary-message-number
"ext:wl-summary" ())
66 (declare-function wl-summary-redisplay
"ext:wl-summary" (&optional arg
))
67 (declare-function wl-summary-registered-temp-mark
"ext:wl-action" (number))
68 (declare-function wl-folder-goto-folder-subr
"ext:wl-folder"
69 (&optional folder sticky
))
71 (defvar wl-summary-buffer-elmo-folder
)
72 (defvar wl-summary-buffer-folder-name
)
74 ;; Install the link type
75 (org-add-link-type "wl" 'org-wl-open
)
76 (add-hook 'org-store-link-functions
'org-wl-store-link
)
79 (defun org-wl-store-link ()
80 "Store a link to a WL folder or message."
81 (when (eq major-mode
'wl-summary-mode
)
82 (let* ((msgnum (wl-summary-message-number))
83 (mark-info (wl-summary-registered-temp-mark msgnum
))
85 (if (and org-wl-link-to-refile-destination
87 (equal (nth 1 mark-info
) "o")) ; marked as refile
89 wl-summary-buffer-folder-name
))
90 (message-id (elmo-message-field wl-summary-buffer-elmo-folder
93 (if (fboundp 'elmo-message-entity
)
95 wl-summary-buffer-elmo-folder msgnum
)
96 (elmo-msgdb-overview-get-entity
97 msgnum
(wl-summary-buffer-msgdb))))
98 (from (wl-summary-line-from))
99 (to (let ((to-field (elmo-message-entity-field wl-message-entity
104 (subject (let (wl-thr-indent-string wl-parent-message-entity
)
105 (wl-summary-line-subject)))
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
113 (org-add-link-props :link link
:description desc
)
116 (defun org-wl-open (path)
117 "Follow the WL message link specified by PATH."
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
)))
125 (if (not (elmo-folder-exists-p (org-no-warnings
126 (wl-folder-get-elmo-folder folder
))))
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
)
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.
136 (goto-char old-point
))
137 (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
139 (wl-summary-redisplay)))))
143 ;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a
145 ;;; org-wl.el ends here