Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Quota Support to Latest Version of MiaB and resolving code review comments #2387

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

chadfurman
Copy link

@chadfurman chadfurman commented Apr 27, 2024

This is an implementation of mailbox quotas using dovecot's quota capabilities. This pull request supersedes a previous pull request that contained some changes not pertinent to the main repository.

^ @jrsupplee


This PR is an update of #1568 ported to the latest version of MiaB.

TODO:

  • Move conf files to editorconf tool
    • 15-mailboxes.conf
    • 20-imap.conf
    • 90-quota.conf
  • get confirmation that we're okay with how the quota column is being added in the setup script - is this maintainable?
  • get confirmation we're okay with recalculating quotas on setup -- seems fine to me?
  • Figure out why JRSupplee had his own bootstrap script and resolve any discrepencies -- I'm guessing it's largely related to the conf files but could also be initializing dovecot somehow tbd
  • get approval from MiaB team and get merged into mainline

@chadfurman chadfurman mentioned this pull request Apr 27, 2024
@chadfurman
Copy link
Author

Looks like 15-mailbox.conf is just relocated and the script is already updated so it's fine as-is.

@chadfurman
Copy link
Author

Does not appear to be any reason why https://raw.githubusercontent.com/jrsupplee/mailinabox/master/setup/bootstrap.sh was being used instead of https://mailinabox.email/setup.sh?ping=1 -- my best guess is for reasons of pinning the version

.gitignore Outdated
@@ -5,5 +5,6 @@ tools/__pycache__/
externals/
.env
.vagrant
.idea/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small change happy to remove if you want

@chadfurman
Copy link
Author

Woops looks like basing off main was a bad idea. Gonna redo this and base instead off of v68

@chadfurman chadfurman force-pushed the master branch 2 times, most recently from f82be1b to 1795f8a Compare April 27, 2024 22:54
@chadfurman
Copy link
Author

So the conflict is trivial to resolve (just bring in the first line of the if block and also the elseif block) but when I do, it also pulls in the latest commits from main and it causes the setup to break (due to the no password provided bug) so I'm not resolving conflicts just yet.

@chadfurman
Copy link
Author

strangely, I get a 500 error the first time I run setup/start.sh but the second time it works?

@chadfurman
Copy link
Author

When it 500s after setting the password, it seems it fails to create the admin user.

Creating the admin user by hand seems to work?

ubuntu@ip-172-31-36-105:~/mailinabox$ sudo management/cli.py user make-admin 'me@agnai.guide'
sudo: unable to resolve host box.agnai.guide: No address associated with hostname
OK
ubuntu@ip-172-31-36-105:~/mailinabox$ sudo management/cli.py alias add administrator@agnai.guide me@agnai.guide
sudo: unable to resolve host box.agnai.guide: No address associated with hostname
alias added

@chadfurman
Copy link
Author

Fixed the 500, it was related to missing the subprocess module. Fixed some conflicts with the spamassassin.sh script also

@chadfurman
Copy link
Author

I've resolved the conflict -- the remote chadfurman/mailinabox has a somewhat stable and tested version of this tagged as v68a (i.e. git checkout v68a), but the head now lines up with mail-in-a-box/mailinabox to make this easier to merge / manage.

@@ -117,6 +123,14 @@ def setup_key_auth(mgmt_uri):
if "admin" in user['privileges']:
print(user['email'])

elif sys.argv[1] == "user" and sys.argv[2] == "quota" and len(sys.argv) == 4:
# Set a user's quota
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment correct? I don't understand how this sets a user's quota.

@stylnchris
Copy link

stylnchris commented May 6, 2024

Not sure if it helps or not but I've installed this with the v68a 'tag' on my production MiaB server and can confirm it works.

Steps I've taken to install it:

ssh into your box -

cd /root/
mv mailinabox mailinabox.old
git clone https://github.com/chadfurman/mailinabox.git
cd mailinabox
git checkout v68a
sudo setup/start.sh

echo "CREATE TABLE aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT NOT NULL UNIQUE, destination TEXT NOT NULL, permitted_senders TEXT);" | sqlite3 "$db_path";
echo "CREATE TABLE mfa (id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER NOT NULL, type TEXT NOT NULL, secret TEXT NOT NULL, mru_token TEXT, label TEXT, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE);" | sqlite3 "$db_path";
echo "CREATE TABLE auto_aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT NOT NULL UNIQUE, destination TEXT NOT NULL, permitted_senders TEXT);" | sqlite3 "$db_path";
elif sqlite3 $db_path ".schema users" | grep --invert-match quota; then
echo "ALTER TABLE users ADD COLUMN quota TEXT NOT NULL DEFAULT '0';" | sqlite3 $db_path;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've opted to make the quota column type TEXT versus making it a numeric column. Just curious if there was a reason for this choice.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure what is stored in sqlite is basically for the webui to 'display' with what is actually set with maildirsize file for dovecot.

Also don't forget this is based on proven code from @jrsupplee, so some of this code is obviously not written by Chad.

@@ -20,10 +20,12 @@ db_path=$STORAGE_ROOT/mail/users.sqlite
# Create an empty database if it doesn't yet exist.
if [ ! -f "$db_path" ]; then
echo "Creating new user database: $db_path";
echo "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL UNIQUE, password TEXT NOT NULL, extra, privileges TEXT NOT NULL DEFAULT '');" | sqlite3 "$db_path";
echo "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL UNIQUE, password TEXT NOT NULL, extra, privileges TEXT NOT NULL DEFAULT '', quota TEXT NOT NULL DEFAULT '0');" | sqlite3 $db_path;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, '0' means unlimited and non-zero represents the quota. But there's no symbolic representation for "system default' from what I can see. So for example, if I made the system default 1GB, then the users would all get their DB value set to 1GB. If I later were to increase the system default to 10GB, the existing users would stay at 1GB and not inherit the new default.

Correct me if I've overlooked something and that's not how it works, but assuming that description is correct, then I'm wondering if the users that are getting the "system default quota" should have a symbolic representation of this in the DB, so if the default were to be changed, these users inherit the new value automatically.

Copy link

@stylnchris stylnchris May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quota is not applied, by default so it is basically set to 0. 0 represents "no quota or 'unlimited' quota" (obviously the limit is the size of the hard-drive for miab server.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creating a new user will give you the option to specify a quota with the new user.

miab_quota

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is an example of setting the quota:

miab_quota3

Then enter the number and and click the "set quota" button

miab_quota2

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my confusion stems from the fact that 0 means unlimited, but I also see a system default-quota value that can be set, and I'm not sure what role that default value plays in this. How would I set a user to the "default-quota" value?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dms00 - Will not having some of these answers prevent this from being merged? Again, code is based on original code from PR - #1568 created by @jrsupplee. Of which we don't have all the answers as to why things were done the original way. Perhaps this was meant for something that wasn't implemented. I do appreciate you reviewing this though. If its required for the PR to be completed we can try to figure out what John was doing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to use it but when I set quota and try to send a mail that has attachments to exceed the quota it errors but mail still sent but it didn't saved as sent folder.. How can I prevent that?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you installed the fork, you set a quota. Then you tried to send mail out of that mailbox in order to exceed the quota. It sends the mail, but doesnt save the mail in the sent box.

Am I understanding the above correctly?

You wouldn't prevent that, that is the expected result. Once a user hits a quota that is set, they need to either remove mail from their mailbox, sent folder, trash, etc or things become a bit unstable (by design) you wont be allowed to future things to disk as you exceed the quota.

How can you prevent it, give yourself more quota or delete mail.

Maybe I dont understand correctly though....

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You understand correctly but I want to prevent that email sent. If quota is full user shouldn't be able to use it. And what can be do about 1 quota per domain? like example.com has 10GB total quota and every user in it like hi@example.com go@example.com has same quota based on domain but it will not affect to example.net?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I understand what you would like to see, but I believe this is a limitation of Dovecot / Postfix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants