From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.user/3471 Path: news.gmane.org!not-for-mail From: Eric Simon Newsgroups: gmane.emacs.gnus.user Subject: Re: Automatically sign/encrypt messages Date: Wed, 04 Feb 2004 17:33:08 +0100 Organization: Knowledge, Information and Data Processing Group, University of =?utf-8?q?Neuch=C3=A2tel?= Message-ID: <8765emerej.fsf@pc70-23.unine.ch> References: <87n086ach0.fsf@ulm.my.lan> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: sea.gmane.org 1138669579 19107 80.91.229.2 (31 Jan 2006 01:06:19 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 31 Jan 2006 01:06:19 +0000 (UTC) Original-X-From: nobody Tue Jan 17 17:32:16 2006 Original-Path: quimby.gnus.org!newsfeed1.e.nsc.no!nsc.no!nextra.com!news.tele.dk!news.tele.dk!small.news.tele.dk!irazu.switch.ch!switch.ch!newsfeed.sunrise.ch!news.sunrise.ch!not-for-mail Original-Newsgroups: gnu.emacs.gnus X-Homepage: http://iiun.unine.ch/people/simone/ User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) Cancel-Lock: sha1:4T2MUcRvdL2J2J+axVt9SKvjcbg= Original-NNTP-Posting-Host: 130.125.70.23 Original-X-Trace: 1075912390 news.sunrise.ch 727 130.125.70.23 Original-Xref: bridgekeeper.physik.uni-ulm.de gnus-emacs-gnus:3612 Original-Lines: 64 X-Gnus-Article-Number: 3612 Tue Jan 17 17:32:16 2006 Xref: news.gmane.org gmane.emacs.gnus.user:3471 Archived-At: --=-=-= Klaus Uhl writes: > (add-hook > 'message-send-hook > (lambda () > (let ((recipient (message-fetch-field "To"))) > (cond ((and (not (null recipient)) > (or (pgg-lookup-key recipient) > (pgg-fetch-key pgg-default-keyserver-address recipient))) > (mml-secure-message-encrypt-pgpmime)) > (t > (mml-secure-message-sign-pgpmime)))))) Nice indeed. Been using it today. Then I noticed sometimes it's not able to find the key in my ring or on the server because (message-fetch-field "To") returns the whole header. There is a function to parse a string and get a pair email/name: mail-header-parse-address, so I thought getting only the actual address would be better. So below is a slightly modified version that's been working nice for me for the past... 2 hours or so? Oh, not exactly, one friend had a public key published but didn't use encryption anymore and didn't have the secret counterpart, so he complained I was using cryptography with him... Anyway: (add-hook 'message-send-hook (lambda () (let* ((recipient (message-fetch-field "To")) (recid (if (not (null recipient)) (car (mail-header-parse-address recipient))))) (cond ((and (not (null recipient)) (or (pgg-lookup-key recid) (pgg-fetch-key pgg-default-keyserver-address recid)) ) (mml-secure-message-encrypt-pgpmime)) (t (mml-secure-message-sign-pgpmime)))))) The first (if (not (null recipient)) is to avoid trying to take the car of something bad, dunno if needed really, quite ugly, but safer in my opinion. Cheers Eric --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBAIR7HYcF8O7nhxZcRAhh+AKCRL/WPvuIZD0I2v8zviw4A2EOURgCfbkfB aNMEHobtpVCv+iJlmDUc5GE= =m0nS -----END PGP SIGNATURE----- --=-=-=--