From d88a146b547d047c60e4bf3b26e7d5a0bd1b4ccb Mon Sep 17 00:00:00 2001 From: J08nY Date: Sat, 15 Jul 2017 17:11:58 +0200 Subject: Add `key receive` command to get list public key. --- src/mailman_pgp/commands/eml_key.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/mailman_pgp/commands/eml_key.py') diff --git a/src/mailman_pgp/commands/eml_key.py b/src/mailman_pgp/commands/eml_key.py index 1b6dc9f..deb396a 100644 --- a/src/mailman_pgp/commands/eml_key.py +++ b/src/mailman_pgp/commands/eml_key.py @@ -16,8 +16,10 @@ # this program. If not, see . """The key email command.""" +from email.mime.text import MIMEText from email.utils import parseaddr +from mailman.email.message import UserNotification from mailman.interfaces.command import ContinueProcessing, IEmailCommand from mailman.interfaces.pending import IPendings from mailman.interfaces.subscriptions import ISubscriptionManager @@ -29,6 +31,7 @@ from zope.interface import implementer from mailman_pgp.database import transaction from mailman_pgp.model.address import PGPAddress from mailman_pgp.model.list import PGPMailingList +from mailman_pgp.pgp.mime import MIMEWrapper from mailman_pgp.pgp.wrapper import PGPWrapper from mailman_pgp.workflows.base import CONFIRM_REQUEST from mailman_pgp.workflows.key_change import (CHANGE_CONFIRM_REQUEST, @@ -193,15 +196,39 @@ def _cmd_sign(pgp_list, mlist, msg, msgdata, arguments, results): pass +def _cmd_receive(pgp_list, mlist, msg, msgdata, arguments, results): + if len(arguments) != 1: + print('Extraneous argument/s: ' + ','.join(arguments[1:]), + file=results) + return ContinueProcessing.no + + email = _get_email(msg) + if not email: + print('No email to send list public key.', file=results) + return ContinueProcessing.no + + msg = UserNotification(email, mlist.request_address, + '{} public key'.format(mlist.fqdn_listname)) + msg.set_type('multipart/mixed') + msg['MIME-Version'] = '1.0' + msg.attach(MIMEText('Here is the public key you requested.')) + wrapped = MIMEWrapper(msg) + msg = wrapped.attach_key(pgp_list.pubkey) + + msg.send(mlist) + return ContinueProcessing.yes + + SUBCOMMANDS = { 'set': _cmd_set, 'confirm': _cmd_confirm, 'change': _cmd_change, 'revoke': _cmd_revoke, - 'sign': _cmd_sign + 'sign': _cmd_sign, + 'receive': _cmd_receive } -ARGUMENTS = '<' + '|'.join(SUBCOMMANDS.keys()) + '>' +ARGUMENTS = '<' + '|'.join(SUBCOMMANDS) + '>' @public -- cgit v1.2.3-70-g09d2