]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/rmail.el
Update copyright year to 2016
[gnu-emacs] / lisp / mail / rmail.el
index 26c91bb26faf1469d99ee67adb4ccb904fdfb6ca..2eb19dfef1f2037fcd4cdbe6398ff9771bd33875 100644 (file)
@@ -1,6 +1,6 @@
 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs  -*- lexical-binding:t -*-
 
-;; Copyright (C) 1985-1988, 1993-1998, 2000-2015 Free Software
+;; Copyright (C) 1985-1988, 1993-1998, 2000-2016 Free Software
 ;; Foundation, Inc.
 
 ;; Maintainer: emacs-devel@gnu.org
@@ -98,7 +98,7 @@ its character representation and its display representation.")
 
 (defvar rmail-header-style 'normal
   "The current header display style choice, one of
-'normal (selected headers) or 'full (all headers).")
+`normal' (selected headers) or `full' (all headers).")
 
 (defvar rmail-mime-decoded nil
   "Non-nil if message has been processed by `rmail-show-mime-function'.")
@@ -298,7 +298,7 @@ mail URLs as the source mailbox.")
 ;;;###autoload
 (defun rmail-movemail-variant-p (&rest variants)
   "Return t if the current movemail variant is any of VARIANTS.
-Currently known variants are 'emacs and 'mailutils."
+Currently known variants are `emacs' and `mailutils'."
   (when (not rmail-movemail-variant-in-use)
     ;; Autodetect
     (setq rmail-movemail-variant-in-use (rmail-autodetect)))
@@ -316,7 +316,7 @@ Currently known variants are 'emacs and 'mailutils."
 If non-nil, this variable is used to identify the correspondent
 when receiving new mail.  If it matches the address of the sender,
 the recipient is taken as correspondent of a mail.
-If nil \(default value\), your `user-login-name' and `user-mail-address'
+If nil \(default value), your `user-login-name' and `user-mail-address'
 are used to exclude yourself as correspondent.
 
 Usually you don't have to set this variable, except if you collect mails
@@ -894,7 +894,7 @@ isn't provided."
       (error
        (display-warning
        'rmail
-       (format "Although MIME support is requested
+       (format-message "Although MIME support is requested
 through `rmail-enable-mime' being non-nil, the required feature
 `%s' (the value of `rmail-mime-feature')
 is not available in the current session.
@@ -2662,8 +2662,8 @@ Ask the user whether to add that list name to `mail-mailing-lists'."
                                      "\\>\\)"))
                          addr))
                        (y-or-n-p
-                        (format "Add `%s' to `mail-mailing-lists'? "
-                                addr)))
+                        (format-message "Add `%s' to `mail-mailing-lists'? "
+                                        addr)))
               (customize-save-variable 'mail-mailing-lists
                                        (cons addr mail-mailing-lists)))))))))
 
@@ -4508,9 +4508,78 @@ encoded string (and the same mask) will decode the string."
      (setq i (1+ i)))
    (concat string-vector)))
 
+(defun rmail-epa-decrypt-1 (mime)
+  "Decrypt a single GnuPG encrypted text in a message.
+The starting string of the encrypted text should have just been regexp-matched.
+Argument MIME is non-nil if this is a mime message."
+  (let* ((armor-start (match-beginning 0))
+         (armor-prefix (buffer-substring
+                        (line-beginning-position)
+                        armor-start))
+         (armor-end-regexp)
+         armor-end after-end
+         unquote)
+    (if (string-match "<pre>\\'" armor-prefix)
+        (setq armor-prefix ""))
+
+    (setq armor-end-regexp
+          (concat "^"
+                  armor-prefix
+                  "-----END PGP MESSAGE-----$"))
+    (setq armor-end (re-search-forward armor-end-regexp
+                                       nil t))
+
+    (unless armor-end
+      (error "Encryption armor beginning has no matching end"))
+    (goto-char armor-start)
+
+    ;; Because epa--find-coding-system-for-mime-charset not autoloaded.
+    (require 'epa)
+
+    ;; Advance over this armor.
+    (goto-char armor-end)
+    (setq after-end (- (point-max) armor-end))
+
+    (when mime
+      (save-excursion
+        (goto-char armor-start)
+        (re-search-backward "^--" nil t)
+        (save-restriction
+          (narrow-to-region (point) armor-start)
+
+          ;; Use the charset specified in the armor.
+          (unless coding-system-for-read
+            (if (re-search-forward "^[ \t]*Charset[ \t\n]*:[ \t\n]*\\(.*\\)" nil t)
+                (setq coding-system-for-read
+                      (epa--find-coding-system-for-mime-charset
+                       (intern (downcase (match-string 1)))))))
+
+          (goto-char (point-min))
+          (if (re-search-forward "^[ \t]*Content-transfer-encoding[ \t\n]*:[ \t\n]*quoted-printable[ \t]*$" nil t)
+              (setq unquote t)))))
+
+    (when unquote
+      (let ((inhibit-read-only t))
+        (mail-unquote-printable-region armor-start
+                                       (- (point-max) after-end))))
+
+    ;; Decrypt it, maybe in place, maybe making new buffer.
+    (epa-decrypt-region
+     armor-start (- (point-max) after-end)
+     ;; Call back this function to prepare the output.
+     (lambda ()
+       (let ((inhibit-read-only t))
+         (delete-region armor-start (- (point-max) after-end))
+         (goto-char armor-start)
+         (current-buffer))))
+
+    (list armor-start (- (point-max) after-end) mime
+          armor-end-regexp)))
+
 ;; Should this have a key-binding, or be in a menu?
 ;; There doesn't really seem to be an appropriate menu.
 ;; Eg the edit command is not in a menu either.
+
 (defun rmail-epa-decrypt ()
   "Decrypt GnuPG or OpenPGP armors in current message."
   (interactive)
@@ -4519,12 +4588,14 @@ encoded string (and the same mask) will decode the string."
   ;; change it in one of the calls to `epa-decrypt-region'.
 
   (save-excursion
-    (let (decrypts (mime (rmail-mime-message-p)))
+    (let (decrypts (mime (rmail-mime-message-p))
+                   mime-disabled)
       (goto-char (point-min))
 
       ;; Turn off mime processing.
       (when (and mime
                 (not (get-text-property (point-min) 'rmail-mime-hidden)))
+        (setq mime-disabled t)
        (rmail-mime))
 
       ;; Now find all armored messages in the buffer
@@ -4532,74 +4603,12 @@ encoded string (and the same mask) will decode the string."
       (goto-char (point-min))
       (while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t)
        (let ((coding-system-for-read coding-system-for-read)
-             (case-fold-search t)
-             unquote
-             armor-start armor-prefix armor-end-regexp armor-end after-end)
-
-         (setq armor-start (match-beginning 0)
-               armor-prefix (buffer-substring
-                             (line-beginning-position)
-                             armor-start))
-         (if (string-match "<pre>\\'" armor-prefix)
-             (setq armor-prefix ""))
-
-         (setq armor-end-regexp
-               (concat "^"
-                       armor-prefix
-                       "-----END PGP MESSAGE-----$"))
-         (setq armor-end (re-search-forward armor-end-regexp
-                                            nil t))
-
-         (unless armor-end
-           (error "Encryption armor beginning has no matching end"))
-         (goto-char armor-start)
-
-         ;; Because epa--find-coding-system-for-mime-charset not autoloaded.
-         (require 'epa)
-
-         ;; Advance over this armor.
-         (goto-char armor-end)
-         (setq after-end (- (point-max) armor-end))
-
-         (when mime
-           (save-excursion
-             (goto-char armor-start)
-             (re-search-backward "^--" nil t)
-             (save-restriction
-               (narrow-to-region (point) armor-start)
-
-               ;; Use the charset specified in the armor.
-               (unless coding-system-for-read
-                 (if (re-search-forward "^[ \t]*Charset[ \t\n]*:[ \t\n]*\\(.*\\)" nil t)
-                     (setq coding-system-for-read
-                           (epa--find-coding-system-for-mime-charset
-                            (intern (downcase (match-string 1)))))))
-
-               (goto-char (point-min))
-               (if (re-search-forward "^[ \t]*Content-transfer-encoding[ \t\n]*:[ \t\n]*quoted-printable[ \t]*$" nil t)
-                   (setq unquote t)))))
-
-         (when unquote
-           (let ((inhibit-read-only t))
-             (mail-unquote-printable-region armor-start
-                                            (- (point-max) after-end))))
-
-         ;; Decrypt it, maybe in place, maybe making new buffer.
-         (epa-decrypt-region
-          armor-start (- (point-max) after-end)
-          ;; Call back this function to prepare the output.
-          (lambda ()
-            (let ((inhibit-read-only t))
-              (delete-region armor-start (- (point-max) after-end))
-              (goto-char armor-start)
-              (current-buffer))))
-
-         (push (list armor-start (- (point-max) after-end) mime
-                     armor-end-regexp)
-               decrypts)))
+             (case-fold-search t))
 
-      (unless decrypts
-       (error "Nothing to decrypt"))
+          (push (rmail-epa-decrypt-1 mime) decrypts)))
+
+      (when (and decrypts (eq major-mode 'rmail-mode))
+        (rmail-add-label "decrypt"))
 
       (when (and decrypts (rmail-buffers-swapped-p))
        (when (y-or-n-p "Replace the original message? ")
@@ -4639,8 +4648,31 @@ encoded string (and the same mask) will decode the string."
                                (let ((value (match-string 0)))
                                  (unless (member value '("text/plain" "text/html"))
                                    (replace-match "text/plain"))))))))
-                     ))))))))))
+                     )))))))
+
+      (when (and (null decrypts)
+                 mime mime-disabled)
+        ;; Re-enable mime processing.
+       (rmail-mime)
+        ;; Find each Show button and show that part.
+       (while (search-forward " Show " nil t)
+         (forward-char -2)
+         (let ((rmail-mime-render-html-function nil)
+               (entity (get-text-property (point) 'rmail-mime-entity)))
+            (unless (and (not (stringp entity))
+                         (rmail-mime-entity-truncated entity))
+              (push-button))))
+        (goto-char (point-min))
+        (while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t)
+          (let ((coding-system-for-read coding-system-for-read)
+                (case-fold-search t))
+            (push (rmail-epa-decrypt-1 mime) decrypts)))
+
+        )
+
+      (unless decrypts
+       (error "Nothing to decrypt")))))
+
 \f
 ;;;;  Desktop support
 
@@ -4746,7 +4778,7 @@ With prefix argument N moves forward N messages with these labels.
 
 ;;;***
 \f
-;;;### (autoloads nil "rmailmm" "rmailmm.el" "e5b89eed8afb278cc8881f2208382c7c")
+;;;### (autoloads nil "rmailmm" "rmailmm.el" "36f518e036612a33eb436cb267fd39c7")
 ;;; Generated autoloads from rmailmm.el
 
 (autoload 'rmail-mime "rmailmm" "\
@@ -4890,7 +4922,7 @@ SENDERS is a regular expression.
 
 ;;;***
 \f
-;;;### (autoloads nil "undigest" "undigest.el" "912d4d3bf762991df5d4d02f42358025")
+;;;### (autoloads nil "undigest" "undigest.el" "c0ddfad4fe34ef9c1e790c2cc72b571d")
 ;;; Generated autoloads from undigest.el
 
 (autoload 'undigestify-rmail-message "undigest" "\