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

fix: don't crash if user doesn't exist in mailcow #133

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ To setup your development environment, you need to do something like this:
git clone https://github.com/deltachat/mailadm
python3 -m venv venv
. venv/bin/activate
pip install pytest tox pytest-xdist pytest-timeout pyzbar
pip install pytest tox pytest-xdist pytest-timeout pyzbar black ruff
sudo apt install -y libzbar0
pip install .

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools_scm"]
build-backend = "setuptools.build_meta"

[tool.ruff]
select = [
lint.select = [
"E", "W", # pycodestyle
"F", # Pyflakes
"N", # pep8-naming
Expand All @@ -24,7 +24,7 @@ select = [
"PLE", # Pylint Error
"PLW", # Pylint Warning
]
ignore = ["PT001", "PT016", "PT011"]
lint.ignore = ["PT001", "PT016", "PT011"]
line-length = 100

[tool.black]
Expand Down
1 change: 1 addition & 0 deletions src/mailadm/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
help gunicorn and other WSGI servers to instantiate a web instance of mailadm
"""

import threading

from mailadm.bot import get_admbot_db_path
Expand Down
6 changes: 5 additions & 1 deletion src/mailadm/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ def get_expired_users(self, sysdate):
if user.ttl < mailadm.util.parse_expiry_code("27d"):
expired_users.append(user)
continue
last_login = self.get_mailcow_connection().get_user(user.addr).last_login
mc_user = self.get_mailcow_connection().get_user(user.addr)
if mc_user is None:
logging.warning("user %s doesn't exist in mailcow", user.addr)
continue
last_login = mc_user.last_login
# expire users who weren't online for longer than 25% of their TTL:
if sysdate - last_login > user.ttl * 0.25:
expired_users.append(user)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ deps =
black
commands =
rst-lint README.rst CHANGELOG.rst doc/index.rst
ruff src/ tests/
ruff check src/ tests/
black --check --diff src/ tests/

[testenv:check-manifest]
Expand Down
Loading