org-wl.el 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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: Carsten Dominik <carsten at orgmode dot org>
  4. ;; Keywords: outlines, hypermedia, calendar, wp
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 1.0
  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, or (at your option)
  13. ;; 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; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Commentary:
  25. ;; This file implements links to Wanderlust messages from within Org-mode.
  26. ;; Org-mode loads this module by default - if this is not what you want,
  27. ;; configure the variable `org-modules'.
  28. ;;; Code:
  29. (require 'org)
  30. (defgroup org-wl nil
  31. "Options concerning the Wanderlust link."
  32. :tag "Org Startup"
  33. :group 'org-link)
  34. (defcustom org-wl-link-to-refile-destination t
  35. "Create a link to the refile destination if the message is marked as refile."
  36. :group 'org-wl
  37. :type 'boolean)
  38. ;; Declare external functions and variables
  39. (declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
  40. (declare-function elmo-message-entity-field "ext:elmo-msgdb"
  41. (entity field &optional type))
  42. (declare-function elmo-message-field "ext:elmo"
  43. (folder number field &optional type) t)
  44. (declare-function elmo-msgdb-overview-get-entity "ext:elmo" (&rest unknown) t)
  45. ;; Backward compatibility to old version of wl
  46. (declare-function wl-summary-buffer-msgdb "ext:wl-folder" (&rest unknown) t)
  47. (declare-function wl-folder-get-elmo-folder "ext:wl-folder"
  48. (entity &optional no-cache))
  49. (declare-function wl-summary-goto-folder-subr "ext:wl-summary"
  50. (&optional name scan-type other-window sticky interactive
  51. scoring force-exit))
  52. (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
  53. (&optional id))
  54. (declare-function wl-summary-line-from "ext:wl-summary" ())
  55. (declare-function wl-summary-line-subject "ext:wl-summary" ())
  56. (declare-function wl-summary-message-number "ext:wl-summary" ())
  57. (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
  58. (declare-function wl-summary-registered-temp-mark "ext:wl-action" (number))
  59. (defvar wl-summary-buffer-elmo-folder)
  60. (defvar wl-summary-buffer-folder-name)
  61. ;; Install the link type
  62. (org-add-link-type "wl" 'org-wl-open)
  63. (add-hook 'org-store-link-functions 'org-wl-store-link)
  64. ;; Implementation
  65. (defun org-wl-store-link ()
  66. "Store a link to a WL folder or message."
  67. (when (eq major-mode 'wl-summary-mode)
  68. (let* ((msgnum (wl-summary-message-number))
  69. (mark-info (wl-summary-registered-temp-mark msgnum))
  70. (folder-name
  71. (if (and org-wl-link-to-refile-destination
  72. mark-info
  73. (equal (nth 1 mark-info) "o")) ; marked as refile
  74. (nth 2 mark-info)
  75. wl-summary-buffer-folder-name))
  76. (message-id (elmo-message-field wl-summary-buffer-elmo-folder
  77. msgnum 'message-id))
  78. (wl-message-entity
  79. (if (fboundp 'elmo-message-entity)
  80. (elmo-message-entity
  81. wl-summary-buffer-elmo-folder msgnum)
  82. (elmo-msgdb-overview-get-entity
  83. msgnum (wl-summary-buffer-msgdb))))
  84. (from (wl-summary-line-from))
  85. (to (let ((to-field (elmo-message-entity-field wl-message-entity
  86. 'to)))
  87. (if (listp to-field)
  88. (car to-field)
  89. to-field)))
  90. (subject (let (wl-thr-indent-string wl-parent-message-entity)
  91. (wl-summary-line-subject)))
  92. desc link)
  93. (org-store-link-props :type "wl" :from from :to to
  94. :subject subject :message-id message-id)
  95. (setq message-id (org-remove-angle-brackets message-id))
  96. (setq desc (org-email-link-description))
  97. (setq link (org-make-link "wl:" folder-name
  98. "#" message-id))
  99. (org-add-link-props :link link :description desc)
  100. link)))
  101. (defun org-wl-open (path)
  102. "Follow the WL message link specified by PATH."
  103. ;; XXX: The imap-uw's MH folder names start with "%#".
  104. (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
  105. (error "Error in Wanderlust link"))
  106. (let ((folder (match-string 1 path))
  107. (article (match-string 3 path)))
  108. (if (not (elmo-folder-exists-p (wl-folder-get-elmo-folder folder)))
  109. (error "No such folder: %s" folder))
  110. (let ((old-buf (current-buffer))
  111. (old-point (point-marker)))
  112. (wl-folder-goto-folder-subr folder)
  113. (save-excursion
  114. ;; XXX: `wl-folder-goto-folder-subr' moves point to the
  115. ;; beginning of the current line. So, restore the point
  116. ;; in the old buffer.
  117. (set-buffer old-buf)
  118. (goto-char old-point))
  119. (wl-thread-open-all)
  120. (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
  121. article))
  122. (wl-summary-redisplay)))))
  123. (provide 'org-wl)
  124. ;;; org-wl.el ends here