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 part of Planner. It is not part of GNU Emacs.
14 ;; Planner is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; Planner is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with Planner; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 ;; Boston, MA 02110-1301, USA.
31 ;; Inspired by planner-gnus (thanks to Sacha Chua)
33 ;; This file adds annotations for MH-E messages. You will then be able
34 ;; to use M-x planner-create-task-from-buffer to create tasks from
35 ;; MH-E folder or show buffers with the correct annotation. If you
36 ;; create an annotation from a mh-index folder, the message "real"
37 ;; folder will be taken into account.
41 ;; Yann Hodique helped port this to Muse.
49 (defun planner-mhe-get-message-folder-from-index ()
50 "Returns the name of the message folder in a index folder
53 (mh-index-previous-folder)
55 (planner-line-beginning-position)
56 (planner-line-end-position))))
58 (defun planner-mhe-get-message-real-folder ()
59 "Return the name of the current message real folder, so if you use
60 sequences, it will now work."
63 (if (equal major-mode
'mh-folder-mode
)
65 ;; Refer to the show buffer
66 mh-show-folder-buffer
))
67 (end-index (min (length mh-index-folder
) (length folder
))))
68 ;; a simple test on mh-index-data does not work, because
69 ;; mh-index-data is always nil in a show buffer.
70 (if (string= mh-index-folder
(substring folder
0 end-index
))
71 (if (equal major-mode
'mh-show-mode
)
72 (save-window-excursion
73 (when (buffer-live-p (get-buffer folder
))
75 (pop-to-buffer folder
)
76 (planner-mhe-get-message-folder-from-index))))
77 (planner-mhe-get-message-folder-from-index))
80 (defun planner-mhe-get-message-folder ()
81 "Return the name of the current message folder."
82 (if (equal major-mode
'mh-folder-mode
)
84 ;; Refer to the show buffer
85 mh-show-folder-buffer
))
87 (defun planner-mhe-get-message-field (field)
88 "Return a particular field of the current message."
91 (if (equal major-mode
'mh-folder-mode
)
93 ;; Refer to the show buffer
94 (mh-show-buffer-message-number)))
95 (folder (planner-mhe-get-message-folder)))
98 (call-process (expand-file-name "anno" mh-progs
)
101 "-list" "-component" field
102 (number-to-string num
))
107 (defun planner-mhe-annotation ()
108 "If called from a MH-E folder or message buffer, return an annotation.
109 Suitable for use in `planner-annotation-functions'."
110 (when (or (equal major-mode
'mh-folder-mode
)
111 (equal major-mode
'mh-show-mode
))
112 (let ((from-header (planner-mhe-get-message-field "From"))
113 (to-header (planner-mhe-get-message-field "To")))
115 (concat "mhe://" (planner-mhe-get-message-real-folder) "/"
116 (planner-mhe-get-message-field "Message-Id"))
118 (if (and planner-ignored-from-addresses
120 (string-match planner-ignored-from-addresses
122 ;; Mail from me, so use the To: instead
123 (concat "to " (planner-get-name-from-address
125 ;; Mail to me, so use the From:
126 (concat "from " (planner-get-name-from-address
130 (defun planner-mhe-browse-url (url)
131 "If this is a MH-E URL, jump to it."
132 (when (string-match "\\`mhe://\\(.+\\)/\\([^>\n]+\\)" url
)
133 (let* ((folder (match-string 1 url
))
134 (num (match-string 2 url
))
135 (show-buf (concat "show-" folder
)))
136 (save-window-excursion
137 (mh-visit-folder folder
)
138 (get-buffer-create show-buf
)
141 (if (= (aref num
0) ?
<) ; message-id
145 (expand-file-name "pick" mh-progs
)
154 (pop-to-buffer show-buf
))))
156 ;(fset 'planner-get-from 'planner-gnus-get-address)
157 ;(fset 'planner-get-message-id 'planner-gnus-get-message-id)
158 (custom-add-option 'planner-annotation-functions
159 'planner-mhe-annotation
)
160 (add-hook 'planner-annotation-functions
'planner-mhe-annotation
)
161 (planner-add-protocol "mhe://" 'planner-mhe-browse-url nil
)
163 ; to set the mh-path etc. variables
166 (provide 'planner-mhe
)
167 ;;; planner-mhe.el ends here