Function: epa-mail-encrypt

epa-mail-encrypt is an autoloaded, interactive and byte-compiled function defined in epa-mail.el.gz.

Signature

(epa-mail-encrypt &optional RECIPIENTS SIGNERS)

Documentation

Encrypt the outgoing mail message in the current buffer.

Takes the recipients from the text in the header in the buffer and translates them through epa-mail-aliases. With prefix argument, asks you to select among them interactively and also whether and how to sign.

Called from Lisp, the optional argument RECIPIENTS is a list of recipient addresses, t to perform symmetric encryption, or nil meaning use the defaults.

SIGNERS is a list of keys to sign the message with.

Probably introduced at or before Emacs version 24.4.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/epa-mail.el.gz
;;;###autoload
(defun epa-mail-encrypt (&optional recipients signers)
  "Encrypt the outgoing mail message in the current buffer.
Takes the recipients from the text in the header in the buffer
and translates them through `epa-mail-aliases'.
With prefix argument, asks you to select among them interactively
and also whether and how to sign.

Called from Lisp, the optional argument RECIPIENTS is a list
of recipient addresses, t to perform symmetric encryption,
or nil meaning use the defaults.

SIGNERS is a list of keys to sign the message with."
  (interactive
   (let ((verbose current-prefix-arg)
	 (context (epg-make-context epa-protocol)))
     (list (if verbose
	       (or (epa-select-keys
		    context
		    "Select recipients for encryption.
If no one is selected, symmetric encryption will be performed.  "
		    (epa-mail-default-recipients))
		   t))
	   (and verbose (y-or-n-p "Sign? ")
		(epa-select-keys context
				 "Select keys for signing.  ")))))
  (let (start recipient-keys default-recipients)
    (save-excursion
      (setq recipient-keys
	    (cond ((eq recipients t)
		   nil)
		  (recipients recipients)
		  (t
		   (setq default-recipients
			 (epa-mail-default-recipients))
		   ;; Convert recipients to keys.
		   (apply
		    'nconc
		    (mapcar
		     (lambda (recipient)
		       (let ((recipient-key
			      (epa-mail--find-usable-key
			       (epg-list-keys
				(epg-make-context epa-protocol)
				(if (string-search "@" recipient)
				    (concat "<" recipient ">")
				  recipient))
			       'encrypt)))
			 (unless (or recipient-key
                                     (and epa-mail-offer-skip
                                          (y-or-n-p
                                           (format
                                            "No public key for %s; skip it? "
                                            recipient)))
                                     )
			   (error "No public key for %s" recipient))
			 (if recipient-key (list recipient-key))))
		       default-recipients)))))

      (goto-char (point-min))
      (rfc822-goto-eoh)
      (unless (eobp)
	(forward-line))
      (setq start (point))

      (setq epa-last-coding-system-specified
	    (or coding-system-for-write
		(select-safe-coding-system (point) (point-max)))))

    ;; Insert contents of requested attachments, if any.
    (when (and (eq major-mode 'mail-mode) mail-encode-mml)
      (mml-to-mime)
      (setq mail-encode-mml nil))

    ;; Don't let some read-only text stop us from encrypting.
    (let ((inhibit-read-only t))
      (with-suppressed-warnings ((interactive-only epa-encrypt-region))
        (epa-encrypt-region start (point-max)
                            recipient-keys signers signers)))))