Commit graph

48 commits

Author SHA1 Message Date
Aine
fda0d62087
send emails 2022-09-04 22:09:53 +03:00
Aine
104e948b9c
remove migrations 2022-08-31 10:33:13 +03:00
Aine
84b1900dbb
adjust initBotUsers() 2022-08-30 18:29:16 +03:00
Aine
cec2761911
users adjustments 2022-08-30 15:43:06 +03:00
Aine
9f66d1fee6
rename options, rename settings types 2022-08-30 14:45:07 +03:00
Aine
5ed3a53223
diff bot and room settings 2022-08-30 14:37:19 +03:00
Aine
f97ebb604a
manage users in runtime, closes #16 2022-08-29 21:41:14 +03:00
Aine
0ba951fbe6
set default POSTMOOGLE_USERS pattern 2022-08-29 20:56:28 +03:00
Aine
e0bd71717c
remove NOOWNER, closes #14 2022-08-29 20:21:37 +03:00
Aine
505a1b42d7
removed federation, closes #12 2022-08-29 19:58:54 +03:00
Aine
5a5a649cba
add cache 2022-08-29 15:28:37 +03:00
Aine
6623251695
refactored 2022-08-29 12:30:43 +03:00
Slavi Pantaleev
a057654962 Put command access checks on the command level
Checking using `settings.Allowed` is odd. Not all commands are related
to setting configuration settings. Admin commands are coming in the
future, for which this is certainly not the case.

We now do access checks early on (during command processing), so command
handlers can be clean of access checks. If we're inside of a command
handler, the user is privileged to run it.
2022-08-29 10:27:53 +03:00
Slavi Pantaleev
a62dc0df4f Add POSTMOOGLE_ADMINS 2022-08-29 09:10:31 +03:00
Slavi Pantaleev
1d6b43a83a Reindent bot/bot.go 2022-08-28 17:56:19 +03:00
Slavi Pantaleev
dc5ed41723 Merge branch 'main' into 'user-whitelisting'
# Conflicts:
#   bot/bot.go
2022-08-28 14:50:57 +00:00
Aine
13776ad7a6
properly update mailbox, fixes #9 2022-08-28 09:37:18 +03:00
Aine
d1c48b9b31
add per-room mutex, possibly fixes #8 2022-08-27 22:10:22 +03:00
Slavi Pantaleev
8ad2e29930 Add support for configuring user whitelisting
This does not do anything useful just yet.
It will be hooked to access control checks later on.

Wildcards are converted to regular expressions, because it was simpler
to do that than to write (or include) some ugly wildcard matcher library.
It also provides more flexibility, should we wish to use it later.
Regular expressions should also work well performance-wise.

We compile wildcards to regexes early on (during configuration
processing) and fail if we detect a bad pattern. This is meant to
catch various problems (typos or other mistakes) that could happen.

For this to work, configuration building had to be redone, since it can
now return an error. This may be useful in the future for validating
other configuration settings.

Related to https://gitlab.com/etke.cc/postmoogle/-/issues/1
2022-08-27 07:50:41 +03:00
Aine
f2d81495dc
refactor Send(), fixes #6 2022-08-26 23:06:20 +03:00
Aine
4000b39480
add custom status message 2022-08-26 16:40:43 +03:00
Aine
2da1aacc7a
automatically remove mailboxes in empty rooms, fixes #3 2022-08-26 16:22:44 +03:00
Aine
2dcba843cc
add 'nofiles' option, refactored bot.Send(); fixes #2 2022-08-26 16:11:08 +03:00
Aine
42c9e15619
add 'nothreads' option, fixes #4 2022-08-26 16:00:37 +03:00
Aine
41a52c1eca
add 'nohtml' option, fixes #5 2022-08-26 15:56:25 +03:00
Aine
0a5bc5d989
refactor rooms/roomsmu to sync.Map 2022-08-25 22:38:45 +03:00
Aine
b0c274491f
refactor to context, remove sentry spans 2022-08-25 22:31:12 +03:00
Slavi Pantaleev
06856adb86 Simplify code 2022-08-25 21:38:42 +03:00
Slavi Pantaleev
236a128129 Fix double membership=join event handling
This fixes the problem mentioned in 8e1aa5b11c.

Turns out that it's a long-standing Synapse bug:
https://github.com/matrix-org/synapse/issues/9768
2022-08-25 20:18:09 +03:00
Slavi Pantaleev
1babbb7169 Make Notice() not do string formatting anymore
In various places, we build messages using `Sprintf` before passing them
to `Notice()`.

If we let `Notice()` do string formatting, we run the chance of having
it try to format our already-preformatted text. If our text includes
format references (e.g. `%s`), it would cause a problem (`%s(MISSING)`).

One way to trigger it is to change the bot prefix from `!pm` to `%pm`.
Doing so, `sendHelp()` would create some help message which contains
`%pm` references. `Notice()` would then try to process them as well,
leading to a bunch of `%!p(MISSING)m` in the final text.
2022-08-25 10:55:15 +03:00
Aine
f9cf94c914
threads 2022-08-24 21:28:30 +03:00
Slavi Pantaleev
16ce4314b9 Sanitize settings on Get() and add convenience getters
Sanitizing options on Get() ensures that when someone asks
for a given option which may not be defined (`nosubject`, `nosender`),
we'll return a valid value (`'true'` or `'false'`) and not `''` (empty
string, undefined).

This way, users do not need to wonder if "nosender is not set" is
handled like "true" or "false" or in some 3rd way. They also don't need
to think about "how to unset this setting, now that I've set it to something".
Options will appear to have a default sanitized value no matter if
they've explicitly been set or not.

The `NoSender()` and `NoSubject()` getters are just there for
convenience, so that we won't need to do casting in other places.
2022-08-24 10:16:28 +03:00
Slavi Pantaleev
e4acbb31f0 Add nosubject option 2022-08-24 07:37:34 +03:00
Aine
85fc06cfce
lint; rearrange code 2022-08-23 22:12:11 +03:00
Aine
e5e9be528b
refactor options to be more generic 2022-08-23 21:58:05 +03:00
Aine
81abe8c785
unoptimal refactoring 2022-08-23 19:23:15 +03:00
Aine
609e19c133
Merge branch 'main' into hide-sender-address-support 2022-08-23 18:58:40 +03:00
Slavi Pantaleev
9f3aa3dd68 Add ability to hide sender's email address (hide-sender-address setting)
The configuration setting is called `Hide*` instead of `Show*`, because
it's backward compatible with existing configuration settings.

This is useful for when you setup an email forwarding inbox and you're
always sending to it through the same email address. In that case, you
don't need to see the email address in each Matrix message.

In the future, another similar `bool` setting (`hide-subject`) will land,
which controls whether the email's subject is shown in the final message
or not. That setting can make use of most of the same setup (all of
`handleBooleanConfigurationKey`).
2022-08-23 18:21:23 +03:00
Aine
0178c3cff3
do not convert plaintext as html 2022-08-23 18:11:38 +03:00
Aine
24686ef501
lint fixes 2022-08-23 17:56:38 +03:00
Slavi Pantaleev
b79a728967 Use notice instead of error for expected "errors"
Notice() is like Error(), but:

- the message is not sent to the error log (and Sentry)
- the message sent to the room is not prefixed with `ERROR: `
2022-08-23 17:52:07 +03:00
Aine
848d6a7187
refactor mappings getter 2022-08-22 23:24:51 +03:00
Aine
0decd4fad6
add noowner and federation 2022-08-22 22:08:32 +03:00
Aine
69f20e5670
try to receive attachments 2022-08-22 18:43:12 +03:00
Aine
abb6c027bf
fix autojoins 2022-08-22 16:22:55 +03:00
Aine
e6d5e81efe
bugfixes; email parsing; send emails into matrix rooms; e2e tests 2022-08-22 12:28:29 +03:00
Aine
c746c91dbb
account data only; integrate smtp server; logging 2022-08-21 23:00:20 +03:00
Aine
c4b7a16e21
wip 2022-08-21 18:41:35 +03:00