[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


From: Richard Stallman
Subject: epa-mail.el
Date: Fri, 19 Jul 2013 15:10:00 -0400

        [ To any NSA and FBI agents reading my email: please consider
        [ whether defending the US Constitution against all enemies,
        [ foreign or domestic, requires you to follow Snowden's example.

I would like to replace epa-mail-encrypt with this,
to make it usable from Lisp code.  Any objections?

(defun epa-mail-encrypt (&optional recipients signers)
  "Encrypt the outgoing mail message in the current buffer.
Optional argument RECIPIENTS is a list of recipient addresses
or t to perform symmetric encryption.  If it is nil,
take the recipients from the text in the header in the buffer.

SIGNERS is a list of keys to sign the message with."
   (let ((verbose current-prefix-arg))
     (list (if verbose
               (or (epa-select-keys
                    "Select recipients for encryption.
If no one is selected, symmetric encryption will be performed.  "
           (and verbose (y-or-n-p "Sign? ")
                (epa-select-keys context
                                 "Select keys for signing.  ")))))
  (let (start real-recipients recipient-keys)
      (if recipients
          (setq real-recipients
                (if (eq recipients t)

        (let ((config (epg-configuration))
              (context (epg-make-context epa-protocol))
              recipients-string recipient-key sign)
          (goto-char (point-min))
            (narrow-to-region (point)
                              (if (search-forward mail-header-separator nil 0)
                                  (match-beginning 0)
            (setq recipients-string
                  (mapconcat #'identity
                             (nconc (mail-fetch-field "to" nil nil t)
                                    (mail-fetch-field "cc" nil nil t)
                                    (mail-fetch-field "bcc" nil nil t))
            (setq recipients-string
                     (insert "to: " recipients-string "\n")
                     (expand-mail-aliases (point-min) (point-max))
                     (car (mail-fetch-field "to" nil nil t))))))

          (setq real-recipients
                (split-string recipients-string "," t "[ \t\n]*"))

          ;; Process all the recipients thru the list of GnuPG groups.
          ;; Expand GnuPG group names to what they stand for.
          (setq real-recipients
                (apply #'nconc
                        (lambda (recipient)
                          (or (epg-expand-group config recipient)
                              (list recipient)))

        (goto-char (point-min))
        (if (search-forward mail-header-separator nil t)
        (setq start (point))

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

        (when real-recipients
          (setq recipient-keys
                  (lambda (recipient)
                    (setq recipient-key
                            (epg-make-context epa-protocol)
                            (if (string-match "@" recipient)
                                (concat "<" recipient ">")
                    (unless (or recipient-key
                                  "No public key for %s; skip it? "
                      (error "No public key for %s" recipient))
                    (if recipient-key (list recipient-key)))

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

Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use Ekiga or an ordinary phone call.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]