annotate libervia/cli/cmd_message.py @ 4327:554a87ae17a6

plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks): - Former bookmarks implementation is now labeled as "legacy". - XEP-0402 is now used for bookmarks when relevant namespaces are found, and it fallbacks to legacy XEP-0048/XEP-0049 bookmarks otherwise. - CLI legacy bookmark commands have been moved to `bookmarks legacy` - CLI bookmarks commands now use the new XEP-0402 (with fallback to legacy one automatically used if necessary).
author Goffi <goffi@goffi.org>
date Wed, 20 Nov 2024 11:43:27 +0100
parents 1795bfcc38e7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
815
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
3
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia CLI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3411
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
815
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
6
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
7 # This program is free software: you can redistribute it and/or modify
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
10 # (at your option) any later version.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
11
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
12 # This program is distributed in the hope that it will be useful,
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
15 # GNU Affero General Public License for more details.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
16
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
19
3925
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
20 from pathlib import Path
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
21 import sys
3925
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
22
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
23 from twisted.python import filepath
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
24
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.tools.common import data_format
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
27 from libervia.backend.tools.common.ansi import ANSI as A
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
28 from libervia.backend.tools.utils import clean_ustr
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
29 from libervia.cli import base
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
30 from libervia.cli.constants import Const as C
4074
26b7ed2817da refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
31 from libervia.frontends.tools import jid
3925
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
32
0
goffi@necton2
parents:
diff changeset
33
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
34 __commands__ = ["Message"]
393
393b35aa86d2 jp: added --connect option
Goffi <goffi@goffi.org>
parents: 391
diff changeset
35
4308
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
36 RECIPIENTS_ARGS = ["to", "cc", "bcc"]
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
37 REPLY_ARGS = ["reply-to", "reply-room"]
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
38
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
39
1828
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
40 class Send(base.CommandBase):
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
41 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 super(Send, self).__init__(host, "send", help=_("send a message to a contact"))
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
43
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
44 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
46 "-l", "--lang", type=str, default="", help=_("language of the message")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 "-s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 "--separate",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 action="store_true",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 help=_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
53 "separate xmpp messages: send one message per line instead of one "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
54 "message alone."
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 "-n",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 "--new-line",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 action="store_true",
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
61 help=_("add a new line at the beginning of the input"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 "-S",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 "--subject",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
66 help=_("subject of the message"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 self.parser.add_argument(
3411
f30b238d9c45 jp: follow best practices and use a dash (`-`) instead of underscore (`_`) for long options.
Goffi <goffi@goffi.org>
parents: 3356
diff changeset
69 "-L", "--subject-lang", type=str, default="", help=_("language of subject")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 "-t",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 "--type",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 choices=C.MESS_TYPE_STANDARD + (C.MESS_TYPE_AUTO,),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 default=C.MESS_TYPE_AUTO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 help=_("type of the message"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 )
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
78 self.parser.add_argument(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
79 "-e",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
80 "--encrypt",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
81 metavar="ALGORITHM",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
82 help=_("encrypt message using given algorithm"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
83 )
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
84 self.parser.add_argument(
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
85 "--encrypt-noreplace",
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
86 action="store_true",
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
87 help=_("don't replace encryption algorithm if an other one is already used"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
88 )
3925
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
89 self.parser.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
90 "-a",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
91 "--attach",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
92 dest="attachments",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
93 action="append",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
94 metavar="FILE_PATH",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
95 help=_("add a file as an attachment"),
3925
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
96 )
4308
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
97
4316
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
98 self.parser.add_argument(
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
99 "-k",
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
100 "--keyword",
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
101 dest="keywords",
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
102 action="append",
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
103 help=_("add keyword to message"),
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
104 )
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
105
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
106 self.parser.add_argument(
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
107 "-H",
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
108 "--header",
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
109 dest="headers",
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
110 action="append",
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
111 nargs=2,
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
112 metavar=("NAME", "VALUE"),
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
113 help=_("add header metadata"),
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
114 )
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
115
4308
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
116 addressing_group = self.parser.add_argument_group(
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
117 "addressing commands",
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
118 description="Commands to add addressing metadata, and/or to send message to "
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4316
diff changeset
119 "multiple recipients.",
4308
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
120 )
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
121 for arg_name in RECIPIENTS_ARGS:
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
122 addressing_group.add_argument(
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
123 f"--{arg_name}",
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
124 nargs="+",
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
125 action="append",
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
126 metavar=("JID", "DESCRIPTION"),
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
127 help=f'extra "{arg_name.upper()}" recipient(s), may be used several '
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4316
diff changeset
128 "times",
4308
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
129 )
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
130 for arg_name in REPLY_ARGS:
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
131 addressing_group.add_argument(
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
132 f"--{arg_name}",
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
133 nargs="+",
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
134 action="append",
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
135 metavar=("JID", "DESCRIPTION"),
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4316
diff changeset
136 help=f"ask to reply to this JID, may be used several times",
4308
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
137 )
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
138 addressing_group.add_argument(
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
139 "--no-reply",
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
140 action="store_true",
4327
554a87ae17a6 plugin XEP-0048, XEP-0402; CLI (bookmarks): implement XEP-0402 (PEP Native Bookmarks):
Goffi <goffi@goffi.org>
parents: 4316
diff changeset
141 help="flag this message as not requiring replies",
4308
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
142 )
2081
2265d9df4cfb jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
143 syntax = self.parser.add_mutually_exclusive_group()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
144 syntax.add_argument("-x", "--xhtml", action="store_true", help=_("XHTML body"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
145 syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body"))
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
146 self.parser.add_argument("jid", help=_("the destination jid"))
401
b2caa2615c4c jp roster name manegement + Pipe transfer
Goffi <goffi@goffi.org>
parents: 393
diff changeset
147
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
148 async def send_stdin(self, dest_jid):
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
149 """Send incomming data on stdin to jabber contact
1828
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
150
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
151 @param dest_jid: destination jid
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
152 """
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
153 header = "\n" if self.args.new_line else ""
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
154 # FIXME: stdin is not read asynchronously at the moment
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
155 stdin_lines = [stream for stream in sys.stdin.readlines()]
2081
2265d9df4cfb jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
156 extra = {}
1963
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
157 if self.args.subject is None:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
158 subject = {}
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
159 else:
a2bc5089c2eb backend, frontends: message refactoring (huge commit):
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
160 subject = {self.args.subject_lang: self.args.subject}
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
161
2081
2265d9df4cfb jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
162 if self.args.xhtml or self.args.rich:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
163 key = "xhtml" if self.args.xhtml else "rich"
2081
2265d9df4cfb jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
164 if self.args.lang:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
165 key = f"{key}_{self.args.lang}"
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
166 extra[key] = clean_ustr("".join(stdin_lines))
2081
2265d9df4cfb jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
167 stdin_lines = []
2265d9df4cfb jp (message/send): message/send can now send XHTML (-x) or rich (-r) messages
Goffi <goffi@goffi.org>
parents: 1963
diff changeset
168
4316
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
169 if self.args.headers:
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
170 extra["headers"] = dict(self.args.headers)
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
171
4308
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
172 addresses = {}
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
173 for arg_name in RECIPIENTS_ARGS + [a.replace("-", "_") for a in REPLY_ARGS]:
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
174 values = getattr(self.args, arg_name)
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
175 if values:
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
176 for value in values:
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
177 address_jid = value[0]
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
178 address_desc = " ".join(value[1:]).strip()
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
179 address = {"jid": address_jid}
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
180 if address_desc:
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
181 address["desc"] = address_desc
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
182 addresses.setdefault(arg_name.replace("_", ""), []).append(address)
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
183
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
184 if self.args.no_reply:
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
185 addresses["noreply"] = True
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
186
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
187 if addresses:
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
188 extra["addresses"] = addresses
472a938a46e3 cli (message/send): add arguments for message addressing:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
189
4316
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
190 if self.args.keywords:
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
191 extra["keywords"] = self.args.keywords
1795bfcc38e7 cli (message/send): add arguments to send keywords and headers:
Goffi <goffi@goffi.org>
parents: 4308
diff changeset
192
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
193 to_send = []
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
194
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
195 error = False
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
196
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
197 if self.args.separate:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
198 # we send stdin in several messages
0
goffi@necton2
parents:
diff changeset
199 if header:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
200 # first we sent the header
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
201 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
202 await self.host.bridge.message_send(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
203 dest_jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
204 {self.args.lang: header},
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
205 subject,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
206 self.args.type,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
207 profile_key=self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
208 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
209 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
210 self.disp(f"can't send header: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
211 error = True
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
212
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
213 to_send.extend(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
214 {self.args.lang: clean_ustr(l.replace("\n", ""))} for l in stdin_lines
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
215 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
216 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
217 # we sent all in a single message
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
218 if not (self.args.xhtml or self.args.rich):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
219 msg = {self.args.lang: header + clean_ustr("".join(stdin_lines))}
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
220 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
221 msg = {}
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
222 to_send.append(msg)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
223
3925
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
224 if self.args.attachments:
4023
78b5f356900c component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents: 3925
diff changeset
225 attachments = extra[C.KEY_ATTACHMENTS] = []
3925
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
226 for attachment in self.args.attachments:
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
227 try:
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
228 file_path = str(Path(attachment).resolve(strict=True))
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
229 except FileNotFoundError:
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
230 self.disp("file {attachment} doesn't exists, ignoring", error=True)
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
231 else:
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
232 attachments.append({"path": file_path})
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
233
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
234 for idx, msg in enumerate(to_send):
4023
78b5f356900c component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents: 3925
diff changeset
235 if idx > 0 and C.KEY_ATTACHMENTS in extra:
3925
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
236 # if we send several messages, we only want to send attachments with the
900bf04d87c8 cli (message/send): new `--attach` argument to send an attachment:
Goffi <goffi@goffi.org>
parents: 3887
diff changeset
237 # first one
4023
78b5f356900c component AP gateway: handle attachments
Goffi <goffi@goffi.org>
parents: 3925
diff changeset
238 del extra[C.KEY_ATTACHMENTS]
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
239 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
240 await self.host.bridge.message_send(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
241 dest_jid,
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
242 msg,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
243 subject,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 self.args.type,
3179
84a94b385760 bridge: messageSend's extra is now serialised
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
245 data_format.serialise(extra),
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
246 profile_key=self.host.profile,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
247 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
248 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
249 self.disp(f"can't send message {msg!r}: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
250 error = True
0
goffi@necton2
parents:
diff changeset
251
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
252 if error:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
253 # at least one message sending failed
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
254 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
255
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
256 self.host.quit()
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
257
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
258 async def start(self):
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
259 if self.args.xhtml and self.args.separate:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
260 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
261 "argument -s/--separate is not compatible yet with argument -x/--xhtml",
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
262 error=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
263 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
264 self.host.quit(C.EXIT_BAD_ARG)
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
265
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
266 jids = await self.host.check_jids([self.args.jid])
2740
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
267 jid_ = jids[0]
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
268
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
269 if self.args.encrypt_noreplace and self.args.encrypt is None:
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
270 self.parser.error("You need to use --encrypt if you use --encrypt-noreplace")
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
271
8fd8ce5a5855 jp (message/send, encryption): encryption handling:
Goffi <goffi@goffi.org>
parents: 2719
diff changeset
272 if self.args.encrypt is not None:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
273 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
274 namespace = await self.host.bridge.encryption_namespace_get(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
275 self.args.encrypt
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
276 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
277 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
278 self.disp(f"can't get encryption namespace: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
279 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
280
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
281 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
282 await self.host.bridge.message_encryption_start(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
283 jid_, namespace, not self.args.encrypt_noreplace, self.profile
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
284 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
285 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
286 self.disp(f"can't start encryption session: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
287 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
288
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
289 await self.send_stdin(jid_)
1828
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
290
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
291
3805
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
292 class Retract(base.CommandBase):
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
293
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
294 def __init__(self, host):
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
295 super().__init__(host, "retract", help=_("retract a message"))
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
296
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
297 def add_parser_options(self):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
298 self.parser.add_argument("message_id", help=_("ID of the message (internal ID)"))
3805
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
299
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
300 async def start(self):
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
301 try:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
302 await self.host.bridge.message_retract(self.args.message_id, self.profile)
3805
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
303 except Exception as e:
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
304 self.disp(f"can't retract message: {e}", error=True)
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
305 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
306 else:
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
307 self.disp(
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
308 "message retraction has been requested, please note that this is a "
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
309 "request which can't be enforced (see documentation for details)."
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
310 )
3805
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
311 self.host.quit(C.EXIT_OK)
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
312
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
313
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
314 class MAM(base.CommandBase):
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
315
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
316 def __init__(self, host):
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
317 super(MAM, self).__init__(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
318 host,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
319 "mam",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
320 use_output=C.OUTPUT_MESS,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
321 use_verbose=True,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
322 help=_("query archives using MAM"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
323 )
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
324
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
325 def add_parser_options(self):
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
326 self.parser.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
327 "-s",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
328 "--service",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
329 default="",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
330 help=_("jid of the service (default: profile's server"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
331 )
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
332 self.parser.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
333 "-S",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
334 "--start",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
335 dest="mam_start",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
336 type=base.date_decoder,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
337 help=_("start fetching archive from this date (default: from the beginning)"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
338 )
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
339 self.parser.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
340 "-E",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
341 "--end",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
342 dest="mam_end",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
343 type=base.date_decoder,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
344 help=_("end fetching archive after this date (default: no limit)"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
345 )
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
346 self.parser.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
347 "-W",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
348 "--with",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
349 dest="mam_with",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
350 help=_("retrieve only archives with this jid"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
351 )
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
352 self.parser.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
353 "-m",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
354 "--max",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
355 dest="rsm_max",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
356 type=int,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
357 default=20,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
358 help=_("maximum number of items to retrieve, using RSM (default: 20))"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
359 )
2819
fd45089b3a92 jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
360 rsm_page_group = self.parser.add_mutually_exclusive_group()
fd45089b3a92 jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
361 rsm_page_group.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
362 "-a",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
363 "--after",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
364 dest="rsm_after",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
365 help=_("find page after this item"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
366 metavar="ITEM_ID",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
367 )
2819
fd45089b3a92 jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
368 rsm_page_group.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
369 "-b",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
370 "--before",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
371 dest="rsm_before",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
372 help=_("find page before this item"),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
373 metavar="ITEM_ID",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
374 )
2819
fd45089b3a92 jp (message/mam): added missing RSM options
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
375 rsm_page_group.add_argument(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
376 "--index", dest="rsm_index", type=int, help=_("index of the page to retrieve")
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
377 )
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
378
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
379 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
380 extra = {}
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
381 if self.args.mam_start is not None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
382 extra["mam_start"] = float(self.args.mam_start)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
383 if self.args.mam_end is not None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
384 extra["mam_end"] = float(self.args.mam_end)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
385 if self.args.mam_with is not None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
386 extra["mam_with"] = self.args.mam_with
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
387 for suff in ("max", "after", "before", "index"):
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
388 key = "rsm_" + suff
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
389 value = getattr(self.args, key)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
390 if value is not None:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
391 extra[key] = str(value)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
392 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
393 data, metadata_s, profile = await self.host.bridge.mam_get(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
394 self.args.service, data_format.serialise(extra), self.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
395 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
396 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
397 self.disp(f"can't retrieve MAM archives: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
398 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
399
3356
569f4cf7183b plugin XEP-0313: fixed `MAMGet` signature
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
400 metadata = data_format.deserialise(metadata_s)
569f4cf7183b plugin XEP-0313: fixed `MAMGet` signature
Goffi <goffi@goffi.org>
parents: 3179
diff changeset
401
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
402 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4023
diff changeset
403 session_info = await self.host.bridge.session_infos_get(self.profile)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
404 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
405 self.disp(f"can't get session infos: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
406 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
407
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
408 # we need to fill own_jid for message output
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
409 self.host.own_jid = jid.JID(session_info["jid"])
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
410
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
411 await self.output(data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
412
2719
45189c8bd165 jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents: 2708
diff changeset
413 # FIXME: metadata are not displayed correctly and don't play nice with output
45189c8bd165 jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents: 2708
diff changeset
414 # they should be added to output data somehow
45189c8bd165 jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents: 2708
diff changeset
415 if self.verbosity:
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
416 for value in (
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
417 "rsm_first",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
418 "rsm_last",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
419 "rsm_index",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
420 "rsm_count",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
421 "mam_complete",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
422 "mam_stable",
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
423 ):
2719
45189c8bd165 jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents: 2708
diff changeset
424 if value in metadata:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2824
diff changeset
425 label = value.split("_")[1]
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
426 self.disp(A.color(C.A_HEADER, label, ": ", A.RESET, metadata[value]))
2719
45189c8bd165 jp (message/mam): display metadata when verbose
Goffi <goffi@goffi.org>
parents: 2708
diff changeset
427
2708
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
428 self.host.quit()
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
429
0b5deb9a35fd jp (message): new mam subcommand:
Goffi <goffi@goffi.org>
parents: 2663
diff changeset
430
1828
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
431 class Message(base.CommandBase):
3805
33ab258df0de cli (message/retract): message retractation command:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
432 subcommands = (Send, Retract, MAM)
1828
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
433
cb4be663a4a7 jp (message): message is now a subcommand, and the sending command is moved to message/send
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
434 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
435 super(Message, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
436 host, "message", use_profile=False, help=_("messages handling")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
437 )