Fixed bug related to repeating time stamps.
[org-mode.git] / lisp / org-vm.el
blobc38801471f6723d5b01fdae062b51b1501d99b7b
1 ;;; org-vm.el --- Support for links to VM messages from within 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: 6.00pre-1
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:
29 ;; This file implements links to VM messages and folders 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 ;; Declare external functions and variables
38 (declare-function vm-beginning-of-message "ext:vm-page" ())
39 (declare-function vm-follow-summary-cursor "ext:vm-motion" ())
40 (declare-function vm-get-header-contents "ext:vm-summary"
41 (message header-name-regexp &optional clump-sep))
42 (declare-function vm-isearch-narrow "ext:vm-search" ())
43 (declare-function vm-isearch-update "ext:vm-search" ())
44 (declare-function vm-select-folder-buffer "ext:vm-macro" ())
45 (declare-function vm-su-message-id "ext:vm-summary" (m))
46 (declare-function vm-su-subject "ext:vm-summary" (m))
47 (declare-function vm-summarize "ext:vm-summary" (&optional display raise))
48 (defvar vm-message-pointer)
49 (defvar vm-folder-directory)
51 ;; Install the link type
52 (org-add-link-type "vm" 'org-vm-open)
53 (add-hook 'org-store-link-functions 'org-vm-store-link)
55 ;; Implementation
56 (defun org-vm-store-link ()
57 "Store a link to a VM folder or message."
58 (when (or (eq major-mode 'vm-summary-mode)
59 (eq major-mode 'vm-presentation-mode))
60 (and (eq major-mode 'vm-presentation-mode) (vm-summarize))
61 (vm-follow-summary-cursor)
62 (save-excursion
63 (vm-select-folder-buffer)
64 (let* ((message (car vm-message-pointer))
65 (folder buffer-file-name)
66 (subject (vm-su-subject message))
67 (to (vm-get-header-contents message "To"))
68 (from (vm-get-header-contents message "From"))
69 (message-id (vm-su-message-id message))
70 desc link)
71 (org-store-link-props :type "vm" :from from :to to :subject subject
72 :message-id message-id)
73 (setq message-id (org-remove-angle-brackets message-id))
74 (setq folder (abbreviate-file-name folder))
75 (if (string-match (concat "^" (regexp-quote vm-folder-directory))
76 folder)
77 (setq folder (replace-match "" t t folder)))
78 (setq desc (org-email-link-description))
79 (setq link (org-make-link "vm:" folder "#" message-id))
80 (org-add-link-props :link link :description desc)
81 link))))
83 (defun org-vm-open (path)
84 "Follow a VM message link specified by PATH."
85 (let (folder article)
86 (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
87 (error "Error in VM link"))
88 (setq folder (match-string 1 path)
89 article (match-string 3 path))
90 ;; The prefix argument will be interpreted as read-only
91 (org-vm-follow-link folder article current-prefix-arg)))
93 (defun org-vm-follow-link (&optional folder article readonly)
94 "Follow a VM link to FOLDER and ARTICLE."
95 (require 'vm)
96 (setq article (org-add-angle-brackets article))
97 (if (string-match "^//\\([a-zA-Z]+@\\)?\\([^:]+\\):\\(.*\\)" folder)
98 ;; ange-ftp or efs or tramp access
99 (let ((user (or (match-string 1 folder) (user-login-name)))
100 (host (match-string 2 folder))
101 (file (match-string 3 folder)))
102 (cond
103 ((featurep 'tramp)
104 ;; use tramp to access the file
105 (if (featurep 'xemacs)
106 (setq folder (format "[%s@%s]%s" user host file))
107 (setq folder (format "/%s@%s:%s" user host file))))
109 ;; use ange-ftp or efs
110 (require (if (featurep 'xemacs) 'efs 'ange-ftp))
111 (setq folder (format "/%s@%s:%s" user host file))))))
112 (when folder
113 (funcall (cdr (assq 'vm org-link-frame-setup)) folder readonly)
114 (sit-for 0.1)
115 (when article
116 (vm-select-folder-buffer)
117 (widen)
118 (let ((case-fold-search t))
119 (goto-char (point-min))
120 (if (not (re-search-forward
121 (concat "^" "message-id: *" (regexp-quote article))))
122 (error "Could not find the specified message in this folder"))
123 (vm-isearch-update)
124 (vm-isearch-narrow)
125 (vm-beginning-of-message)
126 (vm-summarize)))))
128 (provide 'org-vm)
130 ;;; org-vm.el ends here