aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/workflows/mod_approval.py
blob: 90edf4c2b6a68ea98cb57d70d7ee1cde0fd57f19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (C) 2017 Jan Jancar
#
# This file is a part of the Mailman PGP plugin.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.

""""""
import copy

from mailman.email.message import UserNotification
from mailman.interfaces.subscriptions import TokenOwner
from public import public

from mailman_pgp.pgp.mime import MIMEWrapper
from mailman_pgp.utils.email import overwrite_message

MOD_APPROVAL_REQUEST = """\
----------
TODO: this is a pgp enabled list.
A subscriber with address {} requested a change of his key.
His new key is attached to this message.

Fingerprint: {}
----------
"""


@public
class ModeratorApprovalMixin:
    def _step_mod_approval(self):
        self.push('get_approval')

    def _step_get_approval(self):
        self._pend(TokenOwner.moderator)
        self.push('receive_confirmation')
        self.save()

        if self.mlist.admin_immed_notify:
            subject = 'New key change request from {}'.format(
                    self.pgp_address.email)
            text = MOD_APPROVAL_REQUEST.format(self.pgp_address.email,
                                               self.pubkey.fingerprint)
            msg = UserNotification(
                    self.mlist.owner_address, self.mlist.owner_address,
                    subject, text, self.mlist.preferred_language)
            out = copy.deepcopy(msg)
            wrapped = MIMEWrapper(msg)
            msg = wrapped.attach_keys(self.pubkey)
            overwrite_message(msg, out)
            out.send(self.mlist)
        raise StopIteration