Extend the daemon skeleton
This commit is contained in:
parent
29b5b50901
commit
7849c55d9f
|
@ -1,22 +1,21 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
#
|
||||
# gpg-mailgate
|
||||
# gpg-mailgate
|
||||
#
|
||||
# This file is part of the gpg-mailgate source code.
|
||||
# This file is part of the gpg-mailgate source code.
|
||||
#
|
||||
# gpg-mailgate 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.
|
||||
# gpg-mailgate 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.
|
||||
#
|
||||
# gpg-mailgate source code 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.
|
||||
# gpg-mailgate source code 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 gpg-mailgate source code. If not, see <http://www.gnu.org/licenses/>.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with gpg-mailgate source code. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import email
|
||||
|
@ -38,12 +37,12 @@ LOG = logging.getLogger(__name__)
|
|||
|
||||
missing_params = conf.validate_config()
|
||||
if missing_params:
|
||||
LOG.error(f"Aborting delivery! Following mandatory config parameters are missing: {missing_params!r}")
|
||||
sys.exit(lacre.EX_CONFIG)
|
||||
LOG.error(f"Aborting delivery! Following mandatory config parameters are missing: {missing_params!r}")
|
||||
sys.exit(lacre.EX_CONFIG)
|
||||
|
||||
# Read e-mail from stdin
|
||||
raw = sys.stdin.read()
|
||||
raw_message = email.message_from_string( raw )
|
||||
raw_message = email.message_from_string(raw)
|
||||
from_addr = raw_message['From']
|
||||
to_addrs = sys.argv[1:]
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue