]> git.notmuchmail.org Git - notmuch/blob - emacs/notmuch-mua.el
Merge branch 'release'
[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.
66 If this is `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 list."
77   :type '(repeat string)
78   :group 'notmuch-send)
79
80 (defgroup notmuch-reply nil
81   "Replying to messages in notmuch"
82   :group 'notmuch)
83
84 (defcustom notmuch-mua-cite-function 'message-cite-original
85   "Function for citing an original message.
86
87 Predefined functions include `message-cite-original' and
88 `message-cite-original-without-signature'.  Note that these
89 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 `notmuch-mua-compose-in'."
171   (when (or (eq notmuch-mua-compose-in 'new-frame)
172             (eq notmuch-mua-compose-in 'new-window))
173     (set-window-dedicated-p (selected-window) t)))
174
175 (defun notmuch-mua-user-agent-full ()
176   "Generate a `User-Agent:' string suitable for notmuch."
177   (concat (notmuch-mua-user-agent-notmuch)
178           " "
179           (notmuch-mua-user-agent-emacs)))
180
181 (defun notmuch-mua-user-agent-notmuch ()
182   "Generate a `User-Agent:' string suitable for notmuch."
183   (let ((notmuch-version (if (string= notmuch-emacs-version "unknown")
184                              (notmuch-cli-version)
185                            notmuch-emacs-version)))
186     (concat "Notmuch/" notmuch-version " (https://notmuchmail.org)")))
187
188 (defun notmuch-mua-user-agent-emacs ()
189   "Generate a `User-Agent:' string suitable for notmuch."
190   (concat "Emacs/" emacs-version " (" system-configuration ")"))
191
192 (defun notmuch-mua-add-more-hidden-headers ()
193   "Add some headers to the list that are hidden by default."
194   (mapc (lambda (header)
195           (unless (member header message-hidden-headers)
196             (push header message-hidden-headers)))
197         notmuch-mua-hidden-headers))
198
199 (defun notmuch-mua-reply-crypto (parts)
200   "Add mml sign-encrypt flag if any part of original message is encrypted."
201   (cl-loop for part in parts
202            if (notmuch-match-content-type (plist-get part :content-type)
203                                           "multipart/encrypted")
204            do (mml-secure-message-sign-encrypt)
205            else if (notmuch-match-content-type (plist-get part :content-type)
206                                                "multipart/*")
207            do (notmuch-mua-reply-crypto (plist-get part :content))))
208
209 ;; There is a bug in Emacs' message.el that results in a newline
210 ;; not being inserted after the References header, so the next header
211 ;; is concatenated to the end of it. This function fixes the problem,
212 ;; while guarding against the possibility that some current or future
213 ;; version of emacs has the bug fixed.
214 (defun notmuch-mua-insert-references (original-func header references)
215   (funcall original-func header references)
216   (unless (bolp) (insert "\n")))
217
218 (defun notmuch-mua-reply (query-string &optional sender reply-all)
219   (let ((args '("reply" "--format=sexp" "--format-version=4"))
220         (process-crypto notmuch-show-process-crypto)
221         reply
222         original)
223     (when process-crypto
224       (setq args (append args '("--decrypt=true"))))
225     (if reply-all
226         (setq args (append args '("--reply-to=all")))
227       (setq args (append args '("--reply-to=sender"))))
228     (setq args (append args (list query-string)))
229     ;; Get the reply object as SEXP, and parse it into an elisp object.
230     (setq reply (apply #'notmuch-call-notmuch-sexp args))
231     ;; Extract the original message to simplify the following code.
232     (setq original (plist-get reply :original))
233     ;; Extract the headers of both the reply and the original message.
234     (let* ((original-headers (plist-get original :headers))
235            (reply-headers (plist-get reply :reply-headers)))
236       ;; If sender is non-nil, set the From: header to its value.
237       (when sender
238         (plist-put reply-headers :From sender))
239       (let
240           ;; Overlay the composition window on that being used to read
241           ;; the original message.
242           ((same-window-regexps '("\\*mail .*")))
243         ;; We modify message-header-format-alist to get around
244         ;; a bug in message.el.  See the comment above on
245         ;; notmuch-mua-insert-references.
246         (let ((message-header-format-alist
247                (cl-loop for pair in message-header-format-alist
248                         if (eq (car pair) 'References)
249                         collect (cons 'References
250                                       (apply-partially
251                                        'notmuch-mua-insert-references
252                                        (cdr pair)))
253                         else
254                         collect pair)))
255           (notmuch-mua-mail (plist-get reply-headers :To)
256                             (notmuch-sanitize (plist-get reply-headers :Subject))
257                             (notmuch-headers-plist-to-alist reply-headers)
258                             nil (notmuch-mua-get-switch-function))))
259       ;; Create a buffer-local queue for tag changes triggered when
260       ;; sending the reply.
261       (when notmuch-message-replied-tags
262         (setq-local notmuch-message-queued-tag-changes
263                     (list (cons query-string notmuch-message-replied-tags))))
264       ;; Insert the message body - but put it in front of the signature
265       ;; if one is present, and after any other content
266       ;; message*setup-hooks may have added to the message body already.
267       (save-restriction
268         (message-goto-body)
269         (narrow-to-region (point) (point-max))
270         (goto-char (point-max))
271         (if (re-search-backward message-signature-separator nil t)
272             (when message-signature-insert-empty-line
273               (forward-line -1))
274           (goto-char (point-max))))
275       (let ((from (plist-get original-headers :From))
276             (date (plist-get original-headers :Date))
277             (start (point)))
278         ;; notmuch-mua-cite-function constructs a citation line based
279         ;; on the From and Date headers of the original message, which
280         ;; are assumed to be in the buffer.
281         (insert "From: " from "\n")
282         (insert "Date: " date "\n\n")
283         (insert
284          (with-temp-buffer
285            (let
286                ;; Don't attempt to clean up messages, excerpt
287                ;; citations, etc. in the original message before
288                ;; quoting.
289                ((notmuch-show-insert-text/plain-hook nil)
290                 ;; Don't omit long parts.
291                 (notmuch-show-max-text-part-size 0)
292                 ;; Insert headers for parts as appropriate for replying.
293                 (notmuch-show-insert-header-p-function
294                  notmuch-mua-reply-insert-header-p-function)
295                 ;; Ensure that any encrypted parts are
296                 ;; decrypted during the generation of the reply
297                 ;; text.
298                 (notmuch-show-process-crypto process-crypto)
299                 ;; Don't indent multipart sub-parts.
300                 (notmuch-show-indent-multipart nil))
301              ;; We don't want sigstatus buttons (an information leak and usually wrong anyway).
302              (cl-letf (((symbol-function 'notmuch-crypto-insert-sigstatus-button) #'ignore)
303                        ((symbol-function 'notmuch-crypto-insert-encstatus-button) #'ignore))
304                (notmuch-show-insert-body original (plist-get original :body) 0)
305                (buffer-substring-no-properties (point-min) (point-max))))))
306         (set-mark (point))
307         (goto-char start)
308         ;; Quote the original message according to the user's configured style.
309         (funcall notmuch-mua-cite-function)))
310     ;; Crypto processing based crypto content of the original message
311     (when process-crypto
312       (notmuch-mua-reply-crypto (plist-get original :body))))
313   ;; Push mark right before signature, if any.
314   (message-goto-signature)
315   (unless (eobp)
316     (end-of-line -1))
317   (push-mark)
318   (message-goto-body)
319   (set-buffer-modified-p nil))
320
321 (defvar notmuch-message-mode-map
322   (let ((map (make-sparse-keymap)))
323     (define-key map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
324     (define-key map (kbd "C-c C-s") #'notmuch-mua-send)
325     (define-key map (kbd "C-c C-p") #'notmuch-draft-postpone)
326     (define-key map (kbd "C-x C-s") #'notmuch-draft-save)
327     map)
328   "Keymap for `notmuch-message-mode'.")
329
330 (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
331   "Notmuch message composition mode. Mostly like `message-mode'."
332   (notmuch-address-setup))
333
334 (put 'notmuch-message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
335
336 (defun notmuch-mua-pop-to-buffer (name switch-function)
337   "Pop to buffer NAME, and warn if it already exists and is modified.
338 Like `message-pop-to-buffer' but enable `notmuch-message-mode'
339 instead of `message-mode' and SWITCH-FUNCTION is mandatory."
340   (let ((buffer (get-buffer name)))
341     (if (and buffer
342              (buffer-name buffer))
343         (let ((window (get-buffer-window buffer 0)))
344           (if window
345               ;; Raise the frame already displaying the message buffer.
346               (progn
347                 (select-frame-set-input-focus (window-frame window))
348                 (select-window window))
349             (funcall switch-function buffer)
350             (set-buffer buffer))
351           (when (and (buffer-modified-p)
352                      (not (prog1
353                               (y-or-n-p
354                                "Message already being composed; erase? ")
355                             (message nil))))
356             (error "Message being composed")))
357       (funcall switch-function name)
358       (set-buffer name))
359     (erase-buffer)
360     (notmuch-message-mode)))
361
362 (defun notmuch-mua-mail (&optional to subject other-headers continue
363                                    switch-function yank-action send-actions
364                                    return-action &rest ignored)
365   "Invoke the notmuch mail composition window."
366   (interactive)
367   (when notmuch-mua-user-agent-function
368     (let ((user-agent (funcall notmuch-mua-user-agent-function)))
369       (unless (string= "" user-agent)
370         (push (cons 'User-Agent user-agent) other-headers))))
371   (unless (assq 'From other-headers)
372     (push (cons 'From (message-make-from
373                        (notmuch-user-name)
374                        (notmuch-user-primary-email)))
375           other-headers))
376   (notmuch-mua-pop-to-buffer (message-buffer-name "mail" to)
377                              (or switch-function
378                                  (notmuch-mua-get-switch-function)))
379   (let ((headers
380          (append
381           ;; The following is copied from `message-mail'
382           `((To . ,(or to "")) (Subject . ,(or subject "")))
383           ;; C-h f compose-mail says that headers should be specified as
384           ;; (string . value); however all the rest of message expects
385           ;; headers to be symbols, not strings (eg message-header-format-alist).
386           ;; https://lists.gnu.org/archive/html/emacs-devel/2011-01/msg00337.html
387           ;; We need to convert any string input, eg from rmail-start-mail.
388           (dolist (h other-headers other-headers)
389             (when (stringp (car h))
390               (setcar h (intern (capitalize (car h))))))))
391         ;; Cause `message-setup-1' to do things relevant for mail,
392         ;; such as observe `message-default-mail-headers'.
393         (message-this-is-mail t))
394     (message-setup-1 headers yank-action send-actions return-action))
395   (notmuch-fcc-header-setup)
396   (message-sort-headers)
397   (message-hide-headers)
398   (set-buffer-modified-p nil)
399   (notmuch-mua-maybe-set-window-dedicated)
400   (message-goto-to))
401
402 (defcustom notmuch-identities nil
403   "Identities that can be used as the From: address when composing a new message.
404
405 If this variable is left unset, then a list will be constructed from the
406 name and addresses configured in the notmuch configuration file."
407   :type '(repeat string)
408   :group 'notmuch-send)
409
410 (defcustom notmuch-always-prompt-for-sender nil
411   "Always prompt for the From: address when composing or forwarding a message.
412
413 This is not taken into account when replying to a message, because in that case
414 the From: header is already filled in by notmuch."
415   :type 'boolean
416   :group 'notmuch-send)
417
418 (defvar notmuch-mua-sender-history nil)
419
420 (defun notmuch-mua-prompt-for-sender ()
421   "Prompt for a sender from the user's configured identities."
422   (if notmuch-identities
423       (ido-completing-read "Send mail from: " notmuch-identities
424                            nil nil nil 'notmuch-mua-sender-history
425                            (car notmuch-identities))
426     (let* ((name (notmuch-user-name))
427            (addrs (cons (notmuch-user-primary-email)
428                         (notmuch-user-other-email)))
429            (address
430             (ido-completing-read (concat "Sender address for " name ": ") addrs
431                                  nil nil nil 'notmuch-mua-sender-history
432                                  (car addrs))))
433       (message-make-from name address))))
434
435 (put 'notmuch-mua-new-mail 'notmuch-prefix-doc "... and prompt for sender")
436 (defun notmuch-mua-new-mail (&optional prompt-for-sender)
437   "Compose new mail.
438
439 If PROMPT-FOR-SENDER is non-nil, the user will be prompted for
440 the From: address first."
441   (interactive "P")
442   (let ((other-headers
443          (and (or prompt-for-sender notmuch-always-prompt-for-sender)
444               (list (cons 'From (notmuch-mua-prompt-for-sender))))))
445     (notmuch-mua-mail nil nil other-headers nil (notmuch-mua-get-switch-function))))
446
447 (defun notmuch-mua-new-forward-messages (messages &optional prompt-for-sender)
448   "Compose a new message forwarding MESSAGES.
449
450 If PROMPT-FOR-SENDER is non-nil, the user will be prompteed for
451 the From: address."
452   (let* ((other-headers
453           (and (or prompt-for-sender notmuch-always-prompt-for-sender)
454                (list (cons 'From (notmuch-mua-prompt-for-sender)))))
455          ;; Comes from the first message and is applied later.
456          forward-subject
457          ;; List of accumulated message-references of forwarded messages.
458          forward-references
459          ;; List of corresponding message-query.
460          forward-queries)
461     ;; Generate the template for the outgoing message.
462     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
463     (save-excursion
464       ;; Insert all of the forwarded messages.
465       (mapc (lambda (id)
466               (let ((temp-buffer (get-buffer-create
467                                   (concat "*notmuch-fwd-raw-" id "*"))))
468                 ;; Get the raw version of this message in the buffer.
469                 (with-current-buffer temp-buffer
470                   (erase-buffer)
471                   (let ((coding-system-for-read 'no-conversion))
472                     (call-process notmuch-command nil t nil
473                                   "show" "--format=raw" id))
474                   ;; Because we process the messages in reverse order,
475                   ;; always generate a forwarded subject, then use the
476                   ;; last (i.e. first) one.
477                   (setq forward-subject (message-make-forward-subject))
478                   (push (message-fetch-field "Message-ID") forward-references)
479                   (push id forward-queries))
480                 ;; Make a copy ready to be forwarded in the
481                 ;; composition buffer.
482                 (message-forward-make-body temp-buffer)
483                 ;; Kill the temporary buffer.
484                 (kill-buffer temp-buffer)))
485             ;; `message-forward-make-body' always puts the message at
486             ;; the top, so do them in reverse order.
487             (reverse messages))
488       ;; Add in the appropriate subject.
489       (save-restriction
490         (message-narrow-to-headers)
491         (message-remove-header "Subject")
492         (message-add-header (concat "Subject: " forward-subject))
493         (message-remove-header "References")
494         (message-add-header (concat "References: "
495                                     (mapconcat 'identity forward-references " "))))
496       ;; Create a buffer-local queue for tag changes triggered when
497       ;; sending the message.
498       (when notmuch-message-forwarded-tags
499         (setq-local notmuch-message-queued-tag-changes
500                     (cl-loop for id in forward-queries
501                              collect
502                              (cons id notmuch-message-forwarded-tags))))
503       ;; `message-forward-make-body' shows the User-agent header.  Hide
504       ;; it again.
505       (message-hide-headers)
506       (set-buffer-modified-p nil))))
507
508 (defun notmuch-mua-new-reply (query-string &optional prompt-for-sender reply-all)
509   "Compose a reply to the message identified by QUERY-STRING.
510
511 If PROMPT-FOR-SENDER is non-nil, the user will be prompted for
512 the From: address first.  If REPLY-ALL is non-nil, the message
513 will be addressed to all recipients of the source message."
514   ;; `select-active-regions' is t by default. The reply insertion code
515   ;; sets the region to the quoted message to make it easy to delete
516   ;; (kill-region or C-w). These two things combine to put the quoted
517   ;; message in the primary selection.
518   ;;
519   ;; This is not what the user wanted and is a privacy risk (accidental
520   ;; pasting of the quoted message). We can avoid some of the problems
521   ;; by let-binding select-active-regions to nil. This fixes if the
522   ;; primary selection was previously in a non-emacs window but not if
523   ;; it was in an emacs window. To avoid the problem in the latter case
524   ;; we deactivate mark.
525   (let ((sender (and prompt-for-sender
526                      (notmuch-mua-prompt-for-sender)))
527         (select-active-regions nil))
528     (notmuch-mua-reply query-string sender reply-all)
529     (deactivate-mark)))
530
531 (defun notmuch-mua-check-no-misplaced-secure-tag ()
532   "Query user if there is a misplaced secure mml tag.
533
534 Emacs message-send will (probably) ignore a secure mml tag unless
535 it is at the start of the body. Returns t if there is no such
536 tag, or the user confirms they mean it."
537   (save-excursion
538     (let ((body-start (progn (message-goto-body) (point))))
539       (goto-char (point-max))
540       (or
541        ;; We are always fine if there is no secure tag.
542        (not (search-backward "<#secure" nil t))
543        ;; There is a secure tag, so it must be at the start of the
544        ;; body, with no secure tag earlier (i.e., in the headers).
545        (and (= (point) body-start)
546             (not (search-backward "<#secure" nil t)))
547        ;; The user confirms they means it.
548        (yes-or-no-p "\
549 There is a <#secure> tag not at the start of the body. It is
550 likely that the message will be sent unsigned and unencrypted.
551 Really send? ")))))
552
553 (defun notmuch-mua-check-secure-tag-has-newline ()
554   "Query if the secure mml tag has a newline following it.
555
556 Emacs message-send will (probably) ignore a correctly placed
557 secure mml tag unless it is followed by a newline. Returns t if
558 any secure tag is followed by a newline, or the user confirms
559 they mean it."
560   (save-excursion
561     (message-goto-body)
562     (or
563      ;; There is no (correctly placed) secure tag.
564      (not (looking-at "<#secure"))
565      ;; The secure tag is followed by a newline.
566      (looking-at "<#secure[^\n>]*>\n")
567      ;; The user confirms they means it.
568      (yes-or-no-p "\
569 The <#secure> tag at the start of the body is not followed by a
570 newline. It is likely that the message will be sent unsigned and
571 unencrypted.  Really send? "))))
572
573 (defun notmuch-mua-send-common (arg &optional exit)
574   (interactive "P")
575   (run-hooks 'notmuch-mua-send-hook)
576   (when (and (notmuch-mua-check-no-misplaced-secure-tag)
577              (notmuch-mua-check-secure-tag-has-newline))
578     (cl-letf (((symbol-function 'message-do-fcc)
579                #'notmuch-maildir-message-do-fcc))
580       (if exit
581           (message-send-and-exit arg)
582         (message-send arg)))))
583
584 (defun notmuch-mua-send-and-exit (&optional arg)
585   (interactive "P")
586   (notmuch-mua-send-common arg t))
587
588 (defun notmuch-mua-send (&optional arg)
589   (interactive "P")
590   (notmuch-mua-send-common arg))
591
592 (defun notmuch-mua-kill-buffer ()
593   (interactive)
594   (message-kill-buffer))
595
596 ;;
597
598 (define-mail-user-agent 'notmuch-user-agent
599   'notmuch-mua-mail 'notmuch-mua-send-and-exit
600   'notmuch-mua-kill-buffer 'notmuch-mua-send-hook)
601
602 ;; Add some more headers to the list that `message-mode' hides when
603 ;; composing a message.
604 (notmuch-mua-add-more-hidden-headers)
605
606 ;;
607
608 (provide 'notmuch-mua)
609
610 ;;; notmuch-mua.el ends here