gpg-lacre/gpg-mailgate.py

55 lines
1.6 KiB
Python
Raw Normal View History

2010-01-20 21:53:25 +01:00
#!/usr/bin/python
#
2022-06-30 22:55:04 +02:00
# gpg-mailgate
#
2022-06-30 22:55:04 +02:00
# This file is part of the gpg-mailgate source code.
#
2022-06-30 22:55:04 +02:00
# 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.
#
2022-06-30 22:55:04 +02:00
# 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.
#
2022-06-30 22:55:04 +02:00
# 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/>.
#
2010-01-20 21:53:25 +01:00
import email
import sys
import time
import logging
import lacre
import lacre.config as conf
start = time.process_time()
conf.load_config()
lacre.init_logging(conf.get_item('logging', 'config'))
# This has to be executed *after* logging initialisation.
2022-10-22 10:13:54 +02:00
import lacre.core as core
LOG = logging.getLogger('gpg-mailgate.py')
missing_params = conf.validate_config()
if missing_params:
2022-06-30 22:55:04 +02:00
LOG.error(f"Aborting delivery! Following mandatory config parameters are missing: {missing_params!r}")
sys.exit(lacre.EX_CONFIG)
# Read e-mail from stdin, parse it
2022-03-11 22:18:16 +01:00
raw = sys.stdin.read()
2022-06-30 22:55:04 +02:00
raw_message = email.message_from_string(raw)
2022-03-11 22:18:16 +01:00
from_addr = raw_message['From']
# Read recipients from the command-line
2022-03-11 22:18:16 +01:00
to_addrs = sys.argv[1:]
# Let's start
2022-10-22 10:13:54 +02:00
core.deliver_message(raw_message, from_addr, to_addrs)
process_t = (time.process_time() - start) * 1000
LOG.info("Message delivered in {process:.2f} ms".format(process=process_t))