]> git.notmuchmail.org Git - notmuch/blob - emacs/notmuch-mua.el
emacs: more cleanup since dropping support for Emacs 24
[notmuch] / emacs / notmuch-mua.el
1 ;;; notmuch-mua.el --- emacs style mail-user-agent
2 ;;
3 ;; Copyright © David Edmondson
4 ;;
5 ;; This file is part of Notmuch.
6 ;;
7 ;; Notmuch is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11 ;;
12 ;; Notmuch is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 ;; General Public License for more details.
16 ;;
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with Notmuch.  If not, see <https://www.gnu.org/licenses/>.
19 ;;
20 ;; Authors: David Edmondson <dme@dme.org>
21
22 ;;; Code:
23
24 (eval-when-compile (require 'cl-lib))
25
26 (require 'message)
27 (require 'mm-view)
28 (require 'format-spec)
29
30 (require 'notmuch-lib)
31 (require 'notmuch-address)
32 (require 'notmuch-draft)
33 (require 'notmuch-message)
34
35 (declare-function notmuch-show-insert-body "notmuch-show" (msg body depth))
36 (declare-function notmuch-fcc-header-setup "notmuch-maildir-fcc" ())
37 (declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
38 (declare-function notmuch-draft-postpone "notmuch-draft" ())
39 (declare-function notmuch-draft-save "notmuch-draft" ())
40
41 ;;
42
43 (defcustom notmuch-mua-send-hook nil
44   "Hook run before sending messages."
45   :type 'hook
46   :group 'notmuch-send
47   :group 'notmuch-hooks)
48
49 (defcustom notmuch-mua-compose-in 'current-window
50   "Where to create the mail buffer used to compose a new message.
51 Possible values are `current-window' (default), `new-window' and
52 `new-frame'. If set to `current-window', the mail buffer will be
53 displayed in the current window, so the old buffer will be
54 restored when the mail buffer is killed. If set to `new-window'
55 or `new-frame', the mail buffer will be displayed in a new
56 window/frame that will be destroyed when the buffer is killed.
57 You may want to customize `message-kill-buffer-on-exit'
58 accordingly."
59   :group 'notmuch-send
60   :type '(choice (const :tag "Compose in the current window" current-window)
61                  (const :tag "Compose mail in a new window"  new-window)
62                  (const :tag "Compose mail in a new frame"   new-frame)))
63
64 (defcustom notmuch-mua-user-agent-function nil
65   "Function used to generate a `User-Agent:' string. If this is
66 `nil' then no `User-Agent:' will be generated."
67   :type '(choice (const :tag "No user agent string" nil)
68                  (const :tag "Full" notmuch-mua-user-agent-full)
69                  (const :tag "Notmuch" notmuch-mua-user-agent-notmuch)
70                  (const :tag "Emacs" notmuch-mua-user-agent-emacs)
71                  (function :tag "Custom user agent function"
72                            :value notmuch-mua-user-agent-full))
73   :group 'notmuch-send)
74
75 (defcustom notmuch-mua-hidden-headers nil
76   "Headers that are added to the `message-mode' hidden headers
77 list."
78   :type '(repeat string)
79   :group 'notmuch-send)
80
81 (defgroup notmuch-reply nil
82   "Replying to messages in notmuch"
83   :group 'notmuch)
84
85 (defcustom notmuch-mua-cite-function 'message-cite-original
86   "*Function for citing an original message.
87 Predefined functions include `message-cite-original' and
88 `message-cite-original-without-signature'.
89 Note that these functions use `mail-citation-hook' if that is non-nil."
90   :type '(radio (function-item message-cite-original)
91                 (function-item message-cite-original-without-signature)
92                 (function-item sc-cite-original)
93                 (function :tag "Other"))
94   :link '(custom-manual "(message)Insertion Variables")
95   :group 'notmuch-reply)
96
97 (defcustom notmuch-mua-reply-insert-header-p-function
98   'notmuch-show-reply-insert-header-p-never
99   "Function to decide which parts get a header when replying.
100
101 This function specifies which parts of a mime message with
102 multiple parts get a header."
103   :type '(radio (const :tag "No part headers"
104                        notmuch-show-reply-insert-header-p-never)
105                 (const :tag "All except multipart/* and hidden parts"
106                        notmuch-show-reply-insert-header-p-trimmed)
107                 (const :tag "Only for included text parts"
108                        notmuch-show-reply-insert-header-p-minimal)
109                 (const :tag "Exactly as in show view"
110                        notmuch-show-insert-header-p)
111                 (function :tag "Other"))
112   :group 'notmuch-reply)
113
114 (defcustom notmuch-mua-attachment-regexp
115   "\\b\\(attache\?ment\\|attached\\|attach\\|pi[èe]ce\s+jointe?\\)\\b"
116   "Message body text indicating that an attachment is expected.
117
118 This is not used unless `notmuch-mua-attachment-check' is added
119 to `notmuch-mua-send-hook'."
120   :type 'regexp
121   :group 'notmuch-send)
122
123 ;;
124
125 (defun notmuch-mua-attachment-check ()
126   "Signal an error if the message text indicates that an
127 attachment is expected but no MML referencing an attachment is
128 found.
129
130 Typically this is added to `notmuch-mua-send-hook'."
131   (when (and
132          ;; When the message mentions attachment...
133          (save-excursion
134            (message-goto-body)
135            ;; Limit search from reaching other possible parts of the message
136            (let ((search-limit (search-forward "\n<#" nil t)))
137              (message-goto-body)
138              (cl-loop while (re-search-forward notmuch-mua-attachment-regexp
139                                                search-limit t)
140                       ;; For every instance of the "attachment" string
141                       ;; found, examine the text properties. If the text
142                       ;; has either a `face' or `syntax-table' property
143                       ;; then it is quoted text and should *not* cause the
144                       ;; user to be asked about a missing attachment.
145                       if (let ((props (text-properties-at (match-beginning 0))))
146                            (not (or (memq 'syntax-table props)
147                                     (memq 'face props))))
148                       return t
149                       finally return nil)))
150          ;; ...but doesn't have a part with a filename...
151          (save-excursion
152            (message-goto-body)
153            (not (re-search-forward "^<#part [^>]*filename=" nil t)))
154          ;; ...and that's not okay...
155          (not (y-or-n-p "Attachment mentioned, but no attachment - is that okay?")))
156     ;; ...signal an error.
157     (error "Missing attachment")))
158
159 (defun notmuch-mua-get-switch-function ()
160   "Get a switch function according to `notmuch-mua-compose-in'."
161   (cond ((eq notmuch-mua-compose-in 'current-window)
162          'switch-to-buffer)
163         ((eq notmuch-mua-compose-in 'new-window)
164          'switch-to-buffer-other-window)
165         ((eq notmuch-mua-compose-in 'new-frame)
166          'switch-to-buffer-other-frame)
167         (t (error "Invalid value for `notmuch-mua-compose-in'"))))
168
169 (defun notmuch-mua-maybe-set-window-dedicated ()
170   "Set the selected window as dedicated according to
171 `notmuch-mua-compose-in'."
172   (when (or (eq notmuch-mua-compose-in 'new-frame)
173             (eq notmuch-mua-compose-in 'new-window))
174     (set-window-dedicated-p (selected-window) t)))
175
176 (defun notmuch-mua-user-agent-full ()
177   "Generate a `User-Agent:' string suitable for notmuch."
178   (concat (notmuch-mua-user-agent-notmuch)
179           " "
180           (notmuch-mua-user-agent-emacs)))
181
182 (defun notmuch-mua-user-agent-notmuch ()
183   "Generate a `User-Agent:' string suitable for notmuch."
184   (let ((notmuch-version (if (string= notmuch-emacs-version "unknown")
185                              (notmuch-cli-version)
186                            notmuch-emacs-version)))
187     (concat "Notmuch/" notmuch-version " (https://notmuchmail.org)")))
188
189 (defun notmuch-mua-user-agent-emacs ()
190   "Generate a `User-Agent:' string suitable for notmuch."
191   (concat "Emacs/" emacs-version " (" system-configuration ")"))
192
193 (defun notmuch-mua-add-more-hidden-headers ()
194   "Add some headers to the list that are hidden by default."
195   (mapc (lambda (header)
196           (unless (member header message-hidden-headers)
197             (push header message-hidden-headers)))
198         notmuch-mua-hidden-headers))
199
200 (defun notmuch-mua-reply-crypto (parts)
201   "Add mml sign-encrypt flag if any part of original message is encrypted."
202   (cl-loop for part in parts
203            if (notmuch-match-content-type (plist-get part :content-type)
204                                           "multipart/encrypted")
205            do (mml-secure-message-sign-encrypt)
206            else if (notmuch-match-content-type (plist-get part :content-type)
207                                                "multipart/*")
208            do (notmuch-mua-reply-crypto (plist-get part :content))))
209
210 ;; There is a bug in Emacs' message.el that results in a newline
211 ;; not being inserted after the References header, so the next header
212 ;; is concatenated to the end of it. This function fixes the problem,
213 ;; while guarding against the possibility that some current or future
214 ;; version of emacs has the bug fixed.
215 (defun notmuch-mua-insert-references (original-func header references)
216   (funcall original-func header references)
217   (unless (bolp) (insert "\n")))
218
219 (defun notmuch-mua-reply (query-string &optional sender reply-all)
220   (let ((args '("reply" "--format=sexp" "--format-version=4"))
221         (process-crypto notmuch-show-process-crypto)
222         reply
223         original)
224     (when process-crypto
225       (setq args (append args '("--decrypt=true"))))
226     (if reply-all
227         (setq args (append args '("--reply-to=all")))
228       (setq args (append args '("--reply-to=sender"))))
229     (setq args (append args (list query-string)))
230     ;; Get the reply object as SEXP, and parse it into an elisp object.
231     (setq reply (apply #'notmuch-call-notmuch-sexp args))
232     ;; Extract the original message to simplify the following code.
233     (setq original (plist-get reply :original))
234     ;; Extract the headers of both the reply and the original message.
235     (let* ((original-headers (plist-get original :headers))
236            (reply-headers (plist-get reply :reply-headers)))
237       ;; If sender is non-nil, set the From: header to its value.
238       (when sender
239         (plist-put reply-headers :From sender))
240       (let
241           ;; Overlay the composition window on that being used to read
242           ;; the original message.
243           ((same-window-regexps '("\\*mail .*")))
244         ;; We modify message-header-format-alist to get around
245         ;; a bug in message.el.  See the comment above on
246         ;; notmuch-mua-insert-references.
247         (let ((message-header-format-alist
248                (cl-loop for pair in message-header-format-alist
249                         if (eq (car pair) 'References)
250                         collect (cons 'References
251                                       (apply-partially
252                                        'notmuch-mua-insert-references
253                                        (cdr pair)))
254                         else
255                         collect pair)))
256           (notmuch-mua-mail (plist-get reply-headers :To)
257                             (notmuch-sanitize (plist-get reply-headers :Subject))
258                             (notmuch-headers-plist-to-alist reply-headers)
259                             nil (notmuch-mua-get-switch-function))))
260       ;; Create a buffer-local queue for tag changes triggered when
261       ;; sending the reply.
262       (when notmuch-message-replied-tags
263         (setq-local notmuch-message-queued-tag-changes
264                     (list (cons query-string notmuch-message-replied-tags))))
265       ;; Insert the message body - but put it in front of the signature
266       ;; if one is present, and after any other content
267       ;; message*setup-hooks may have added to the message body already.
268       (save-restriction
269         (message-goto-body)
270         (narrow-to-region (point) (point-max))
271         (goto-char (point-max))
272         (if (re-search-backward message-signature-separator nil t)
273             (when message-signature-insert-empty-line
274               (forward-line -1))
275           (goto-char (point-max))))
276       (let ((from (plist-get original-headers :From))
277             (date (plist-get original-headers :Date))
278             (start (point)))
279         ;; notmuch-mua-cite-function constructs a citation line based
280         ;; on the From and Date headers of the original message, which
281         ;; are assumed to be in the buffer.
282         (insert "From: " from "\n")
283         (insert "Date: " date "\n\n")
284         (insert
285          (with-temp-buffer
286            (let
287                ;; Don't attempt to clean up messages, excerpt
288                ;; citations, etc. in the original message before
289                ;; quoting.
290                ((notmuch-show-insert-text/plain-hook nil)
291                 ;; Don't omit long parts.
292                 (notmuch-show-max-text-part-size 0)
293                 ;; Insert headers for parts as appropriate for replying.
294                 (notmuch-show-insert-header-p-function
295                  notmuch-mua-reply-insert-header-p-function)
296                 ;; Ensure that any encrypted parts are
297                 ;; decrypted during the generation of the reply
298                 ;; text.
299                 (notmuch-show-process-crypto process-crypto)
300                 ;; Don't indent multipart sub-parts.
301                 (notmuch-show-indent-multipart nil))
302              ;; We don't want sigstatus buttons (an information leak and usually wrong anyway).
303              (cl-letf (((symbol-function 'notmuch-crypto-insert-sigstatus-button) #'ignore)
304                        ((symbol-function 'notmuch-crypto-insert-encstatus-button) #'ignore))
305                (notmuch-show-insert-body original (plist-get original :body) 0)
306                (buffer-substring-no-properties (point-min) (point-max))))))
307         (set-mark (point))
308         (goto-char start)
309         ;; Quote the original message according to the user's configured style.
310         (funcall notmuch-mua-cite-function)))
311     ;; Crypto processing based crypto content of the original message
312     (when process-crypto
313       (notmuch-mua-reply-crypto (plist-get original :body))))
314   ;; Push mark right before signature, if any.
315   (message-goto-signature)
316   (unless (eobp)
317     (end-of-line -1))
318   (push-mark)
319   (message-goto-body)
320   (set-buffer-modified-p nil))
321
322 (defvar notmuch-message-mode-map
323   (let ((map (make-sparse-keymap)))
324     (define-key map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
325     (define-key map (kbd "C-c C-s") #'notmuch-mua-send)
326     (define-key map (kbd "C-c C-p") #'notmuch-draft-postpone)
327     (define-key map (kbd "C-x C-s") #'notmuch-draft-save)
328     map)
329   "Keymap for `notmuch-message-mode'.")
330
331 (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
332   "Notmuch message composition mode. Mostly like `message-mode'."
333   (notmuch-address-setup))
334
335 (put 'notmuch-message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
336
337 (defun notmuch-mua-pop-to-buffer (name switch-function)
338   "Pop to buffer NAME, and warn if it already exists and is
339 modified. This function is notmuch adaptation of
340 `message-pop-to-buffer'."
341   (let ((buffer (get-buffer name)))
342     (if (and buffer
343              (buffer-name buffer))
344         (let ((window (get-buffer-window buffer 0)))
345           (if window
346               ;; Raise the frame already displaying the message buffer.
347               (progn
348                 (select-frame-set-input-focus (window-frame window))
349                 (select-window window))
350             (funcall switch-function buffer)
351             (set-buffer buffer))
352           (when (and (buffer-modified-p)
353                      (not (prog1
354                               (y-or-n-p
355                                "Message already being composed; erase? ")
356                             (message nil))))
357             (error "Message being composed")))
358       (funcall switch-function name)
359       (set-buffer name))
360     (erase-buffer)
361     (notmuch-message-mode)))
362
363 (defun notmuch-mua-mail (&optional to subject other-headers continue
364                                    switch-function yank-action send-actions
365                                    return-action &rest ignored)
366   "Invoke the notmuch mail composition window."
367   (interactive)
368   (when notmuch-mua-user-agent-function
369     (let ((user-agent (funcall notmuch-mua-user-agent-function)))
370       (unless (string= "" user-agent)
371         (push (cons 'User-Agent user-agent) other-headers))))
372   (unless (assq 'From other-headers)
373     (push (cons 'From (message-make-from
374                        (notmuch-user-name)
375                        (notmuch-user-primary-email)))
376           other-headers))
377   (notmuch-mua-pop-to-buffer (message-buffer-name "mail" to)
378                              (or switch-function
379                                  (notmuch-mua-get-switch-function)))
380   (let ((headers
381          (append
382           ;; The following is copied from `message-mail'
383           `((To . ,(or to "")) (Subject . ,(or subject "")))
384           ;; C-h f compose-mail says that headers should be specified as
385           ;; (string . value); however all the rest of message expects
386           ;; headers to be symbols, not strings (eg message-header-format-alist).
387           ;; https://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
388           ;; We need to convert any string input, eg from rmail-start-mail.
389           (dolist (h other-headers other-headers)
390             (when (stringp (car h))
391               (setcar h (intern (capitalize (car h))))))))
392         ;; Cause `message-setup-1' to do things relevant for mail,
393         ;; such as observe `message-default-mail-headers'.
394         (message-this-is-mail t))
395     (message-setup-1 headers yank-action send-actions return-action))
396   (notmuch-fcc-header-setup)
397   (message-sort-headers)
398   (message-hide-headers)
399   (set-buffer-modified-p nil)
400   (notmuch-mua-maybe-set-window-dedicated)
401   (message-goto-to))
402
403 (defcustom notmuch-identities nil
404   "Identities that can be used as the From: address when composing a new message.
405
406 If this variable is left unset, then a list will be constructed from the
407 name and addresses configured in the notmuch configuration file."
408   :type '(repeat string)
409   :group 'notmuch-send)
410
411 (defcustom notmuch-always-prompt-for-sender nil
412   "Always prompt for the From: address when composing or forwarding a message.
413
414 This is not taken into account when replying to a message, because in that case
415 the From: header is already filled in by notmuch."
416   :type 'boolean
417   :group 'notmuch-send)
418
419 (defvar notmuch-mua-sender-history nil)
420
421 (defun notmuch-mua-prompt-for-sender ()
422   "Prompt for a sender from the user's configured identities."
423   (if notmuch-identities
424       (ido-completing-read "Send mail from: " notmuch-identities
425                            nil nil nil 'notmuch-mua-sender-history
426                            (car notmuch-identities))
427     (let* ((name (notmuch-user-name))
428            (addrs (cons (notmuch-user-primary-email)
429                         (notmuch-user-other-email)))
430            (address
431             (ido-completing-read (concat "Sender address for " name ": ") addrs
432                                  nil nil nil 'notmuch-mua-sender-history
433                                  (car addrs))))
434       (message-make-from name address))))
435
436 (put 'notmuch-mua-new-mail 'notmuch-prefix-doc "... and prompt for sender")
437 (defun notmuch-mua-new-mail (&optional prompt-for-sender)
438   "Compose new mail.
439
440 If PROMPT-FOR-SENDER is non-nil, the user will be prompted for
441 the From: address first."
442   (interactive "P")
443   (let ((other-headers
444          (and (or prompt-for-sender notmuch-always-prompt-for-sender)
445               (list (cons 'From (notmuch-mua-prompt-for-sender))))))
446     (notmuch-mua-mail nil nil other-headers nil (notmuch-mua-get-switch-function))))
447
448 (defun notmuch-mua-new-forward-messages (messages &optional prompt-for-sender)
449   "Compose a new message forwarding MESSAGES.
450
451 If PROMPT-FOR-SENDER is non-nil, the user will be prompteed for
452 the From: address."
453   (let* ((other-headers
454           (and (or prompt-for-sender notmuch-always-prompt-for-sender)
455                (list (cons 'From (notmuch-mua-prompt-for-sender)))))
456          ;; Comes from the first message and is applied later.
457          forward-subject
458          ;; List of accumulated message-references of forwarded messages.
459          forward-references
460          ;; List of corresponding message-query.
461          forward-queries)
462     ;; Generate the template for the outgoing message.
463     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
464     (save-excursion
465       ;; Insert all of the forwarded messages.
466       (mapc (lambda (id)
467               (let ((temp-buffer (get-buffer-create
468                                   (concat "*notmuch-fwd-raw-" id "*"))))
469                 ;; Get the raw version of this message in the buffer.
470                 (with-current-buffer temp-buffer
471                   (erase-buffer)
472                   (let ((coding-system-for-read 'no-conversion))
473                     (call-process notmuch-command nil t nil
474                                   "show" "--format=raw" id))
475                   ;; Because we process the messages in reverse order,
476                   ;; always generate a forwarded subject, then use the
477                   ;; last (i.e. first) one.
478                   (setq forward-subject (message-make-forward-subject))
479                   (push (message-fetch-field "Message-ID") forward-references)
480                   (push id forward-queries))
481                 ;; Make a copy ready to be forwarded in the
482                 ;; composition buffer.
483                 (message-forward-make-body temp-buffer)
484                 ;; Kill the temporary buffer.
485                 (kill-buffer temp-buffer)))
486             ;; `message-forward-make-body' always puts the message at
487             ;; the top, so do them in reverse order.
488             (reverse messages))
489       ;; Add in the appropriate subject.
490       (save-restriction
491         (message-narrow-to-headers)
492         (message-remove-header "Subject")
493         (message-add-header (concat "Subject: " forward-subject))
494         (message-remove-header "References")
495         (message-add-header (concat "References: "
496                                     (mapconcat 'identity forward-references " "))))
497       ;; Create a buffer-local queue for tag changes triggered when
498       ;; sending the message.
499       (when notmuch-message-forwarded-tags
500         (setq-local notmuch-message-queued-tag-changes
501                     (cl-loop for id in forward-queries
502                              collect
503                              (cons id notmuch-message-forwarded-tags))))
504       ;; `message-forward-make-body' shows the User-agent header.  Hide
505       ;; it again.
506       (message-hide-headers)
507       (set-buffer-modified-p nil))))
508
509 (defun notmuch-mua-new-reply (query-string &optional prompt-for-sender reply-all)
510   "Compose a reply to the message identified by QUERY-STRING.
511
512 If PROMPT-FOR-SENDER is non-nil, the user will be prompted for
513 the From: address first.  If REPLY-ALL is non-nil, the message
514 will be addressed to all recipients of the source message."
515   ;; `select-active-regions' is t by default. The reply insertion code
516   ;; sets the region to the quoted message to make it easy to delete
517   ;; (kill-region or C-w). These two things combine to put the quoted
518   ;; message in the primary selection.
519   ;;
520   ;; This is not what the user wanted and is a privacy risk (accidental
521   ;; pasting of the quoted message). We can avoid some of the problems
522   ;; by let-binding select-active-regions to nil. This fixes if the
523   ;; primary selection was previously in a non-emacs window but not if
524   ;; it was in an emacs window. To avoid the problem in the latter case
525   ;; we deactivate mark.
526   (let ((sender (and prompt-for-sender
527                      (notmuch-mua-prompt-for-sender)))
528         (select-active-regions nil))
529     (notmuch-mua-reply query-string sender reply-all)
530     (deactivate-mark)))
531
532 (defun notmuch-mua-check-no-misplaced-secure-tag ()
533   "Query user if there is a misplaced secure mml tag.
534
535 Emacs message-send will (probably) ignore a secure mml tag unless
536 it is at the start of the body. Returns t if there is no such
537 tag, or the user confirms they mean it."
538   (save-excursion
539     (let ((body-start (progn (message-goto-body) (point))))
540       (goto-char (point-max))
541       (or
542        ;; We are always fine if there is no secure tag.
543        (not (search-backward "<#secure" nil 't))
544        ;; There is a secure tag, so it must be at the start of the
545        ;; body, with no secure tag earlier (i.e., in the headers).
546        (and (= (point) body-start)
547             (not (search-backward "<#secure" nil 't)))
548        ;; The user confirms they means it.
549        (yes-or-no-p "\
550 There is a <#secure> tag not at the start of the body. It is
551 likely that the message will be sent unsigned and unencrypted.
552 Really send? ")))))
553
554 (defun notmuch-mua-check-secure-tag-has-newline ()
555   "Query if the secure mml tag has a newline following it.
556
557 Emacs message-send will (probably) ignore a correctly placed
558 secure mml tag unless it is followed by a newline. Returns t if
559 any secure tag is followed by a newline, or the user confirms
560 they mean it."
561   (save-excursion
562     (message-goto-body)
563     (or
564      ;; There is no (correctly placed) secure tag.
565      (not (looking-at "<#secure"))
566      ;; The secure tag is followed by a newline.
567      (looking-at "<#secure[^\n>]*>\n")
568      ;; The user confirms they means it.
569      (yes-or-no-p "\
570 The <#secure> tag at the start of the body is not followed by a
571 newline. It is likely that the message will be sent unsigned and
572 unencrypted.  Really send? "))))
573
574 (defun notmuch-mua-send-common (arg &optional exit)
575   (interactive "P")
576   (run-hooks 'notmuch-mua-send-hook)
577   (when (and (notmuch-mua-check-no-misplaced-secure-tag)
578              (notmuch-mua-check-secure-tag-has-newline))
579     (cl-letf (((symbol-function 'message-do-fcc)
580                #'notmuch-maildir-message-do-fcc))
581       (if exit
582           (message-send-and-exit arg)
583         (message-send arg)))))
584
585 (defun notmuch-mua-send-and-exit (&optional arg)
586   (interactive "P")
587   (notmuch-mua-send-common arg 't))
588
589 (defun notmuch-mua-send (&optional arg)
590   (interactive "P")
591   (notmuch-mua-send-common arg))
592
593 (defun notmuch-mua-kill-buffer ()
594   (interactive)
595   (message-kill-buffer))
596
597 ;;
598
599 (define-mail-user-agent 'notmuch-user-agent
600   'notmuch-mua-mail 'notmuch-mua-send-and-exit
601   'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
602
603 ;; Add some more headers to the list that `message-mode' hides when
604 ;; composing a message.
605 (notmuch-mua-add-more-hidden-headers)
606
607 ;;
608
609 (provide 'notmuch-mua)
610
611 ;;; notmuch-mua.el ends here