org-wl.el 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ;;; org-wl.el --- Support for links to Wanderlust messages from within Org-mode
  2. ;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
  3. ;; Author: Tokuya Kameshima <kames at fa2 dot so-net dot ne dot jp>
  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 Wanderlust messages 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. (defgroup org-wl nil
  29. "Options concerning the Wanderlust link."
  30. :tag "Org Startup"
  31. :group 'org-link)
  32. (defcustom org-wl-link-to-refile-destination t
  33. "Create a link to the refile destination if the message is marked as refile."
  34. :group 'org-wl
  35. :type 'boolean)
  36. ;; Declare external functions and variables
  37. (declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
  38. (declare-function elmo-message-entity-field "ext:elmo-msgdb"
  39. (entity field &optional type))
  40. (declare-function elmo-message-field "ext:elmo"
  41. (folder number field &optional type) t)
  42. (declare-function elmo-msgdb-overview-get-entity "ext:elmo" (id msgdb) t)
  43. ;; Backward compatibility to old version of wl
  44. (declare-function wl "ext:wl" () t)
  45. (declare-function wl-summary-buffer-msgdb "ext:wl-folder" () t)
  46. ;(declare-function wl-folder-get-elmo-folder "ext:wl-folder"
  47. ; (entity &optional no-cache))
  48. (declare-function wl-summary-goto-folder-subr "ext:wl-summary"
  49. (&optional name scan-type other-window sticky interactive
  50. scoring force-exit))
  51. (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
  52. (&optional id))
  53. (declare-function wl-summary-line-from "ext:wl-summary" ())
  54. (declare-function wl-summary-line-subject "ext:wl-summary" ())
  55. (declare-function wl-summary-message-number "ext:wl-summary" ())
  56. (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
  57. (declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
  58. (declare-function wl-folder-goto-folder-subr "ext:wl-folder"
  59. (&optional folder sticky))
  60. (defvar wl-init)
  61. (defvar wl-summary-buffer-elmo-folder)
  62. (defvar wl-summary-buffer-folder-name)
  63. ;; Install the link type
  64. (org-add-link-type "wl" 'org-wl-open)
  65. (add-hook 'org-store-link-functions 'org-wl-store-link)
  66. ;; Implementation
  67. (defun org-wl-store-link ()
  68. "Store a link to a WL folder or message."
  69. (when (eq major-mode 'wl-summary-mode)
  70. (let* ((msgnum (wl-summary-message-number))
  71. (mark-info (wl-summary-registered-temp-mark msgnum))
  72. (folder-name
  73. (if (and org-wl-link-to-refile-destination
  74. mark-info
  75. (equal (nth 1 mark-info) "o")) ; marked as refile
  76. (nth 2 mark-info)
  77. wl-summary-buffer-folder-name))
  78. (message-id (elmo-message-field wl-summary-buffer-elmo-folder
  79. msgnum 'message-id))
  80. (wl-message-entity
  81. (if (fboundp 'elmo-message-entity)
  82. (elmo-message-entity
  83. wl-summary-buffer-elmo-folder msgnum)
  84. (elmo-msgdb-overview-get-entity
  85. msgnum (wl-summary-buffer-msgdb))))
  86. (from (wl-summary-line-from))
  87. (to (let ((to-field (elmo-message-entity-field wl-message-entity
  88. 'to)))
  89. (if (listp to-field)
  90. (car to-field)
  91. to-field)))
  92. (subject (let (wl-thr-indent-string wl-parent-message-entity)
  93. (wl-summary-line-subject)))
  94. desc link)
  95. (org-store-link-props :type "wl" :from from :to to
  96. :subject subject :message-id message-id)
  97. (setq message-id (org-remove-angle-brackets message-id))
  98. (setq desc (org-email-link-description))
  99. (setq link (org-make-link "wl:" folder-name
  100. "#" message-id))
  101. (org-add-link-props :link link :description desc)
  102. link)))
  103. (defun org-wl-open (path)
  104. "Follow the WL message link specified by PATH."
  105. (require 'wl)
  106. (unless wl-init (wl))
  107. ;; XXX: The imap-uw's MH folder names start with "%#".
  108. (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
  109. (error "Error in Wanderlust link"))
  110. (let ((folder (match-string 1 path))
  111. (article (match-string 3 path)))
  112. (if (not (elmo-folder-exists-p (org-no-warnings
  113. (wl-folder-get-elmo-folder folder))))
  114. (error "No such folder: %s" folder))
  115. (let ((old-buf (current-buffer))
  116. (old-point (point-marker)))
  117. (wl-folder-goto-folder-subr folder)
  118. (save-excursion
  119. ;; XXX: `wl-folder-goto-folder-subr' moves point to the
  120. ;; beginning of the current line. So, restore the point
  121. ;; in the old buffer.
  122. (set-buffer old-buf)
  123. (goto-char old-point))
  124. (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
  125. article))
  126. (wl-summary-redisplay)))))
  127. (provide 'org-wl)
  128. ;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a
  129. ;;; org-wl.el ends here