org-wl.el 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.02b
  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. (declare-function wl-thread-open-all "ext:wl-thread" ())
  61. (defvar wl-init)
  62. (defvar wl-summary-buffer-elmo-folder)
  63. (defvar wl-summary-buffer-folder-name)
  64. ;; Install the link type
  65. (org-add-link-type "wl" 'org-wl-open)
  66. (add-hook 'org-store-link-functions 'org-wl-store-link)
  67. ;; Implementation
  68. (defun org-wl-store-link ()
  69. "Store a link to a WL folder or message."
  70. (when (eq major-mode 'wl-summary-mode)
  71. (let* ((msgnum (wl-summary-message-number))
  72. (mark-info (wl-summary-registered-temp-mark msgnum))
  73. (folder-name
  74. (if (and org-wl-link-to-refile-destination
  75. mark-info
  76. (equal (nth 1 mark-info) "o")) ; marked as refile
  77. (nth 2 mark-info)
  78. wl-summary-buffer-folder-name))
  79. (message-id (elmo-message-field wl-summary-buffer-elmo-folder
  80. msgnum 'message-id))
  81. (wl-message-entity
  82. (if (fboundp 'elmo-message-entity)
  83. (elmo-message-entity
  84. wl-summary-buffer-elmo-folder msgnum)
  85. (elmo-msgdb-overview-get-entity
  86. msgnum (wl-summary-buffer-msgdb))))
  87. (from (wl-summary-line-from))
  88. (to (let ((to-field (elmo-message-entity-field wl-message-entity
  89. 'to)))
  90. (if (listp to-field)
  91. (car to-field)
  92. to-field)))
  93. (subject (let (wl-thr-indent-string wl-parent-message-entity)
  94. (wl-summary-line-subject)))
  95. desc link)
  96. (org-store-link-props :type "wl" :from from :to to
  97. :subject subject :message-id message-id)
  98. (setq message-id (org-remove-angle-brackets message-id))
  99. (setq desc (org-email-link-description))
  100. (setq link (org-make-link "wl:" folder-name
  101. "#" message-id))
  102. (org-add-link-props :link link :description desc)
  103. link)))
  104. (defun org-wl-open (path)
  105. "Follow the WL message link specified by PATH."
  106. (require 'wl)
  107. (unless wl-init (wl))
  108. ;; XXX: The imap-uw's MH folder names start with "%#".
  109. (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
  110. (error "Error in Wanderlust link"))
  111. (let ((folder (match-string 1 path))
  112. (article (match-string 3 path)))
  113. (if (not (elmo-folder-exists-p (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. (wl-thread-open-all)
  125. (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
  126. article))
  127. (wl-summary-redisplay)))))
  128. (provide 'org-wl)
  129. ;; arch-tag: 29b75a0f-ef2e-430b-8abc-acff75bde54a
  130. ;;; org-wl.el ends here