1 ;;; planner-mhe.el --- MH-E integration for the Emacs Planner
3 ;; Copyright (C) 2004, 2005 Christophe Garion
4 ;; Parts copyright (C) 2004, 2005 Free Software Foundation, Inc.
6 ;; Author: Christophe Garion <garion@supaero.fr>
7 ;; Author: Sandra Jean Chua <sacha@free.net.ph>
8 ;; Created: <2004-08-09 17:16:57 tof planner-mhe.el>
9 ;; Time-stamp: <12/04/2005 19:26:58 Yann Hodique>
10 ;; Keywords: planner, mh-e
12 ;; This file is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; This file 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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
29 ;; Inspired by planner-gnus (thanks to Sacha Chua)
31 ;; This file adds annotations for MH-E messages. You will then be able
32 ;; to use M-x planner-create-task-from-buffer to create tasks from
33 ;; MH-E folder or show buffers with the correct annotation. If you
34 ;; create an annotation from a mh-index folder, the message "real"
35 ;; folder will be taken into account.
39 ;; Yann Hodique helped port this to Muse.
47 (defun planner-mhe-get-message-folder-from-index ()
48 "Returns the name of the message folder in a index folder
51 (mh-index-previous-folder)
53 (planner-line-beginning-position)
54 (planner-line-end-position))))
56 (defun planner-mhe-get-message-real-folder ()
57 "Return the name of the current message real folder, so if you use
58 sequences, it will now work."
61 (if (equal major-mode
'mh-folder-mode
)
63 ;; Refer to the show buffer
64 mh-show-folder-buffer
))
65 (end-index (min (length mh-index-folder
) (length folder
))))
66 ;; a simple test on mh-index-data does not work, because
67 ;; mh-index-data is always nil in a show buffer.
68 (if (string= mh-index-folder
(substring folder
0 end-index
))
69 (if (equal major-mode
'mh-show-mode
)
70 (save-window-excursion
71 (when (buffer-live-p (get-buffer folder
))
73 (pop-to-buffer folder
)
74 (planner-mhe-get-message-folder-from-index))))
75 (planner-mhe-get-message-folder-from-index))
78 (defun planner-mhe-get-message-folder ()
79 "Return the name of the current message folder."
80 (if (equal major-mode
'mh-folder-mode
)
82 ;; Refer to the show buffer
83 mh-show-folder-buffer
))
85 (defun planner-mhe-get-message-field (field)
86 "Return a particular field of the current message."
89 (if (equal major-mode
'mh-folder-mode
)
91 ;; Refer to the show buffer
92 (mh-show-buffer-message-number)))
93 (folder (planner-mhe-get-message-folder)))
96 (call-process (expand-file-name "anno" mh-progs
)
99 "-list" "-component" field
100 (number-to-string num
))
105 (defun planner-mhe-annotation ()
106 "If called from a MH-E folder or message buffer, return an annotation.
107 Suitable for use in `planner-annotation-functions'."
108 (when (or (equal major-mode
'mh-folder-mode
)
109 (equal major-mode
'mh-show-mode
))
110 (let ((from-header (planner-mhe-get-message-field "From"))
111 (to-header (planner-mhe-get-message-field "To")))
113 (concat "mhe://" (planner-mhe-get-message-real-folder) "/"
114 (planner-mhe-get-message-field "Message-Id"))
116 (if (and planner-ignored-from-addresses
118 (string-match planner-ignored-from-addresses
120 ;; Mail from me, so use the To: instead
121 (concat "to " (planner-get-name-from-address
123 ;; Mail to me, so use the From:
124 (concat "from " (planner-get-name-from-address
128 (defun planner-mhe-browse-url (url)
129 "If this is a MH-E URL, jump to it."
130 (when (string-match "\\`mhe://\\(.+\\)/\\([^>]+\\)" url
)
131 (let* ((folder (match-string 1 url
))
132 (num (match-string 2 url
))
133 (show-buf (concat "show-" folder
)))
134 (save-window-excursion
135 (mh-visit-folder folder
)
136 (get-buffer-create show-buf
)
139 (if (= (aref num
0) ?
<) ; message-id
143 (expand-file-name "pick" mh-progs
)
152 (pop-to-buffer show-buf
))))
154 ;(fset 'planner-get-from 'planner-gnus-get-address)
155 ;(fset 'planner-get-message-id 'planner-gnus-get-message-id)
156 (custom-add-option 'planner-annotation-functions
157 'planner-mhe-annotation
)
158 (add-hook 'planner-annotation-functions
'planner-mhe-annotation
)
159 (planner-add-protocol "mhe://" 'planner-mhe-browse-url nil
)
161 ; to set the mh-path etc. variables
164 (provide 'planner-mhe
)
165 ;;; planner-mhe.el ends here