commit 3ab7c2cd566941ca843d37c615027c3c71fae570
parent c9b542efbe0c8539250233dc1c238d5bc89da09f
Author: Eric Weikl <eric.weikl@tngtech.com>
Date: Thu, 3 Mar 2011 22:02:58 +0100
Added new hook 'gpg-expand-keys'
sup does not support GPG groups, since GPGME ignores group definitions
in gpg.conf by design. Therefore, there is no way e.g. to send encrypted
mails to mailing lists using GPG groups.
The new hook receives the list of current recipients and allows the user
to swap recipients with other email addresses or key IDs. A simple hook
to add group support could look like this:
----------8<---------------
lookup_table = {}
`gpg --with-colons --list-config group 2> /dev/null`.each_line do |line|
email_and_keys = line.split(':')[2..3]
lookup_table[email_and_keys[0].gsub(/[<>]/, '')] = email_and_keys[1].strip.split(';')
end
recipients.map { |r| lookup_table.has_key?(r) ? lookup_table[r] : r }.flatten
---------->8---------------
Diffstat:
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/lib/sup/crypto.rb b/lib/sup/crypto.rb
@@ -41,6 +41,20 @@ from_key: the key that generated the signature (class is GPGME::Key)
Return value: an array of lines of output
EOS
+ HookManager.register "gpg-expand-keys", <<EOS
+Runs when the list of encryption recipients is created, allowing you to
+replace a recipient with one or more GPGME recipients. For example, you could
+replace the email address of a mailing list with the key IDs that belong to
+the recipients of that list. This is essentially what GPG groups do, which
+are not supported by GPGME.
+
+Variables:
+recipients: an array of recipients of the current email
+
+Return value: an array of recipients (email address or GPG key ID) to encrypt
+the email for
+EOS
+
def initialize
@mutex = Mutex.new
@@ -137,7 +151,7 @@ EOS
gpg_opts = HookManager.run("gpg-options",
{:operation => "encrypt", :options => gpg_opts}) || gpg_opts
recipients = to + [from]
-
+ recipients = HookManager.run("gpg-expand-keys", { :recipients => recipients }) || recipients
begin
cipher = GPGME.encrypt(recipients, format_payload(payload), gpg_opts)
rescue GPGME::Error => exc