Mercurial > libervia-backend
diff sat/plugins/plugin_comp_ap_gateway/regex.py @ 3833:381340b9a9ee
component AP gateway: convert XMPP mentions to AP:
When a XEP-0372 mention is received, the linked pubsub item is looked after in cache, and
if found, it is send to mentioned entity with `mention` tag added.
However, this doesn't work in some cases (see incoming doc for details). To work around
that, `@user@server.tld` type mention are also scanned in body, and mentions are added
when found (this can be disabled with `auto_mentions` setting).
Mention are only scanned in "public" messages, i.e. for pubsub items, and not direct
messages.
rel 369
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 10 Jul 2022 16:15:06 +0200 |
parents | eddab3798aca |
children |
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_ap_gateway/regex.py Sun Jul 10 15:16:15 2022 +0200 +++ b/sat/plugins/plugin_comp_ap_gateway/regex.py Sun Jul 10 16:15:06 2022 +0200 @@ -16,7 +16,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -"""Regular Expression to parse "Signature" header""" +"""Various Regular Expression for AP gateway""" + +import re + +## "Signature" header parsing # those expression have been generated with abnf-to-regex # (https://github.com/aas-core-works/abnf-to-regexp) @@ -38,8 +42,6 @@ # obs-text = %x80-FF # --- -import re - ows = '[ \t]*' bws = f'{ows}' obs_text = '[\\x80-\\xff]' @@ -52,3 +54,11 @@ f'(?P<key>{token}{bws})={bws}' f'((?P<uq_value>{token})|(?P<quoted_value>{quoted_string}))' ) + + +## Account/Mention + +# FIXME: naive regex, should be approved following webfinger, but popular implementations +# such as Mastodon use a very restricted subset +RE_ACCOUNT = re.compile(r"[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-]+") +RE_MENTION = re.compile(rf"(?<!\w)@{RE_ACCOUNT.pattern}\b")