1 ;;; org-wl.el - Support for links to Wanderlust messages in Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
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, or (at your option)
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; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;; This file implements links to Wanderlust messages for Org-mode.
31 ;; Org-mode loads this module by default - if this is not what you want,
32 ;; configure the variable `org-modules'.
36 ;; Declare external functions and variables
37 (declare-function elmo-folder-exists-p
"ext:elmo" (folder) t
)
38 (declare-function elmo-message-entity-field
"ext:elmo-msgdb"
39 (entity field
&optional type
))
40 (declare-function elmo-message-field
"ext:elmo"
41 (folder number field
&optional type
) t
)
42 (declare-function elmo-msgdb-overview-get-entity
"ext:elmo" (&rest unknown
) t
)
43 ;; Backward compatibility to old version of wl
44 (declare-function wl-summary-buffer-msgdb
"ext:wl-folder" (&rest unknown
) t
)
45 (declare-function wl-folder-get-elmo-folder
"ext:wl-folder"
46 (entity &optional no-cache
))
47 (declare-function wl-summary-goto-folder-subr
"ext:wl-summary"
48 (&optional name scan-type other-window sticky interactive
50 (declare-function wl-summary-jump-to-msg-by-message-id
"ext:wl-summary"
52 (declare-function wl-summary-line-from
"ext:wl-summary" ())
53 (declare-function wl-summary-line-subject
"ext:wl-summary" ())
54 (declare-function wl-summary-message-number
"ext:wl-summary" ())
55 (declare-function wl-summary-redisplay
"ext:wl-summary" (&optional arg
))
56 (defvar wl-summary-buffer-elmo-folder
)
57 (defvar wl-summary-buffer-folder-name
)
59 ;; Install the link type
60 (org-add-link-type "wl" 'org-wl-open
)
61 (add-hook 'org-store-link-functions
'org-wl-store-link
)
64 (defun org-wl-store-link ()
65 "Store a link to an WL folder or message."
66 (when (eq major-mode
'wl-summary-mode
)
67 (let* ((msgnum (wl-summary-message-number))
68 (message-id (elmo-message-field wl-summary-buffer-elmo-folder
71 (if (fboundp 'elmo-message-entity
)
73 wl-summary-buffer-elmo-folder msgnum
)
74 (elmo-msgdb-overview-get-entity
75 msgnum
(wl-summary-buffer-msgdb))))
76 (from (wl-summary-line-from))
77 (to (car (elmo-message-entity-field wl-message-entity
'to
)))
78 (subject (let (wl-thr-indent-string wl-parent-message-entity
)
79 (wl-summary-line-subject)))
81 (org-store-link-props :type
"wl" :from from
:to to
82 :subject subject
:message-id message-id
)
83 (setq message-id
(org-remove-angle-brackets message-id
))
84 (setq desc
(org-email-link-description))
85 (setq link
(org-make-link "wl:" wl-summary-buffer-folder-name
87 (org-add-link-props :link link
:description desc
)
90 (defun org-wl-open (path)
91 "Follow an WL message link."
93 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path
))
94 (error "Error in Wanderlust link"))
95 (setq folder
(match-string 1 path
)
96 article
(match-string 3 path
))
97 (org-wl-follow-link folder article
)))
99 (defun org-wl-follow-link (folder article
)
100 "Follow a Wanderlust link to FOLDER and ARTICLE."
101 (if (and (string= folder
"%")
103 (string-match "^\\([^#]+\\)\\(#\\(.*\\)\\)?" article
))
104 ;; XXX: imap-uw supports folders starting with '#' such as "#mh/inbox".
105 ;; Thus, we recompose folder and article ids.
106 (setq folder
(format "%s#%s" folder
(match-string 1 article
))
107 article
(match-string 3 article
)))
108 (if (not (elmo-folder-exists-p (wl-folder-get-elmo-folder folder
)))
109 (error "No such folder: %s" folder
))
110 (wl-summary-goto-folder-subr folder
'no-sync t nil t nil nil
)
112 (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets article
))
113 (wl-summary-redisplay)))
117 ;;; org-wl.el ends here