org-vm.el 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. ;;; org-vm.el --- Support for links to VM messages from within Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
  3. ;; Author: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 6.13pre02
  7. ;;
  8. ;; This file is part of GNU Emacs.
  9. ;;
  10. ;; GNU Emacs is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; GNU Emacs is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ;;
  22. ;;; Commentary:
  23. ;; This file implements links to VM messages and folders from within Org-mode.
  24. ;; Org-mode loads this module by default - if this is not what you want,
  25. ;; configure the variable `org-modules'.
  26. ;;; Code:
  27. (require 'org)
  28. ;; Declare external functions and variables
  29. (declare-function vm-preview-current-message "ext:vm-page" ())
  30. (declare-function vm-follow-summary-cursor "ext:vm-motion" ())
  31. (declare-function vm-get-header-contents "ext:vm-summary"
  32. (message header-name-regexp &optional clump-sep))
  33. (declare-function vm-isearch-narrow "ext:vm-search" ())
  34. (declare-function vm-isearch-update "ext:vm-search" ())
  35. (declare-function vm-select-folder-buffer "ext:vm-macro" ())
  36. (declare-function vm-su-message-id "ext:vm-summary" (m))
  37. (declare-function vm-su-subject "ext:vm-summary" (m))
  38. (declare-function vm-summarize "ext:vm-summary" (&optional display raise))
  39. (defvar vm-message-pointer)
  40. (defvar vm-folder-directory)
  41. ;; Install the link type
  42. (org-add-link-type "vm" 'org-vm-open)
  43. (add-hook 'org-store-link-functions 'org-vm-store-link)
  44. ;; Implementation
  45. (defun org-vm-store-link ()
  46. "Store a link to a VM folder or message."
  47. (when (or (eq major-mode 'vm-summary-mode)
  48. (eq major-mode 'vm-presentation-mode))
  49. (and (eq major-mode 'vm-presentation-mode) (vm-summarize))
  50. (vm-follow-summary-cursor)
  51. (save-excursion
  52. (vm-select-folder-buffer)
  53. (let* ((message (car vm-message-pointer))
  54. (folder buffer-file-name)
  55. (subject (vm-su-subject message))
  56. (to (vm-get-header-contents message "To"))
  57. (from (vm-get-header-contents message "From"))
  58. (message-id (vm-su-message-id message))
  59. desc link)
  60. (org-store-link-props :type "vm" :from from :to to :subject subject
  61. :message-id message-id)
  62. (setq message-id (org-remove-angle-brackets message-id))
  63. (setq folder (abbreviate-file-name folder))
  64. (if (string-match (concat "^" (regexp-quote vm-folder-directory))
  65. folder)
  66. (setq folder (replace-match "" t t folder)))
  67. (setq desc (org-email-link-description))
  68. (setq link (org-make-link "vm:" folder "#" message-id))
  69. (org-add-link-props :link link :description desc)
  70. link))))
  71. (defun org-vm-open (path)
  72. "Follow a VM message link specified by PATH."
  73. (let (folder article)
  74. (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
  75. (error "Error in VM link"))
  76. (setq folder (match-string 1 path)
  77. article (match-string 3 path))
  78. ;; The prefix argument will be interpreted as read-only
  79. (org-vm-follow-link folder article current-prefix-arg)))
  80. (defun org-vm-follow-link (&optional folder article readonly)
  81. "Follow a VM link to FOLDER and ARTICLE."
  82. (require 'vm)
  83. (setq article (org-add-angle-brackets article))
  84. (if (string-match "^//\\([a-zA-Z]+@\\)?\\([^:]+\\):\\(.*\\)" folder)
  85. ;; ange-ftp or efs or tramp access
  86. (let ((user (or (match-string 1 folder) (user-login-name)))
  87. (host (match-string 2 folder))
  88. (file (match-string 3 folder)))
  89. (cond
  90. ((featurep 'tramp)
  91. ;; use tramp to access the file
  92. (if (featurep 'xemacs)
  93. (setq folder (format "[%s@%s]%s" user host file))
  94. (setq folder (format "/%s@%s:%s" user host file))))
  95. (t
  96. ;; use ange-ftp or efs
  97. (require (if (featurep 'xemacs) 'efs 'ange-ftp))
  98. (setq folder (format "/%s@%s:%s" user host file))))))
  99. (when folder
  100. (funcall (cdr (assq 'vm org-link-frame-setup)) folder readonly)
  101. (sit-for 0.1)
  102. (when article
  103. (require 'vm-search)
  104. (vm-select-folder-buffer)
  105. (widen)
  106. (let ((case-fold-search t))
  107. (goto-char (point-min))
  108. (if (not (re-search-forward
  109. (concat "^" "message-id: *" (regexp-quote article))))
  110. (error "Could not find the specified message in this folder"))
  111. (vm-isearch-update)
  112. (vm-isearch-narrow)
  113. (vm-preview-current-message)
  114. (vm-summarize)))))
  115. (provide 'org-vm)
  116. ;; arch-tag: cbc3047b-935e-4d2a-96e7-c5b0117aaa6d
  117. ;;; org-vm.el ends here