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
This commit is contained in:
parent
49a1cfe974
commit
ba8ba26636
1 changed files with 50 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue