Implement Advanced Content Filter #97

Merged
pfm merged 36 commits from daemon into main 2022-10-19 20:48:41 +02:00
3 changed files with 49 additions and 22 deletions
Showing only changes of commit 7849c55d9f - Show all commits

View File

@ -1,5 +1,4 @@
#!/usr/bin/python
#
# gpg-mailgate
#

View File

@ -1,15 +1,25 @@
"""Lacre Daemon, the Advanced Mail Filter message dispatcher."""
import logging
import lacre
import lacre.config as conf
from aiosmtpd.controller import Controller
import lacre.config as conf
# import lacre.mailgate as gate
# Mail status constants.
#
# These are the only values that our mail handler is allowed to return.
RESULT_OK = '250 OK'
RESULT_ERROR = '500 Could not process your message'
RESULT_NOT_IMPLEMENTED = '500 Not implemented yet'
# Load configuration and init logging, in this order. Only then can we load
# the last Lacre module, i.e. lacre.mailgate.
conf.load_config()
lacre.init_logging(conf.get_item("logging", "config"))
LOG = logging.getLogger(__name__)
import lacre.mailgate as gate
class MailEncryptionProxy:
"""A mail handler dispatching to appropriate mail operation."""
@ -17,13 +27,21 @@ class MailEncryptionProxy:
async def handle_DATA(self, server, session, envelope):
"""Accept a message and either encrypt it or forward as-is."""
# for now, just return an error because we're not ready to handle mail
for r, s in gate.delivery_plan(envelope.rcpt_tos):
print(r)
return RESULT_NOT_IMPLEMENTED
if __name__ == '__main__':
def _init_controller():
proxy = MailEncryptionProxy()
host, port = conf.relay_params()
controller = Controller(proxy, hostname=host, port=port)
return Controller(proxy, hostname=host, port=port)
def _main():
controller = _init_controller()
# starts the controller in a new thread
controller.start()
@ -32,3 +50,7 @@ if __name__ == '__main__':
# and certificate cache
controller.stop()
if __name__ == '__main__':
_main()

View File

@ -402,6 +402,12 @@ def _is_encrypted(raw_message):
return text.is_pgp_inline(first_payload)
def delivery_plan(recipients):
"""Generate a sequence of pairs: a recipient and their delivery strategy."""
for recipient in recipients:
yield recipient, None
def deliver_message(raw_message, from_address, to_addrs):
"""Send RAW_MESSAGE to all TO_ADDRS using the best encryption method available."""
global from_addr