org-wl.el 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ;;; org-wl.el - Support for links to Wanderlust messages in 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 for Org-mode.
  26. ;; Org-mode loads this module by default - if this is not what you want,
  27. ;; configure the variable `org-modules'.
  28. (require 'org)
  29. (defgroup org-wl nil
  30. "Options concerning the Wanderlust link."
  31. :tag "Org Startup"
  32. :group 'org-link)
  33. (defcustom org-wl-link-to-refile-destination t
  34. "Create a link to the refile destination if the message is marked as refile."
  35. :group 'org-wl
  36. :type 'boolean)
  37. ;; Declare external functions and variables
  38. (declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
  39. (declare-function elmo-message-entity-field "ext:elmo-msgdb"
  40. (entity field &optional type))
  41. (declare-function elmo-message-field "ext:elmo"
  42. (folder number field &optional type) t)
  43. (declare-function elmo-msgdb-overview-get-entity "ext:elmo" (&rest unknown) t)
  44. ;; Backward compatibility to old version of wl
  45. (declare-function wl-summary-buffer-msgdb "ext:wl-folder" (&rest unknown) 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. (defvar wl-summary-buffer-elmo-folder)
  59. (defvar wl-summary-buffer-folder-name)
  60. ;; Install the link type
  61. (org-add-link-type "wl" 'org-wl-open)
  62. (add-hook 'org-store-link-functions 'org-wl-store-link)
  63. ;; Implementation
  64. (defun org-wl-store-link ()
  65. "Store a link to an WL folder or message."
  66. (when (eq major-mode 'wl-summary-mode)
  67. (let* ((msgnum (wl-summary-message-number))
  68. (mark-info (wl-summary-registered-temp-mark msgnum))
  69. (folder-name
  70. (if (and org-wl-link-to-refile-destination
  71. mark-info
  72. (equal (nth 1 mark-info) "o")) ; marked as refile
  73. (nth 2 mark-info)
  74. wl-summary-buffer-folder-name))
  75. (message-id (elmo-message-field wl-summary-buffer-elmo-folder
  76. msgnum 'message-id))
  77. (wl-message-entity
  78. (if (fboundp 'elmo-message-entity)
  79. (elmo-message-entity
  80. wl-summary-buffer-elmo-folder msgnum)
  81. (elmo-msgdb-overview-get-entity
  82. msgnum (wl-summary-buffer-msgdb))))
  83. (from (wl-summary-line-from))
  84. (to (let ((to-field (elmo-message-entity-field wl-message-entity
  85. 'to)))
  86. (if (listp to-field)
  87. (car to-field)
  88. to-field)))
  89. (subject (let (wl-thr-indent-string wl-parent-message-entity)
  90. (wl-summary-line-subject)))
  91. desc link)
  92. (org-store-link-props :type "wl" :from from :to to
  93. :subject subject :message-id message-id)
  94. (setq message-id (org-remove-angle-brackets message-id))
  95. (setq desc (org-email-link-description))
  96. (setq link (org-make-link "wl:" folder-name
  97. "#" message-id))
  98. (org-add-link-props :link link :description desc)
  99. link)))
  100. (defun org-wl-open (path)
  101. "Follow an WL message link."
  102. ;; XXX: The imap-uw's MH folder names start with "%#".
  103. (if (not (string-match "\\`\\(\\(?:%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path))
  104. (error "Error in Wanderlust link"))
  105. (let ((folder (match-string 1 path))
  106. (article (match-string 3 path)))
  107. (if (not (elmo-folder-exists-p (wl-folder-get-elmo-folder folder)))
  108. (error "No such folder: %s" folder))
  109. (let ((old-buf (current-buffer))
  110. (old-point (point-marker)))
  111. (wl-folder-goto-folder-subr folder)
  112. (save-excursion
  113. ;; XXX: `wl-folder-goto-folder-subr' moves point to the
  114. ;; beginning of the current line. So, restore the point
  115. ;; in the old buffer.
  116. (set-buffer old-buf)
  117. (goto-char old-point))
  118. (wl-thread-open-all)
  119. (and (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets
  120. article))
  121. (wl-summary-redisplay)))))
  122. (provide 'org-wl)
  123. ;;; org-wl.el ends here