From: Eric Simon <erik.simon@unine.ch>
Subject: Re: Automatically sign/encrypt messages
Date: Thu, 05 Feb 2004 19:37:49 +0100 [thread overview]
Message-ID: <87smhpwewy.fsf@pc70-23.unine.ch> (raw)
In-Reply-To: <87r7xar7i9.fsf@ulm.my.lan>
[-- Attachment #1: Type: text/plain, Size: 2945 bytes --]
Hallo Klaus,
Klaus Uhl <news@u-h-l.de> 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
[-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --]
prev parent reply other threads:[~2004-02-05 18:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-29 17:31 Klaus Uhl
2004-01-30 19:06 ` Ted Zlatanov
[not found] ` <87ptd0jsqv.fsf@u-h-l.de>
2004-02-02 20:27 ` Ted Zlatanov
2014-05-15 21:41 ` Peter Münster
2004-02-04 16:33 ` Eric Simon
2004-02-04 16:51 ` Klaus Uhl
[not found] ` <87znby7oby.fsf@pc70-23.unine.ch>
[not found] ` <87r7xar7i9.fsf@ulm.my.lan>
2004-02-05 18:37 ` Eric Simon [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87smhpwewy.fsf@pc70-23.unine.ch \
--to=erik.simon@unine.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).