Selective tag inheritance.
[org-mode/org-tableheadings.git] / org-rmail.el
blob225918c2c1f9990c8cd3fdda884535f239660fd1
1 ;;; org-rmail.el - Support for links to RMAIL 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
8 ;; Version: 1.0
9 ;;
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)
15 ;; 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; 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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;; Commentary:
30 ;; This file implements links to RMAIL 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'.
34 (require 'org)
36 ;; Declare external functions and variables
37 (declare-function rmail-narrow-to-non-pruned-header "rmail" ())
38 (declare-function rmail-show-message "rmail" (&optional n no-summary))
39 (declare-function rmail-what-message "rmail" ())
40 (defvar rmail-current-message)
42 ;; Install the link type
43 (org-add-link-type "rmail" 'org-rmail-open)
44 (add-hook 'org-store-link-functions 'org-rmail-store-link)
46 ;; Implementation
47 (defun org-rmail-store-link ()
48 "Store a link to an RMAIL folder or message."
49 (when (or (eq major-mode 'rmail-mode)
50 (eq major-mode 'rmail-summary-mode))
51 (save-window-excursion
52 (save-restriction
53 (when (eq major-mode 'rmail-summary-mode)
54 (rmail-show-message rmail-current-message))
55 (rmail-narrow-to-non-pruned-header)
56 (let* ((folder buffer-file-name)
57 (message-id (mail-fetch-field "message-id"))
58 (from (mail-fetch-field "from"))
59 (to (mail-fetch-field "to"))
60 (subject (mail-fetch-field "subject"))
61 desc link)
62 (org-store-link-props
63 :type "rmail" :from from :to to
64 :subject subject :message-id message-id)
65 (setq message-id (org-remove-angle-brackets message-id))
66 (setq desc (org-email-link-description))
67 (setq link (org-make-link "rmail:" folder "#" message-id))
68 (org-add-link-props :link link :description desc)
69 (rmail-show-message rmail-current-message)
70 link)))))
72 (defun org-rmail-open (path)
73 "Follow an RMAIL message link."
74 (let (folder article)
75 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
76 (error "Error in RMAIL link"))
77 (setq folder (match-string 1 path)
78 article (match-string 3 path))
79 (org-rmail-follow-link folder article)))
81 (defun org-rmail-follow-link (folder article)
82 "Follow an RMAIL link to FOLDER and ARTICLE."
83 (require 'rmail)
84 (setq article (org-add-angle-brackets article))
85 (let (message-number)
86 (save-excursion
87 (save-window-excursion
88 (rmail (if (string= folder "RMAIL") rmail-file-name folder))
89 (setq message-number
90 (save-restriction
91 (widen)
92 (goto-char (point-max))
93 (if (re-search-backward
94 (concat "^Message-ID:\\s-+" (regexp-quote
95 (or article "")))
96 nil t)
97 (rmail-what-message))))))
98 (if message-number
99 (progn
100 (rmail (if (string= folder "RMAIL") rmail-file-name folder))
101 (rmail-show-message message-number)
102 message-number)
103 (error "Message not found"))))
105 (provide 'org-rmail)
107 ;;; org-rmail.el ends here