From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: epa-mail.el Date: Fri, 19 Jul 2013 15:10:00 -0400 Message-ID: Reply-To: rms@gnu.org NNTP-Posting-Host: plane.gmane.org Content-Type: text/plain; charset=ISO-8859-15 X-Trace: ger.gmane.org 1374261019 5455 80.91.229.3 (19 Jul 2013 19:10:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Jul 2013 19:10:19 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 19 21:10:20 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1V0G4J-0007JL-H0 for ged-emacs-devel@m.gmane.org; Fri, 19 Jul 2013 21:10:19 +0200 Original-Received: from localhost ([::1]:46749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V0G4J-0002CO-2P for ged-emacs-devel@m.gmane.org; Fri, 19 Jul 2013 15:10:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V0G4B-00023j-Om for emacs-devel@gnu.org; Fri, 19 Jul 2013 15:10:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V0G49-0000kR-TJ for emacs-devel@gnu.org; Fri, 19 Jul 2013 15:10:11 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:43769) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V0G49-0000k6-Nj for emacs-devel@gnu.org; Fri, 19 Jul 2013 15:10:09 -0400 Original-Received: from rms by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1V0G40-0006VY-OD; Fri, 19 Jul 2013 15:10:00 -0400 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:162025 Archived-At: [ 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." (interactive (let ((verbose current-prefix-arg)) (list (if verbose (or (epa-select-keys context "Select recipients for encryption. If no one is selected, symmetric encryption will be performed. " recipients) t)) (and verbose (y-or-n-p "Sign? ") (epa-select-keys context "Select keys for signing. "))))) (let (start real-recipients recipient-keys) (save-excursion (if recipients (setq real-recipients (if (eq recipients t) nil recipients)) (let ((config (epg-configuration)) (context (epg-make-context epa-protocol)) recipients-string recipient-key sign) (goto-char (point-min)) (save-restriction (narrow-to-region (point) (if (search-forward mail-header-separator nil 0) (match-beginning 0) (point))) (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 (mail-strip-quoted-names (with-temp-buffer (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 (mapcar (lambda (recipient) (or (epg-expand-group config recipient) (list recipient))) real-recipients))) )) (goto-char (point-min)) (if (search-forward mail-header-separator nil t) (forward-line)) (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 (apply 'nconc (mapcar (lambda (recipient) (setq recipient-key (epa-mail--find-usable-key (epg-list-keys (epg-make-context epa-protocol) (if (string-match "@" recipient) (concat "<" recipient ">") recipient)) 'encrypt)) (unless (or recipient-key (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))) real-recipients))))) ;; 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 USA www.fsf.org www.gnu.org Skype: No way! That's nonfree (freedom-denying) software. Use Ekiga or an ordinary phone call.