Push version number to 6.33a
[org-mode.git] / lisp / org-wl.el
blob84f7e5ca380680434d7d81c91b2803cae455abf6
1 ;;; org-wl.el --- Support for links to Wanderlust messages from within Org-mode
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
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
9 ;; Version: 6.33trans
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
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.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;; Commentary:
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'.
33 ;;; Code:
35 (require 'org)
37 (defgroup org-wl nil
38 "Options concerning the Wanderlust link."
39 :tag "Org Startup"
40 :group 'org-link)
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)
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)
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))
66 (defvar wl-init)
67 (defvar wl-summary-buffer-elmo-folder)
68 (defvar wl-summary-buffer-folder-name)
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)
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))))
94 (from (wl-summary-line-from))
95 (to (let ((to-field (elmo-message-entity-field wl-message-entity
96 'to)))
97 (if (listp to-field)
98 (car to-field)
99 to-field)))
100 (subject (let (wl-thr-indent-string wl-parent-message-entity)
101 (wl-summary-line-subject)))
102 desc link)
103 (org-store-link-props :type "wl" :from from :to to
104 :subject subject :message-id message-id)
105 (setq message-id (org-remove-angle-brackets message-id))
106 (setq desc (org-email-link-description))
107 (setq link (org-make-link "wl:" folder-name
108 "#" message-id))
109 (org-add-link-props :link link :description desc)
110 link)))
112 (defun org-wl-open (path)
113 "Follow the WL message link specified by PATH."
114 (require 'wl)
115 (unless wl-init (wl))
116 ;; XXX: The imap-uw's MH folder names start with "%#".
117 (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
118 (error "Error in Wanderlust link"))
119 (let ((folder (match-string 1 path))
120 (article (match-string 3 path)))
121 (if (not (elmo-folder-exists-p (org-no-warnings
122 (wl-folder-get-elmo-folder folder))))
123 (error "No such folder: %s" folder))
124 (let ((old-buf (current-buffer))
125 (old-point (point-marker)))
126 (wl-folder-goto-folder-subr folder)
127 (save-excursion
128 ;; XXX: `wl-folder-goto-folder-subr' moves point to the
129 ;; beginning of the current line. So, restore the point
130 ;; in the old buffer.
131 (set-buffer old-buf)
132 (goto-char old-point))
133 (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
134 article))
135 (wl-summary-redisplay)))))
137 (provide 'org-wl)
139 ;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a
141 ;;; org-wl.el ends here