org-mew.el 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ;;; org-mew.el --- Support for links to Mew messages from within Org-mode
  2. ;; Copyright (C) 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.02
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  18. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. ;; Boston, MA 02110-1301, USA.
  20. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  21. ;;
  22. ;;; Commentary:
  23. ;; This file implements links to Mew 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-mew nil
  29. "Options concerning the Mew link."
  30. :tag "Org Startup"
  31. :group 'org-link)
  32. (defcustom org-mew-link-to-refile-destination t
  33. "Create a link to the refile destination if the message is marked as refile."
  34. :group 'org-mew
  35. :type 'boolean)
  36. ;; Declare external functions and variables
  37. (declare-function mew-cache-hit "ext:mew-cache" (fld msg &optional must-hit))
  38. (declare-function mew-header-get-value "ext:mew-header"
  39. (field &optional as-list))
  40. (declare-function mew-init "ext:mew" ())
  41. (declare-function mew-refile-get "ext:mew-refile" (msg))
  42. (declare-function mew-summary-display "ext:mew-summary2" (&optional redisplay))
  43. (declare-function mew-summary-folder-name "ext:mew-syntax" (&optional ext))
  44. (declare-function mew-summary-get-mark "ext:mew-mark" ())
  45. (declare-function mew-summary-message-number2 "ext:mew-syntax" ())
  46. (declare-function mew-summary-pick-with-mewl "ext:mew-pick"
  47. (pattern folder src-msgs))
  48. (declare-function mew-summary-search-msg "ext:mew-const" (msg))
  49. (declare-function mew-summary-set-message-buffer "ext:mew-summary3" (fld msg))
  50. (declare-function mew-summary-visit-folder "ext:mew-summary4"
  51. (folder &optional goend no-ls))
  52. (declare-function mew-window-push "ext:mew" ())
  53. (defvar mew-init-p)
  54. (defvar mew-summary-goto-line-then-display)
  55. ;; Install the link type
  56. (org-add-link-type "mew" 'org-mew-open)
  57. (add-hook 'org-store-link-functions 'org-mew-store-link)
  58. ;; Implementation
  59. (defun org-mew-store-link ()
  60. "Store a link to a MEW folder or message."
  61. (when (memq major-mode '(mew-summary-mode mew-virtual-mode))
  62. (let* ((msgnum (mew-summary-message-number2))
  63. (mark-info (mew-summary-get-mark))
  64. (folder-name
  65. (if (and org-mew-link-to-refile-destination
  66. (eq mark-info ?o)) ; marked as refile
  67. (nth 1 (mew-refile-get msgnum))
  68. (mew-summary-folder-name)))
  69. message-id from to subject desc link)
  70. (save-window-excursion
  71. (if (fboundp 'mew-summary-set-message-buffer)
  72. (mew-summary-set-message-buffer folder-name msgnum)
  73. (set-buffer (mew-cache-hit folder-name msgnum t)))
  74. (setq message-id (mew-header-get-value "Message-Id:"))
  75. (setq from (mew-header-get-value "From:"))
  76. (setq to (mew-header-get-value "To:"))
  77. (setq subject (mew-header-get-value "Subject:")))
  78. (org-store-link-props :type "mew" :from from :to to
  79. :subject subject :message-id message-id)
  80. (setq message-id (org-remove-angle-brackets message-id))
  81. (setq desc (org-email-link-description))
  82. (setq link (org-make-link "mew:" folder-name
  83. "#" message-id))
  84. (org-add-link-props :link link :description desc)
  85. link)))
  86. (defun org-mew-open (path)
  87. "Follow the Mew message link specified by PATH."
  88. (let (folder msgnum)
  89. (cond ((string-match "\\`\\(+.*\\)+\\+\\([0-9]+\\)\\'" path) ; for Bastien's
  90. (setq folder (match-string 1 path))
  91. (setq msgnum (match-string 2 path)))
  92. ((string-match "\\`\\(\\(%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path)
  93. (setq folder (match-string 1 path))
  94. (setq msgnum (match-string 4 path)))
  95. (t (error "Error in Mew link")))
  96. (require 'mew)
  97. (mew-window-push)
  98. (unless mew-init-p (mew-init))
  99. (mew-summary-visit-folder folder)
  100. (when msgnum
  101. (if (not (string-match "\\`[0-9]+\\'" msgnum))
  102. (let* ((pattern (concat "message-id=" msgnum))
  103. (msgs (mew-summary-pick-with-mewl pattern folder nil)))
  104. (setq msgnum (car msgs))))
  105. (if (mew-summary-search-msg msgnum)
  106. (if mew-summary-goto-line-then-display
  107. (mew-summary-display))
  108. (error "Message not found")))))
  109. (provide 'org-mew)
  110. ;;; org-mew.el ends here