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