add quarantine copy command to CLI
This commit is contained in:
@@ -271,6 +271,13 @@ def release(quarantines, args):
|
|||||||
f"{args.quarantine}: released message with id {args.quarantine_id} "
|
f"{args.quarantine}: released message with id {args.quarantine_id} "
|
||||||
f"for {rcpts}")
|
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):
|
def delete(quarantines, args):
|
||||||
storage = _get_quarantine(quarantines, args.quarantine, args.debug).storage
|
storage = _get_quarantine(quarantines, args.quarantine, args.debug).storage
|
||||||
@@ -432,6 +439,27 @@ def main():
|
|||||||
help="Release email for all recipients.",
|
help="Release email for all recipients.",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
quar_release_parser.set_defaults(func=release)
|
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
|
# quarantine delete command
|
||||||
quar_delete_parser = quar_subparsers.add_parser(
|
quar_delete_parser = quar_subparsers.add_parser(
|
||||||
"delete",
|
"delete",
|
||||||
|
|||||||
@@ -535,6 +535,20 @@ class Quarantine:
|
|||||||
|
|
||||||
return recipients
|
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):
|
def execute(self, milter):
|
||||||
logger = CustomLogger(
|
logger = CustomLogger(
|
||||||
self.logger, {"name": self.cfg["name"], "qid": milter.qid})
|
self.logger, {"name": self.cfg["name"], "qid": milter.qid})
|
||||||
|
|||||||
Reference in New Issue
Block a user