aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/mta/bulk.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman_pgp/mta/bulk.py')
-rw-r--r--src/mailman_pgp/mta/bulk.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/mailman_pgp/mta/bulk.py b/src/mailman_pgp/mta/bulk.py
index cd517e8..a2cc8c6 100644
--- a/src/mailman_pgp/mta/bulk.py
+++ b/src/mailman_pgp/mta/bulk.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
-""""""
+"""PGP enabled BulkDelivery."""
import copy
from mailman.mta.bulk import BulkDelivery
@@ -28,7 +28,7 @@ from mailman_pgp.utils.email import overwrite_message
class CallbackBulkDelivery(BulkDelivery):
- """"""
+ """Bulk delivery that has a list of callbacks to run for each chunk."""
def __init__(self, max_recipients=None):
super().__init__(max_recipients=max_recipients)
@@ -40,19 +40,27 @@ class CallbackBulkDelivery(BulkDelivery):
for recipients in self.chunkify(msgdata.get('recipients', set())):
message_copy = copy.deepcopy(msg)
msgdata_copy = msgdata.copy()
+ recipients_copy = set(recipients)
+
for callback in self.callbacks:
- callback(mlist, message_copy, msgdata_copy, recipients)
+ callback(mlist, message_copy, msgdata_copy, recipients_copy)
+ callback_refused = dict(
+ (recipient, (444, BaseException))
+ for recipient in recipients - recipients_copy)
+ refused.update(callback_refused)
+
chunk_refused = self._deliver_to_recipients(
- mlist, message_copy, msgdata_copy, recipients)
+ mlist, message_copy, msgdata_copy, recipients_copy)
refused.update(chunk_refused)
return refused
class PGPBulkMixin:
- """"""
+ """Bulk encryption and signing Delivery mixin."""
def sign_encrypt(self, mlist, msg, msgdata, recipients):
"""
+ Sign and encrypt the outgoing message to the recipients.
:param mlist:
:type mlist: mailman.model.mailinglist.MailingList
@@ -61,7 +69,7 @@ class PGPBulkMixin:
:param msgdata:
:type msgdata: dict
:param recipients:
- :type recipients: list
+ :type recipients: set
"""
pgp_list = PGPMailingList.for_list(mlist)
if not pgp_list:
@@ -71,13 +79,13 @@ class PGPBulkMixin:
return
keys = []
- for recipient in recipients:
+ for recipient in set(recipients):
pgp_address = PGPAddress.for_email(recipient)
if pgp_address is None:
- # TODO: log failure here
+ recipients.remove(recipient)
continue
if pgp_address.key is None or not pgp_address.key_confirmed:
- # TODO: log failure here?
+ recipients.remove(recipient)
continue
keys.append(pgp_address.key)
@@ -96,7 +104,7 @@ class PGPBulkMixin:
@public
class PGPBulkDelivery(CallbackBulkDelivery, PGPBulkMixin):
- """"""
+ """Bulk PGP enabled delivery."""
def __init__(self, max_recipients=None):
super().__init__(max_recipients=max_recipients)