add quarantine copy command to CLI

This commit is contained in:
2023-12-11 17:51:04 +01:00
parent 5fe152b6b6
commit 9d3c7c84c1
2 changed files with 42 additions and 0 deletions

View File

@@ -271,6 +271,13 @@ def release(quarantines, args):
f"{args.quarantine}: released message with id {args.quarantine_id} "
f"for {rcpts}")
def copy(quarantines, args):
logger = logging.getLogger(__name__)
quarantine = _get_quarantine(quarantines, args.quarantine, args.debug)
quarantine.copy(args.quarantine_id, args.recipient)
logger.info(
f"{args.quarantine}: sent a copy of message with id {args.quarantine_id} "
f"to {args.recipient}")
def delete(quarantines, args):
storage = _get_quarantine(quarantines, args.quarantine, args.debug).storage
@@ -432,6 +439,27 @@ def main():
help="Release email for all recipients.",
action="store_true")
quar_release_parser.set_defaults(func=release)
# quarantine copy command
quar_copy_parser = quar_subparsers.add_parser(
"copy",
description="Send a copy of email to another recipient.",
help="Send a copy of email to another recipient.",
formatter_class=formatter_class)
quar_copy_parser.add_argument(
"quarantine_id",
metavar="ID",
help="Quarantine ID.")
quar_copy_parser.add_argument(
"-n",
"--disable-syslog",
dest="syslog",
help="Disable syslog messages.",
action="store_false")
quar_copy_parser_grp.add_argument(
"-t", "--to",
dest="recipient",
help="Release email for one recipient address.")
quar_copy_parser.set_defaults(func=copy)
# quarantine delete command
quar_delete_parser = quar_subparsers.add_parser(
"delete",

View File

@@ -535,6 +535,20 @@ class Quarantine:
return recipients
def copy(self, storage_id, recipient):
metadata, msg = self.storage.get_mail(storage_id)
try:
mailer.smtp_send(
self.smtp_host,
self.smtp_port,
metadata["mailfrom"],
recipient,
msg.as_string())
except Exception as e:
raise RuntimeError(
f"error while sending message to '{recipient}': {e}")
def execute(self, milter):
logger = CustomLogger(
self.logger, {"name": self.cfg["name"], "qid": milter.qid})