-
Notifications
You must be signed in to change notification settings - Fork 11
/
ebdb-mhe.el
158 lines (125 loc) · 5.72 KB
/
ebdb-mhe.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
;;; ebdb-mhe.el --- EBDB interface to mh-e -*- lexical-binding: t; -*-
;; Copyright (C) 2016-2024 Free Software Foundation, Inc.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; EBDB interface to mh-e. This was copied from the file bbdb-mhe.el,
;; written by Todd Kaufman with contributions from Fritz Knabe and
;; Jack Repenning.
;;; Code:
(require 'ebdb-com)
(require 'ebdb-mua)
(require 'mh-e)
(if (fboundp 'mh-version)
(require 'mh-comp)) ; For mh-e 4.x
(defgroup ebdb-mua-mhe nil
"EBDB customizations for mhe."
:group 'ebdb-mua)
(defcustom ebdb-mhe-auto-update-p ebdb-mua-reader-update-p
"Mh-e-specific value of `ebdb-mua-auto-update-p'."
:type '(choice (const :tag "do nothing" nil)
(const :tag "search for existing records" existing)
(const :tag "update existing records" update)
(const :tag "query for update or record creation" query)
(const :tag "update or create automatically" create)
(function :tag "User-defined function")))
(defcustom ebdb-mhe-window-size ebdb-default-window-size
"Size of the EBDB buffer when popping up in mh-e.
Size should be specified as a float between 0 and 1. Defaults to
the value of `ebdb-default-window-size'."
:type 'float)
;; A simplified `mail-fetch-field'. We could use instead (like rmail):
;; (mail-header (intern-soft (downcase header)) (mail-header-extract))
(defun ebdb/mh-header (header)
"Find and return the value of HEADER in the current buffer.
Returns the empty string if HEADER is not in the message."
(let ((case-fold-search t))
(if mh-show-buffer (set-buffer mh-show-buffer))
(goto-char (point-min))
;; This will be fooled if HEADER appears in the body of the message.
;; Also, it fails if HEADER appears more than once.
(cond ((not (re-search-forward header nil t)) "")
((looking-at "[\t ]*$") "")
(t (re-search-forward "[ \t]*\\([^ \t\n].*\\)$" nil t)
(let ((start (match-beginning 1)))
(while (progn (forward-line 1)
(looking-at "[ \t]")))
(backward-char 1)
(buffer-substring-no-properties start (point)))))))
(cl-defmethod ebdb-make-buffer-name (&context (major-mode mhe-mode))
"Produce a EBDB buffer name associated with mh-hmode."
(format "*%s-MHE*" ebdb-buffer-name))
(cl-defmethod ebdb-make-buffer-name (&context (major-mode mhe-summary-mode))
"Produce a EBDB buffer name associated with mh-hmode."
(format "*%s-MHE*" ebdb-buffer-name))
(cl-defmethod ebdb-make-buffer-name (&context (major-mode mhe-folder-mode))
"Produce a EBDB buffer name associated with mh-hmode."
(format "*%s-MHE*" ebdb-buffer-name))
(cl-defmethod ebdb-popup-buffer (&context (major-mode mhe-summary-mode))
(list (get-buffer-window) ebdb-mhe-window-size))
(cl-defmethod ebdb-mua-message-header ((header string)
&context (major-mode mhe-mode))
(ebdb/mh-header header))
(cl-defmethod ebdb-mua-message-header ((header string)
&context (major-mode mhe-summary-mode))
(ebdb/mh-header header))
(cl-defmethod ebdb-mua-message-header ((header string)
&context (major-mode mhe-folder-mode))
(ebdb/mh-header header))
(cl-defmethod ebdb-mua-prepare-article (&context (major-mode mhe-mode))
(mh-show))
(cl-defmethod ebdb-mua-prepare-article (&context (major-mode mhe-summary-mode))
(mh-show))
(cl-defmethod ebdb-mua-prepare-article (&context (major-mode mhe-folder-mode))
(mh-show))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Use EBDB for interactive spec of MH-E commands
(advice-add 'mh-send :before #'ebdb--mh-send-completion)
(defun ebdb--mh-send-completion (&rest _)
(interactive
(list (ebdb-completing-read-mails "To: ")
(ebdb-completing-read-mails "Cc: ")
(read-string "Subject: ")))
nil)
(advice-add 'mh-send-other-window :before #'ebdb--mh-send-completion)
(advice-add 'mh-forward :before #'ebdb--mh-forward-completion)
(defun ebdb--mh-forward-completion (&rest _)
(interactive
(list (ebdb-completing-read-mails "To: ")
(ebdb-completing-read-mails "Cc: ")
(if current-prefix-arg
(mh-read-seq-default "Forward" t)
(mh-get-msg-num t))))
nil)
(advice-add 'mh-redistribute :before #'ebdb--mh-redistribute-completion)
(defun ebdb--mh-redistribute-completion (&rest _)
(interactive
(list (ebdb-completing-read-mails "Redist-To: ")
(ebdb-completing-read-mails "Redist-Cc: ")
(mh-get-msg-num t)))
nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;###autoload
(defun ebdb-insinuate-mh ()
"Hook EBDB into MH-E."
(unless ebdb-db-list
(ebdb-load))
(define-key mh-folder-mode-map ";" ebdb-mua-keymap)
(when ebdb-complete-mail
(define-key mh-letter-mode-map "\M-;" #'ebdb-complete-mail)
(define-key mh-letter-mode-map "\e\t" #'ebdb-complete-mail)))
;;;###autoload
(defun ebdb-mhe-auto-update ()
(ebdb-mua-auto-update ebdb-mhe-auto-update-p))
(add-hook 'mh-show-hook #'ebdb-mhe-auto-update)
(add-hook 'mh-folder-mode-hook #'ebdb-insinuate-mh)
(provide 'ebdb-mhe)
;;; ebdb-mhe.el ends here