From ba8ba2663629290e5bea0c621cf65cdbd15689d6 Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 26 Sep 2024 16:12:01 +0200 Subject: [PATCH] cli (message/send): add arguments for message addressing: commands have been added to add `to`, `cc` and `bcc` metadata for sending copy of the message to several entities. Metadata such as `reply-to` `reply-room` and `no-reply` are also supported. rel 450 --- libervia/cli/cmd_message.py | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/libervia/cli/cmd_message.py b/libervia/cli/cmd_message.py index 67c97836..6f6144a8 100644 --- a/libervia/cli/cmd_message.py +++ b/libervia/cli/cmd_message.py @@ -33,6 +33,9 @@ from libervia.frontends.tools import jid __commands__ = ["Message"] +RECIPIENTS_ARGS = ["to", "cc", "bcc"] +REPLY_ARGS = ["reply-to", "reply-room"] + class Send(base.CommandBase): def __init__(self, host): @@ -91,6 +94,35 @@ class Send(base.CommandBase): metavar="FILE_PATH", help=_("add a file as an attachment"), ) + + addressing_group = self.parser.add_argument_group( + "addressing commands", + description="Commands to add addressing metadata, and/or to send message to " + "multiple recipients." + ) + for arg_name in RECIPIENTS_ARGS: + addressing_group.add_argument( + f"--{arg_name}", + nargs="+", + action="append", + metavar=("JID", "DESCRIPTION"), + help=f'extra "{arg_name.upper()}" recipient(s), may be used several ' + 'times', + ) + for arg_name in REPLY_ARGS: + addressing_group.add_argument( + f"--{arg_name}", + nargs="+", + action="append", + metavar=("JID", "DESCRIPTION"), + help=f'ask to reply to this JID, may be used several ' + 'times', + ) + addressing_group.add_argument( + "--no-reply", + action="store_true", + help="flag this message as not requiring replies" + ) syntax = self.parser.add_mutually_exclusive_group() syntax.add_argument("-x", "--xhtml", action="store_true", help=_("XHTML body")) syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body")) @@ -117,6 +149,24 @@ class Send(base.CommandBase): extra[key] = clean_ustr("".join(stdin_lines)) stdin_lines = [] + addresses = {} + for arg_name in RECIPIENTS_ARGS + [a.replace("-", "_") for a in REPLY_ARGS]: + values = getattr(self.args, arg_name) + if values: + for value in values: + address_jid = value[0] + address_desc = " ".join(value[1:]).strip() + address = {"jid": address_jid} + if address_desc: + address["desc"] = address_desc + addresses.setdefault(arg_name.replace("_", ""), []).append(address) + + if self.args.no_reply: + addresses["noreply"] = True + + if addresses: + extra["addresses"] = addresses + to_send = [] error = False