]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-mua.el
emacs docstrings: consistent indentation, newlines, periods
[notmuch] / emacs / notmuch-mua.el
index 2f0de92c6ec28f7fb511a1938698685fc41c17c8..1efc88ea4020ceaef8b667e0d68c81a472b478dd 100644 (file)
@@ -21,6 +21,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib))
+
 (require 'message)
 (require 'mm-view)
 (require 'format-spec)
@@ -30,8 +32,6 @@
 (require 'notmuch-draft)
 (require 'notmuch-message)
 
-(eval-when-compile (require 'cl))
-
 (declare-function notmuch-show-insert-body "notmuch-show" (msg body depth))
 (declare-function notmuch-fcc-header-setup "notmuch-maildir-fcc" ())
 (declare-function notmuch-maildir-message-do-fcc "notmuch-maildir-fcc" ())
@@ -121,7 +121,9 @@ multiple parts get a header."
   "Message body text indicating that an attachment is expected.
 
 This is not used unless `notmuch-mua-attachment-check' is added
-to `notmuch-mua-send-hook'.")
+to `notmuch-mua-send-hook'."
+  :type 'regexp
+  :group 'notmuch-send)
 
 ;;
 
@@ -135,17 +137,21 @@ Typically this is added to `notmuch-mua-send-hook'."
         ;; When the message mentions attachment...
         (save-excursion
           (message-goto-body)
-          (loop while (re-search-forward notmuch-mua-attachment-regexp (point-max) t)
-                ;; For every instance of the "attachment" string
-                ;; found, examine the text properties. If the text
-                ;; has either a `face' or `syntax-table' property
-                ;; then it is quoted text and should *not* cause the
-                ;; user to be asked about a missing attachment.
-                if (let ((props (text-properties-at (match-beginning 0))))
-                     (not (or (memq 'syntax-table props)
-                              (memq 'face props))))
-                return t
-                finally return nil))
+          ;; Limit search from reaching other possible parts of the message
+          (let ((search-limit (search-forward "\n<#" nil t)))
+            (message-goto-body)
+            (cl-loop while (re-search-forward notmuch-mua-attachment-regexp
+                                              search-limit t)
+                     ;; For every instance of the "attachment" string
+                     ;; found, examine the text properties. If the text
+                     ;; has either a `face' or `syntax-table' property
+                     ;; then it is quoted text and should *not* cause the
+                     ;; user to be asked about a missing attachment.
+                     if (let ((props (text-properties-at (match-beginning 0))))
+                          (not (or (memq 'syntax-table props)
+                                   (memq 'face props))))
+                     return t
+                     finally return nil)))
         ;; ...but doesn't have a part with a filename...
         (save-excursion
           (message-goto-body)
@@ -198,11 +204,11 @@ Typically this is added to `notmuch-mua-send-hook'."
 
 (defun notmuch-mua-reply-crypto (parts)
   "Add mml sign-encrypt flag if any part of original message is encrypted."
-  (loop for part in parts
-       if (notmuch-match-content-type (plist-get part :content-type) "multipart/encrypted")
-         do (mml-secure-message-sign-encrypt)
-       else if (notmuch-match-content-type (plist-get part :content-type) "multipart/*")
-         do (notmuch-mua-reply-crypto (plist-get part :content))))
+  (cl-loop for part in parts
+          if (notmuch-match-content-type (plist-get part :content-type) "multipart/encrypted")
+            do (mml-secure-message-sign-encrypt)
+          else if (notmuch-match-content-type (plist-get part :content-type) "multipart/*")
+            do (notmuch-mua-reply-crypto (plist-get part :content))))
 
 ;; There is a bug in emacs 23's message.el that results in a newline
 ;; not being inserted after the References header, so the next header
@@ -247,14 +253,14 @@ Typically this is added to `notmuch-mua-send-hook'."
        ;; We modify message-header-format-alist to get around a bug in message.el.
        ;; See the comment above on notmuch-mua-insert-references.
        (let ((message-header-format-alist
-              (loop for pair in message-header-format-alist
-                    if (eq (car pair) 'References)
-                    collect (cons 'References
-                                  (apply-partially
-                                   'notmuch-mua-insert-references
-                                   (cdr pair)))
-                    else
-                    collect pair)))
+              (cl-loop for pair in message-header-format-alist
+                       if (eq (car pair) 'References)
+                       collect (cons 'References
+                                     (apply-partially
+                                      'notmuch-mua-insert-references
+                                      (cdr pair)))
+                       else
+                       collect pair)))
          (notmuch-mua-mail (plist-get reply-headers :To)
                            (notmuch-sanitize (plist-get reply-headers :Subject))
                            (notmuch-headers-plist-to-alist reply-headers)
@@ -304,10 +310,10 @@ Typically this is added to `notmuch-mua-send-hook'."
                       ;; Don't indent multipart sub-parts.
                       (notmuch-show-indent-multipart nil))
                    ;; We don't want sigstatus buttons (an information leak and usually wrong anyway).
-                   (letf (((symbol-function 'notmuch-crypto-insert-sigstatus-button) #'ignore)
-                          ((symbol-function 'notmuch-crypto-insert-encstatus-button) #'ignore))
-                         (notmuch-show-insert-body original (plist-get original :body) 0)
-                         (buffer-substring-no-properties (point-min) (point-max))))))
+                   (cl-letf (((symbol-function 'notmuch-crypto-insert-sigstatus-button) #'ignore)
+                             ((symbol-function 'notmuch-crypto-insert-encstatus-button) #'ignore))
+                     (notmuch-show-insert-body original (plist-get original :body) 0)
+                     (buffer-substring-no-properties (point-min) (point-max))))))
 
        (set-mark (point))
        (goto-char start)
@@ -328,7 +334,7 @@ Typically this is added to `notmuch-mua-send-hook'."
   (set-buffer-modified-p nil))
 
 (define-derived-mode notmuch-message-mode message-mode "Message[Notmuch]"
-  "Notmuch message composition mode. Mostly like `message-mode'"
+  "Notmuch message composition mode. Mostly like `message-mode'."
   (notmuch-address-setup))
 
 (put 'notmuch-message-mode 'flyspell-mode-predicate 'mail-mode-flyspell-verify)
@@ -478,7 +484,8 @@ the From: address."
            (list (cons 'From (notmuch-mua-prompt-for-sender)))))
         forward-subject  ;; Comes from the first message and is
                          ;; applied later.
-        forward-references) ;; List of accumulated message-references of forwarded messages
+        forward-references ;; List of accumulated message-references of forwarded messages
+        forward-queries) ;; List of corresponding message-query
 
     ;; Generate the template for the outgoing message.
     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
@@ -497,7 +504,8 @@ the From: address."
                  ;; always generate a forwarded subject, then use the
                  ;; last (i.e. first) one.
                  (setq forward-subject (message-make-forward-subject))
-                 (push (message-fetch-field "Message-ID") forward-references))
+                 (push (message-fetch-field "Message-ID") forward-references)
+                 (push id forward-queries))
                ;; Make a copy ready to be forwarded in the
                ;; composition buffer.
                (message-forward-make-body temp-buffer)
@@ -516,6 +524,13 @@ the From: address."
        (message-add-header (concat "References: "
                                    (mapconcat 'identity forward-references " "))))
 
+      ;; Create a buffer-local queue for tag changes triggered when sending the message
+      (when notmuch-message-forwarded-tags
+       (setq-local notmuch-message-queued-tag-changes
+                   (cl-loop for id in forward-queries
+                            collect
+                            (cons id notmuch-message-forwarded-tags))))
+
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
       (message-hide-headers)
@@ -594,10 +609,10 @@ unencrypted.  Really send? "))))
   (run-hooks 'notmuch-mua-send-hook)
   (when (and (notmuch-mua-check-no-misplaced-secure-tag)
             (notmuch-mua-check-secure-tag-has-newline))
-    (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
-         (if exit
-             (message-send-and-exit arg)
-           (message-send arg)))))
+    (cl-letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
+      (if exit
+         (message-send-and-exit arg)
+       (message-send arg)))))
 
 (defun notmuch-mua-send-and-exit (&optional arg)
   (interactive "P")