From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.user/3476 Path: news.gmane.org!not-for-mail From: Eric Simon Newsgroups: gmane.emacs.gnus.user Subject: Re: Automatically sign/encrypt messages Date: Thu, 05 Feb 2004 19:37:49 +0100 Organization: Knowledge, Information and Data Processing Group, University of =?utf-8?q?Neuch=C3=A2tel?= Message-ID: <87smhpwewy.fsf@pc70-23.unine.ch> References: <87n086ach0.fsf@ulm.my.lan> <8765emerej.fsf@pc70-23.unine.ch> <87ptcu23fd.fsf@ulm.my.lan> <87znby7oby.fsf@pc70-23.unine.ch> <87r7xar7i9.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 1138669582 19127 80.91.229.2 (31 Jan 2006 01:06:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 31 Jan 2006 01:06:22 +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 Original-To: news@u-h-l.de 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:jc6/IsOKA9po5EQZdz83BhPGilU= Original-NNTP-Posting-Host: 130.125.70.23 Original-X-Trace: 1076006268 news.sunrise.ch 735 130.125.70.23 Original-Xref: bridgekeeper.physik.uni-ulm.de gnus-emacs-gnus:3617 Original-Lines: 100 X-Gnus-Article-Number: 3617 Tue Jan 17 17:32:16 2006 Xref: news.gmane.org gmane.emacs.gnus.user:3476 Archived-At: --=-=-= Hallo Klaus, Klaus Uhl writes: > The problem is that Gnus separately encrypts a mail for _all_ > recipients and if you have a recipient without a PGP key you will get > an error message. Indeed. > I tried to fix this problem with the following code: > > (defun extract-addresses (header-string) > (when (not (null header-string)) > (mapcar #'car (mail-header-parse-addresses header-string)))) > (add-hook > 'message-send-hook > (lambda () > (let* ((to-header (message-fetch-field "To")) > (cc-header (message-fetch-field "Cc")) > (bcc-header (message-fetch-field "Bcc")) > (to (when (not (null to-header)) (substring to-header 3))) > (cc (when (not (null cc-header)) (substring cc-header 3))) > (bcc (when (not (null bcc-header)) (substring bcc-header 4))) > (recipients > (append (extract-addresses to) > (extract-addresses cc) > (extract-addresses bcc)))) > (cond ((every (lambda (rec) > (or > (pgg-lookup-key rec) > (pgg-fetch-key pgg-default-keyserver-address rec))) > recipients) > (mml-secure-message-encrypt-pgpmime)) > (t > (mml-secure-message-sign-pgpmime)))))) > > You can see that I read all three headers, strip off the header > "prefix", extract all addresses and concatenate them to a single > list. Then I test if _all_ recipients have a PGP key. > > The only problem is: it does not work! It always tries to encrypt the > messages. Does anyone have an idea/suggestion? It *does* work for email messages, at least for things like a To: with key and a Cc: without, three To's: with keys, etc etc. Needs testing in real life for a bit, I'll report any scenario that doesn't work. Only problem is that it doesn't check for empty recipient anymore, so when you post in a newgroup, somehow the condition is true: (every lambda ... recipients) must return true for empty recipient list or something, need to investigate this. Anyway, a quick hack that works for me (proof is this message): (add-hook 'message-send-hook (lambda () (let* ((to-header (message-fetch-field "To")) (cc-header (message-fetch-field "Cc")) (bcc-header (message-fetch-field "Bcc")) (to (when (not (null to-header)) (substring to-header 3))) (cc (when (not (null cc-header)) (substring cc-header 3))) (bcc (when (not (null bcc-header)) (substring bcc-header 4))) (recipients (append (extract-addresses to) (extract-addresses cc) (extract-addresses bcc)))) (cond ((and (not (null recipients)) (every (lambda (rec) (or (pgg-lookup-key rec) (pgg-fetch-key pgg-default-keyserver-address rec))) recipients)) (mml-secure-message-encrypt-pgpmime)) (t (mml-secure-message-sign-pgpmime)))))) I'm sure you can enhance this again :-) Now thank you for the work in any case and whatever form this code is going to take, it's going to be very useful to me. Take care Eric --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQBAIo19YcF8O7nhxZcRApLJAJ4zVFsQQBI7fcjK7Qp9GkC+otGkPwCfZ37C +ndcbVvG/mMvdySoM1Le4Bg= =Md0U -----END PGP SIGNATURE----- --=-=-=--