Function: rmail-epa-decrypt-1

rmail-epa-decrypt-1 is a byte-compiled function defined in rmail.el.gz.

Signature

(rmail-epa-decrypt-1 MIME)

Documentation

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.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rmail.el.gz
(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"))
    (setq armor-start (move-marker (make-marker) armor-start))
    (setq armor-end (move-marker (make-marker) armor-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))))

    (condition-case nil
	(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))))
      (error nil))

    (list armor-start (- (point-max) after-end) mime
          armor-end-regexp
          (buffer-substring armor-start (- (point-max) after-end)))))