1 ;;; planner-mhe.el --- MH-E integration for the Emacs Planner
3 ;; Copyright (C) 2004, 2005, 2006 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: <2006-09-28 15:05:05 tof planner-mhe.el>
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.
48 (defun planner-mhe-get-message-folder-from-index ()
49 "Returns the name of the message folder in a index folder
52 (mh-index-previous-folder)
54 (planner-line-beginning-position)
55 (planner-line-end-position))))
57 (defun planner-mhe-get-message-real-folder ()
58 "Return the name of the current message real folder, so if you use
59 sequences, it will now work."
62 (if (equal major-mode
'mh-folder-mode
)
64 ;; Refer to the show buffer
65 mh-show-folder-buffer
))
66 (end-index (min (length mh-index-folder
) (length folder
))))
67 ;; a simple test on mh-index-data does not work, because
68 ;; mh-index-data is always nil in a show buffer.
69 (if (string= mh-index-folder
(substring folder
0 end-index
))
70 (if (equal major-mode
'mh-show-mode
)
71 (save-window-excursion
72 (when (buffer-live-p (get-buffer folder
))
74 (pop-to-buffer folder
)
75 (planner-mhe-get-message-folder-from-index))))
76 (planner-mhe-get-message-folder-from-index))
79 (defun planner-mhe-get-message-folder ()
80 "Return the name of the current message folder."
81 (if (equal major-mode
'mh-folder-mode
)
83 ;; Refer to the show buffer
84 mh-show-folder-buffer
))
86 (defun planner-mhe-get-message-field (field)
87 "Return a particular field of the current message."
90 (if (equal major-mode
'mh-folder-mode
)
92 ;; Refer to the show buffer
93 (mh-show-buffer-message-number)))
94 (folder (planner-mhe-get-message-folder)))
97 (call-process (expand-file-name "anno" mh-progs
)
100 "-list" "-component" field
101 (number-to-string num
))
106 (defun planner-mhe-annotation ()
107 "If called from a MH-E folder or message buffer, return an annotation.
108 Suitable for use in `planner-annotation-functions'."
109 (when (or (equal major-mode
'mh-folder-mode
)
110 (equal major-mode
'mh-show-mode
))
111 (let ((from-header (planner-mhe-get-message-field "From"))
112 (to-header (planner-mhe-get-message-field "To")))
114 (concat "mhe://" (planner-mhe-get-message-real-folder) "/"
115 (planner-mhe-get-message-field "Message-Id"))
117 (if (and planner-ignored-from-addresses
119 (string-match planner-ignored-from-addresses
121 ;; Mail from me, so use the To: instead
122 (concat "to " (planner-get-name-from-address
124 ;; Mail to me, so use the From:
125 (concat "from " (planner-get-name-from-address
129 (defun planner-mhe-browse-url (url)
130 "If this is a MH-E URL, jump to it."
131 (when (string-match "\\`mhe://\\(.+\\)/\\([^>\n]+\\)" url
)
132 (let* ((folder (match-string 1 url
))
133 (num (match-string 2 url
))
134 (show-buf (concat "show-" folder
)))
135 (save-window-excursion
136 (mh-visit-folder folder
)
137 (get-buffer-create show-buf
)
140 (if (= (aref num
0) ?
<) ; message-id
144 (expand-file-name "pick" mh-progs
)
153 (pop-to-buffer show-buf
))))
155 ;(fset 'planner-get-from 'planner-gnus-get-address)
156 ;(fset 'planner-get-message-id 'planner-gnus-get-message-id)
157 (custom-add-option 'planner-annotation-functions
158 'planner-mhe-annotation
)
159 (add-hook 'planner-annotation-functions
'planner-mhe-annotation
)
160 (planner-add-protocol "mhe://" 'planner-mhe-browse-url nil
)
162 ; to set the mh-path etc. variables
165 (provide 'planner-mhe
)
166 ;;; planner-mhe.el ends here