Release 6.05b.
[org-mode.git] / lisp / org-mew.el
blob27a0a0abc69ecdef54ee609de6aa9d191805ab96
1 ;;; org-mew.el --- Support for links to Mew messages from within Org-mode
3 ;; Copyright (C) 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
8 ;; Version: 6.05b
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 ;; This file implements links to Mew 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'.
32 ;;; Code:
34 (require 'org)
36 (defgroup org-mew nil
37 "Options concerning the Mew link."
38 :tag "Org Startup"
39 :group 'org-link)
41 (defcustom org-mew-link-to-refile-destination t
42 "Create a link to the refile destination if the message is marked as refile."
43 :group 'org-mew
44 :type 'boolean)
46 ;; Declare external functions and variables
47 (declare-function mew-cache-hit "ext:mew-cache" (fld msg &optional must-hit))
48 (declare-function mew-header-get-value "ext:mew-header"
49 (field &optional as-list))
50 (declare-function mew-init "ext:mew" ())
51 (declare-function mew-refile-get "ext:mew-refile" (msg))
52 (declare-function mew-summary-display "ext:mew-summary2" (&optional redisplay))
53 (declare-function mew-summary-folder-name "ext:mew-syntax" (&optional ext))
54 (declare-function mew-summary-get-mark "ext:mew-mark" ())
55 (declare-function mew-summary-message-number2 "ext:mew-syntax" ())
56 (declare-function mew-summary-pick-with-mewl "ext:mew-pick"
57 (pattern folder src-msgs))
58 (declare-function mew-summary-search-msg "ext:mew-const" (msg))
59 (declare-function mew-summary-set-message-buffer "ext:mew-summary3" (fld msg))
60 (declare-function mew-summary-visit-folder "ext:mew-summary4"
61 (folder &optional goend no-ls))
62 (declare-function mew-window-push "ext:mew" ())
63 (defvar mew-init-p)
64 (defvar mew-summary-goto-line-then-display)
66 ;; Install the link type
67 (org-add-link-type "mew" 'org-mew-open)
68 (add-hook 'org-store-link-functions 'org-mew-store-link)
70 ;; Implementation
71 (defun org-mew-store-link ()
72 "Store a link to a Mew folder or message."
73 (when (memq major-mode '(mew-summary-mode mew-virtual-mode))
74 (let* ((msgnum (mew-summary-message-number2))
75 (mark-info (mew-summary-get-mark))
76 (folder-name
77 (if (and org-mew-link-to-refile-destination
78 (eq mark-info ?o)) ; marked as refile
79 (nth 1 (mew-refile-get msgnum))
80 (mew-summary-folder-name)))
81 message-id from to subject desc link)
82 (save-window-excursion
83 (if (fboundp 'mew-summary-set-message-buffer)
84 (mew-summary-set-message-buffer folder-name msgnum)
85 (set-buffer (mew-cache-hit folder-name msgnum t)))
86 (setq message-id (mew-header-get-value "Message-Id:"))
87 (setq from (mew-header-get-value "From:"))
88 (setq to (mew-header-get-value "To:"))
89 (setq subject (mew-header-get-value "Subject:")))
90 (org-store-link-props :type "mew" :from from :to to
91 :subject subject :message-id message-id)
92 (setq message-id (org-remove-angle-brackets message-id))
93 (setq desc (org-email-link-description))
94 (setq link (org-make-link "mew:" folder-name
95 "#" message-id))
96 (org-add-link-props :link link :description desc)
97 link)))
99 (defun org-mew-open (path)
100 "Follow the Mew message link specified by PATH."
101 (let (folder msgnum)
102 (cond ((string-match "\\`\\(+.*\\)+\\+\\([0-9]+\\)\\'" path) ; for Bastien's
103 (setq folder (match-string 1 path))
104 (setq msgnum (match-string 2 path)))
105 ((string-match "\\`\\(\\(%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path)
106 (setq folder (match-string 1 path))
107 (setq msgnum (match-string 4 path)))
108 (t (error "Error in Mew link")))
109 (require 'mew)
110 (mew-window-push)
111 (unless mew-init-p (mew-init))
112 (mew-summary-visit-folder folder)
113 (when msgnum
114 (if (not (string-match "\\`[0-9]+\\'" msgnum))
115 (let* ((pattern (concat "message-id=" msgnum))
116 (msgs (mew-summary-pick-with-mewl pattern folder nil)))
117 (setq msgnum (car msgs))))
118 (if (mew-summary-search-msg msgnum)
119 (if mew-summary-goto-line-then-display
120 (mew-summary-display))
121 (error "Message not found")))))
123 (provide 'org-mew)
125 ;; arch-tag: 07ccdca7-6020-4941-a593-588a1e51b870
127 ;;; org-mew.el ends here