Commit 87481229 authored by J08nY's avatar J08nY

Setup some abstractions above PGP enabled mailing lists.

parent 6d8d12aa
......@@ -44,6 +44,9 @@ DEBUG = True
ALLOWED_HOSTS = []
# Set this to the name the mailman_pgp plugin has in your Mailman Core config.
# [plugin.<MAILMAN_PGP_PLUGIN_NAME>]
MAILMAN_PGP_PLUGIN_NAME = 'pgp'
# Application definition
......
from setuptools import find_packages, setup
setup(
name='django_pgpmailman',
version='0.1',
description='A web interface extension for the GNU Mailman apps Postorius and HyperKitty.',
long_description="""""",
author='Jan Jancar',
author_email='johny@neuromancer.sk',
license='',
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: System Administrators',
'Operating System :: POSIX',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Communications :: Email :: Mailing List Servers',
],
keywords='email pgp',
packages=find_packages('src'),
package_dir={'': 'src'},
include_package_data=True,
install_requires=[
'Django>=1.8',
'Django<1.12',
'django_mailman3',
'mailmanclient',
]
name='django_pgpmailman',
version='0.1',
description='A web interface extension for the GNU Mailman apps Postorius and HyperKitty.',
long_description="""""",
author='Jan Jancar',
author_email='johny@neuromancer.sk',
license='',
classifiers=[
'Development Status :: 1 - Planning',
'Intended Audience :: System Administrators',
'Operating System :: POSIX',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Communications :: Email :: Mailing List Servers',
],
keywords='email pgp',
packages=find_packages('src'),
package_dir={'': 'src'},
include_package_data=True,
install_requires=[
'Django>=1.8',
'Django<1.12',
'django_mailman3',
'mailmanclient',
'PGPy>=0.4.2'
],
dependency_links=[
'https://github.com/J08nY/PGPy/archive/dev.zip#egg=PGPy-0.4.2'
]
)
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Jan Jancar
#
# This file is a part of the Django 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/>.
from itertools import chain
from mailmanclient._client import RESTObject, MailingList
from pgpy import PGPKey
from pgpy.errors import PGPError
from six.moves.urllib_error import HTTPError
class PGPMailingList(RESTObject):
_writable_properties = (
'unsigned_msg_action', 'inline_pgp_action', 'expired_sig_action',
'revoked_sig_action', 'invalid_sig_action', 'duplicate_sig_action',
'strip_original_sig', 'sign_outgoing', 'nonencrypted_msg_action',
'encrypt_outgoing', 'key_change_workflow', 'key_signing_allowed')
_read_only_properties = ('self_link', 'list_id')
_properties = chain(_writable_properties, _read_only_properties)
@property
def mlist(self):
return MailingList(self._connection, 'lists/{}'.format(self.list_id))
@property
def key(self):
try:
response, content = self._connection.call(self._url + '/key')
key, _ = PGPKey.from_blob(response['key'])
return key
except PGPError:
return None
@key.setter
def key(self, value):
str_key = str(value) if value else ''
try:
self._connection.call(self._url + '/key', data=dict(key=str_key),
method='PUT')
except HTTPError:
pass
@property
def pubkey(self):
try:
response, content = self._connection.call(self._url + '/pubkey')
key, _ = PGPKey.from_blob(response['key'])
return key
except PGPError:
return None
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Jan Jancar
#
# This file is a part of the Django 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/>.
from operator import itemgetter
from django.conf import settings
from django_mailman3.lib.mailman import get_mailman_client
from mailmanclient._client import Plugin
from django_pgpmailman.models import PGPMailingList
class PGPPlugin(Plugin):
def __init__(self, base_plugin):
super(PGPPlugin, self).__init__(base_plugin.connection,
base_plugin.name,
base_plugin.rest_data)
self._base_plugin = base_plugin
@property
def lists(self):
response, content = self.call('lists')
if 'entries' not in content:
return []
return [PGPMailingList(self._connection, entry['self_link'], entry) for
entry in sorted(content['entries'], key=itemgetter('list_id'))]
def get_list(self, list_identifier):
response, content = self.call('lists/{}'.format(list_identifier))
return PGPMailingList(self._connection, content['self_link', content])
def get_pgp_plugin():
return PGPPlugin(
get_mailman_client().get_plugin(settings.MAILMAN_PGP_PLUGIN_NAME))
......@@ -20,7 +20,9 @@ from __future__ import absolute_import, unicode_literals
from django.shortcuts import render
from django_pgpmailman.plugin import get_pgp_plugin
def pgp_list_index(request):
return render(request, 'django_pgpmailman/index.html',
{'lists': []})
{'lists': get_pgp_plugin().lists})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment