1 ;;; org-rmail.el --- Support for links to Rmail messages from within Org-mode
3 ;; Copyright (C) 2004-2011 Free Software Foundation, Inc.
5 ;; Author: Carsten Dominik <carsten at orgmode dot org>
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;; Homepage: http://orgmode.org
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;; This file implements links to Rmail messages from within Org-mode.
28 ;; Org-mode loads this module by default - if this is not what you want,
29 ;; configure the variable `org-modules'.
35 ;; Declare external functions and variables
36 (declare-function rmail-show-message
"rmail" (&optional n no-summary
))
37 (declare-function rmail-what-message
"rmail" ())
38 (defvar rmail-current-message
)
40 ;; Install the link type
41 (org-add-link-type "rmail" 'org-rmail-open
)
42 (add-hook 'org-store-link-functions
'org-rmail-store-link
)
45 (defun org-rmail-store-link ()
46 "Store a link to an Rmail folder or message."
47 (when (or (eq major-mode
'rmail-mode
)
48 (eq major-mode
'rmail-summary-mode
))
49 (save-window-excursion
51 (when (eq major-mode
'rmail-summary-mode
)
52 (rmail-show-message rmail-current-message
))
53 (when (fboundp 'rmail-narrow-to-non-pruned-header
)
54 (rmail-narrow-to-non-pruned-header))
55 (let* ((folder buffer-file-name
)
56 (message-id (mail-fetch-field "message-id"))
57 (from (mail-fetch-field "from"))
58 (to (mail-fetch-field "to"))
59 (subject (mail-fetch-field "subject"))
60 (date (mail-fetch-field "date"))
61 (date-ts (and date
(format-time-string
62 (org-time-stamp-format t
)
63 (date-to-time date
))))
64 (date-ts-ia (and date
(format-time-string
65 (org-time-stamp-format t t
)
66 (date-to-time date
))))
69 :type
"rmail" :from from
:to to
70 :subject subject
:message-id message-id
)
72 (org-add-link-props :date date
:date-timestamp date-ts
73 :date-timestamp-inactive date-ts-ia
))
74 (setq message-id
(org-remove-angle-brackets message-id
))
75 (setq desc
(org-email-link-description))
76 (setq link
(org-make-link "rmail:" folder
"#" message-id
))
77 (org-add-link-props :link link
:description desc
)
78 (rmail-show-message rmail-current-message
)
81 (defun org-rmail-open (path)
82 "Follow an Rmail message link to the specified PATH."
84 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path
))
85 (error "Error in Rmail link"))
86 (setq folder
(match-string 1 path
)
87 article
(match-string 3 path
))
88 (org-rmail-follow-link folder article
)))
90 (defun org-rmail-follow-link (folder article
)
91 "Follow an Rmail link to FOLDER and ARTICLE."
93 (setq article
(org-add-angle-brackets article
))
96 (save-window-excursion
97 (rmail (if (string= folder
"RMAIL") rmail-file-name folder
))
101 (goto-char (point-max))
102 (if (re-search-backward
103 (concat "^Message-ID:\\s-+" (regexp-quote
106 (rmail-what-message))))))
109 (rmail (if (string= folder
"RMAIL") rmail-file-name folder
))
110 (rmail-show-message message-number
)
112 (error "Message not found"))))
116 ;;; org-rmail.el ends here