Commit | Line | Data |
---|---|---|
20908596 CD |
1 | ;;; org-mew.el --- Support for links to Mew messages from within Org-mode |
2 | ||
73b0cd50 | 3 | ;; Copyright (C) 2008-2011 Free Software Foundation, Inc. |
20908596 CD |
4 | |
5 | ;; Author: Tokuya Kameshima <kames at fa2 dot so-net dot ne dot jp> | |
6 | ;; Keywords: outlines, hypermedia, calendar, wp | |
7 | ;; Homepage: http://orgmode.org | |
acedf35c | 8 | ;; Version: 7.4 |
20908596 CD |
9 | |
10 | ;; This file is part of GNU Emacs. | |
11 | ||
b1fc2b50 | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
20908596 | 13 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
20908596 CD |
16 | |
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
20908596 CD |
24 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
25 | ;; | |
26 | ;;; Commentary: | |
27 | ||
28 | ;; This file implements links to Mew messages from within Org-mode. | |
29 | ;; Org-mode loads this module by default - if this is not what you want, | |
30 | ;; configure the variable `org-modules'. | |
31 | ||
32 | ;;; Code: | |
33 | ||
34 | (require 'org) | |
35 | ||
36 | (defgroup org-mew nil | |
ce4fdcb9 CD |
37 | "Options concerning the Mew link." |
38 | :tag "Org Startup" | |
39 | :group 'org-link) | |
20908596 CD |
40 | |
41 | (defcustom org-mew-link-to-refile-destination t | |
ce4fdcb9 CD |
42 | "Create a link to the refile destination if the message is marked as refile." |
43 | :group 'org-mew | |
44 | :type 'boolean) | |
20908596 CD |
45 | |
46 | ;; Declare external functions and variables | |
47 | (declare-function mew-cache-hit "ext:mew-cache" (fld msg &optional must-hit)) | |
ce4fdcb9 | 48 | (declare-function mew-case-folder "ext:mew-func" (case folder)) |
20908596 CD |
49 | (declare-function mew-header-get-value "ext:mew-header" |
50 | (field &optional as-list)) | |
51 | (declare-function mew-init "ext:mew" ()) | |
52 | (declare-function mew-refile-get "ext:mew-refile" (msg)) | |
ce4fdcb9 | 53 | (declare-function mew-sinfo-get-case "ext:mew-summary" ()) |
20908596 CD |
54 | (declare-function mew-summary-display "ext:mew-summary2" (&optional redisplay)) |
55 | (declare-function mew-summary-folder-name "ext:mew-syntax" (&optional ext)) | |
56 | (declare-function mew-summary-get-mark "ext:mew-mark" ()) | |
57 | (declare-function mew-summary-message-number2 "ext:mew-syntax" ()) | |
58 | (declare-function mew-summary-pick-with-mewl "ext:mew-pick" | |
59 | (pattern folder src-msgs)) | |
60 | (declare-function mew-summary-search-msg "ext:mew-const" (msg)) | |
61 | (declare-function mew-summary-set-message-buffer "ext:mew-summary3" (fld msg)) | |
62 | (declare-function mew-summary-visit-folder "ext:mew-summary4" | |
63 | (folder &optional goend no-ls)) | |
64 | (declare-function mew-window-push "ext:mew" ()) | |
65 | (defvar mew-init-p) | |
66 | (defvar mew-summary-goto-line-then-display) | |
67 | ||
68 | ;; Install the link type | |
69 | (org-add-link-type "mew" 'org-mew-open) | |
70 | (add-hook 'org-store-link-functions 'org-mew-store-link) | |
71 | ||
72 | ;; Implementation | |
73 | (defun org-mew-store-link () | |
ce4fdcb9 CD |
74 | "Store a link to a Mew folder or message." |
75 | (when (memq major-mode '(mew-summary-mode mew-virtual-mode)) | |
76 | (let* ((msgnum (mew-summary-message-number2)) | |
20908596 CD |
77 | (mark-info (mew-summary-get-mark)) |
78 | (folder-name | |
79 | (if (and org-mew-link-to-refile-destination | |
80 | (eq mark-info ?o)) ; marked as refile | |
ce4fdcb9 CD |
81 | (mew-case-folder (mew-sinfo-get-case) |
82 | (nth 1 (mew-refile-get msgnum))) | |
20908596 | 83 | (mew-summary-folder-name))) |
afe98dfa | 84 | message-id from to subject desc link date date-ts date-ts-ia) |
ce4fdcb9 | 85 | (save-window-excursion |
20908596 CD |
86 | (if (fboundp 'mew-summary-set-message-buffer) |
87 | (mew-summary-set-message-buffer folder-name msgnum) | |
88 | (set-buffer (mew-cache-hit folder-name msgnum t))) | |
89 | (setq message-id (mew-header-get-value "Message-Id:")) | |
90 | (setq from (mew-header-get-value "From:")) | |
91 | (setq to (mew-header-get-value "To:")) | |
afe98dfa CD |
92 | (setq date (mew-header-get-value "Date:")) |
93 | (setq date-ts (and date (format-time-string | |
94 | (org-time-stamp-format t) | |
95 | (date-to-time date)))) | |
96 | (setq date-ts-ia (and date (format-time-string | |
97 | (org-time-stamp-format t t) | |
98 | (date-to-time date)))) | |
20908596 | 99 | (setq subject (mew-header-get-value "Subject:"))) |
ce4fdcb9 | 100 | (org-store-link-props :type "mew" :from from :to to |
20908596 | 101 | :subject subject :message-id message-id) |
afe98dfa CD |
102 | (when date |
103 | (org-add-link-props :date date :date-timestamp date-ts | |
104 | :date-timestamp-inactive date-ts-ia)) | |
ce4fdcb9 CD |
105 | (setq message-id (org-remove-angle-brackets message-id)) |
106 | (setq desc (org-email-link-description)) | |
107 | (setq link (org-make-link "mew:" folder-name | |
20908596 | 108 | "#" message-id)) |
ce4fdcb9 CD |
109 | (org-add-link-props :link link :description desc) |
110 | link))) | |
20908596 CD |
111 | |
112 | (defun org-mew-open (path) | |
ce4fdcb9 CD |
113 | "Follow the Mew message link specified by PATH." |
114 | (let (folder msgnum) | |
115 | (cond ((string-match "\\`\\(+.*\\)+\\+\\([0-9]+\\)\\'" path) ; for Bastien's | |
20908596 CD |
116 | (setq folder (match-string 1 path)) |
117 | (setq msgnum (match-string 2 path))) | |
118 | ((string-match "\\`\\(\\(%#\\)?[^#]+\\)\\(#\\(.*\\)\\)?" path) | |
119 | (setq folder (match-string 1 path)) | |
120 | (setq msgnum (match-string 4 path))) | |
121 | (t (error "Error in Mew link"))) | |
ce4fdcb9 CD |
122 | (require 'mew) |
123 | (mew-window-push) | |
124 | (unless mew-init-p (mew-init)) | |
125 | (mew-summary-visit-folder folder) | |
126 | (when msgnum | |
127 | (if (not (string-match "\\`[0-9]+\\'" msgnum)) | |
20908596 CD |
128 | (let* ((pattern (concat "message-id=" msgnum)) |
129 | (msgs (mew-summary-pick-with-mewl pattern folder nil))) | |
130 | (setq msgnum (car msgs)))) | |
ce4fdcb9 | 131 | (if (mew-summary-search-msg msgnum) |
20908596 CD |
132 | (if mew-summary-goto-line-then-display |
133 | (mew-summary-display)) | |
134 | (error "Message not found"))))) | |
135 | ||
136 | (provide 'org-mew) | |
137 | ||
b349f79f | 138 | |
20908596 | 139 | ;;; org-mew.el ends here |