org-wl.el 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. ;; Declare external functions and variables
  30. (declare-function elmo-folder-exists-p "ext:elmo" (folder) t)
  31. (declare-function elmo-message-entity-field "ext:elmo-msgdb"
  32. (entity field &optional type))
  33. (declare-function elmo-message-field "ext:elmo"
  34. (folder number field &optional type) t)
  35. (declare-function elmo-msgdb-overview-get-entity "ext:elmo" (&rest unknown) t)
  36. ;; Backward compatibility to old version of wl
  37. (declare-function wl-summary-buffer-msgdb "ext:wl-folder" (&rest unknown) t)
  38. (declare-function wl-folder-get-elmo-folder "ext:wl-folder"
  39. (entity &optional no-cache))
  40. (declare-function wl-summary-goto-folder-subr "ext:wl-summary"
  41. (&optional name scan-type other-window sticky interactive
  42. scoring force-exit))
  43. (declare-function wl-summary-jump-to-msg-by-message-id "ext:wl-summary"
  44. (&optional id))
  45. (declare-function wl-summary-line-from "ext:wl-summary" ())
  46. (declare-function wl-summary-line-subject "ext:wl-summary" ())
  47. (declare-function wl-summary-message-number "ext:wl-summary" ())
  48. (declare-function wl-summary-redisplay "ext:wl-summary" (&optional arg))
  49. (defvar wl-summary-buffer-elmo-folder)
  50. (defvar wl-summary-buffer-folder-name)
  51. ;; Install the link type
  52. (org-add-link-type "wl" 'org-wl-open)
  53. (add-hook 'org-store-link-functions 'org-wl-store-link)
  54. ;; Implementation
  55. (defun org-wl-store-link ()
  56. "Store a link to an WL folder or message."
  57. (when (eq major-mode 'wl-summary-mode)
  58. (let* ((msgnum (wl-summary-message-number))
  59. (message-id (elmo-message-field wl-summary-buffer-elmo-folder
  60. msgnum 'message-id))
  61. (wl-message-entity
  62. (if (fboundp 'elmo-message-entity)
  63. (elmo-message-entity
  64. wl-summary-buffer-elmo-folder msgnum)
  65. (elmo-msgdb-overview-get-entity
  66. msgnum (wl-summary-buffer-msgdb))))
  67. (from (wl-summary-line-from))
  68. (to (car (elmo-message-entity-field wl-message-entity 'to)))
  69. (subject (let (wl-thr-indent-string wl-parent-message-entity)
  70. (wl-summary-line-subject)))
  71. desc link)
  72. (org-store-link-props :type "wl" :from from :to to
  73. :subject subject :message-id message-id)
  74. (setq message-id (org-remove-angle-brackets message-id))
  75. (setq desc (org-email-link-description))
  76. (setq link (org-make-link "wl:" wl-summary-buffer-folder-name
  77. "#" message-id))
  78. (org-add-link-props :link link :description desc)
  79. link)))
  80. (defun org-wl-open (path)
  81. "Follow an WL message link."
  82. (let (folder article)
  83. (if (not (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" path))
  84. (error "Error in Wanderlust link"))
  85. (setq folder (match-string 1 path)
  86. article (match-string 3 path))
  87. (org-wl-follow-link folder article)))
  88. (defun org-wl-follow-link (folder article)
  89. "Follow a Wanderlust link to FOLDER and ARTICLE."
  90. (if (and (string= folder "%")
  91. article
  92. (string-match "^\\([^#]+\\)\\(#\\(.*\\)\\)?" article))
  93. ;; XXX: imap-uw supports folders starting with '#' such as "#mh/inbox".
  94. ;; Thus, we recompose folder and article ids.
  95. (setq folder (format "%s#%s" folder (match-string 1 article))
  96. article (match-string 3 article)))
  97. (if (not (elmo-folder-exists-p (wl-folder-get-elmo-folder folder)))
  98. (error "No such folder: %s" folder))
  99. (wl-summary-goto-folder-subr folder 'no-sync t nil t nil nil)
  100. (and article
  101. (wl-summary-jump-to-msg-by-message-id (org-add-angle-brackets article))
  102. (wl-summary-redisplay)))
  103. (provide 'org-wl)
  104. ;;; org-wl.el ends here