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