mirror of
https://github.com/chatmail/relay.git
synced 2026-05-18 16:08:57 +00:00
Compare commits
32 Commits
link2xt/rs
...
hpk/fixup
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb1424f944 | ||
|
|
0931da21b8 | ||
|
|
11a8f8cf9e | ||
|
|
0aa255e3f1 | ||
|
|
6c4764b452 | ||
|
|
c1f08a9afe | ||
|
|
5c8afb377e | ||
|
|
8225a9f398 | ||
|
|
eb221ca1af | ||
|
|
93421b317b | ||
|
|
777be107f3 | ||
|
|
8b81d5b5d6 | ||
|
|
e6a2906e82 | ||
|
|
67ba4ac99e | ||
|
|
8cadf51387 | ||
|
|
ce4bb97294 | ||
|
|
3a0c629f3b | ||
|
|
8df53c2655 | ||
|
|
3fd3ab1a68 | ||
|
|
d74f792787 | ||
|
|
1135372b81 | ||
|
|
c9f80bffd8 | ||
|
|
10e53d17e8 | ||
|
|
01ca2a8b91 | ||
|
|
fb01944f0d | ||
|
|
a90a651ba0 | ||
|
|
7d74b46502 | ||
|
|
6d3e690653 | ||
|
|
ed7a70ba31 | ||
|
|
023116bc91 | ||
|
|
b13929119b | ||
|
|
a4152140ca |
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
## untagged
|
## untagged
|
||||||
|
|
||||||
- Require TLS 1.2 for outgoing SMTP connections
|
|
||||||
([#685](https://github.com/chatmail/relay/pull/685))
|
|
||||||
|
|
||||||
- filtermail: run CPU-intensive handle_DATA in a thread pool executor
|
- filtermail: run CPU-intensive handle_DATA in a thread pool executor
|
||||||
([#676](https://github.com/chatmail/relay/pull/676))
|
([#676](https://github.com/chatmail/relay/pull/676))
|
||||||
|
|
||||||
|
|||||||
@@ -22,30 +22,11 @@ def iter_mailboxes(basedir, maxnum):
|
|||||||
print_info(f"no mailboxes found at: {basedir}")
|
print_info(f"no mailboxes found at: {basedir}")
|
||||||
return
|
return
|
||||||
|
|
||||||
for name in os_listdir_if_exists(basedir)[:maxnum]:
|
for name in os.listdir(basedir)[:maxnum]:
|
||||||
if "@" in name:
|
if "@" in name:
|
||||||
yield MailboxStat(basedir + "/" + name)
|
yield MailboxStat(basedir + "/" + name)
|
||||||
|
|
||||||
|
|
||||||
def get_file_entry(path):
|
|
||||||
"""return a FileEntry or None if the path does not exist or is not a regular file."""
|
|
||||||
try:
|
|
||||||
st = os.stat(path)
|
|
||||||
except FileNotFoundError:
|
|
||||||
return None
|
|
||||||
if not S_ISREG(st.st_mode):
|
|
||||||
return None
|
|
||||||
return FileEntry(path, st.st_mtime, st.st_size)
|
|
||||||
|
|
||||||
|
|
||||||
def os_listdir_if_exists(path):
|
|
||||||
"""return a list of names obtained from os.listdir or an empty list if the path does not exist."""
|
|
||||||
try:
|
|
||||||
return os.listdir(path)
|
|
||||||
except FileNotFoundError:
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
class MailboxStat:
|
class MailboxStat:
|
||||||
last_login = None
|
last_login = None
|
||||||
|
|
||||||
@@ -59,23 +40,19 @@ class MailboxStat:
|
|||||||
|
|
||||||
# scan all relevant files (without recursion)
|
# scan all relevant files (without recursion)
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
try:
|
os.chdir(self.basedir)
|
||||||
os.chdir(self.basedir)
|
for name in os.listdir("."):
|
||||||
except FileNotFoundError:
|
|
||||||
return
|
|
||||||
for name in os_listdir_if_exists("."):
|
|
||||||
if name in ("cur", "new", "tmp"):
|
if name in ("cur", "new", "tmp"):
|
||||||
for msg_name in os_listdir_if_exists(name):
|
for msg_name in os.listdir(name):
|
||||||
entry = get_file_entry(f"{name}/{msg_name}")
|
relpath = name + "/" + msg_name
|
||||||
if entry is not None:
|
st = os.stat(relpath)
|
||||||
self.messages.append(entry)
|
self.messages.append(FileEntry(relpath, st.st_mtime, st.st_size))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
entry = get_file_entry(name)
|
st = os.stat(name)
|
||||||
if entry is not None:
|
if S_ISREG(st.st_mode):
|
||||||
self.extrafiles.append(entry)
|
self.extrafiles.append(FileEntry(name, st.st_mtime, st.st_size))
|
||||||
if name == "password":
|
if name == "password":
|
||||||
self.last_login = entry.mtime
|
self.last_login = st.st_mtime
|
||||||
self.extrafiles.sort(key=lambda x: -x.size)
|
self.extrafiles.sort(key=lambda x: -x.size)
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
|
|
||||||
@@ -103,13 +80,9 @@ class Expiry:
|
|||||||
shutil.rmtree(mboxdir)
|
shutil.rmtree(mboxdir)
|
||||||
self.del_mboxes += 1
|
self.del_mboxes += 1
|
||||||
|
|
||||||
def remove_file(self, path, mtime=None):
|
def remove_file(self, path):
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
if mtime is not None:
|
print_info(f"removing {path}")
|
||||||
date = datetime.fromtimestamp(mtime).strftime("%b %d")
|
|
||||||
print_info(f"removing {date} {path}")
|
|
||||||
else:
|
|
||||||
print_info(f"removing {path}")
|
|
||||||
if not self.dry:
|
if not self.dry:
|
||||||
try:
|
try:
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
@@ -131,27 +104,18 @@ class Expiry:
|
|||||||
return
|
return
|
||||||
|
|
||||||
# all to-be-removed files are relative to the mailbox basedir
|
# all to-be-removed files are relative to the mailbox basedir
|
||||||
try:
|
os.chdir(mbox.basedir)
|
||||||
os.chdir(mbox.basedir)
|
|
||||||
except FileNotFoundError:
|
|
||||||
print_info(f"mailbox not found/vanished {mbox.basedir}")
|
|
||||||
return
|
|
||||||
|
|
||||||
mboxname = os.path.basename(mbox.basedir)
|
mboxname = os.path.basename(mbox.basedir)
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
date = datetime.fromtimestamp(mbox.last_login) if mbox.last_login else None
|
print_info(f"checking for mailbox messages in: {mboxname}")
|
||||||
if date:
|
|
||||||
print_info(f"checking mailbox {date.strftime('%b %d')} {mboxname}")
|
|
||||||
else:
|
|
||||||
print_info(f"checking mailbox (no last_login) {mboxname}")
|
|
||||||
self.all_files += len(mbox.messages)
|
self.all_files += len(mbox.messages)
|
||||||
for message in mbox.messages:
|
for message in mbox.messages:
|
||||||
if message.mtime < cutoff_mails:
|
if message.mtime < cutoff_mails:
|
||||||
self.remove_file(message.relpath, mtime=message.mtime)
|
self.remove_file(message.relpath)
|
||||||
elif message.size > 200000 and message.mtime < cutoff_large_mails:
|
elif message.size > 200000 and message.mtime < cutoff_large_mails:
|
||||||
# we only remove noticed large files (not unnoticed ones in new/)
|
# we only remove noticed large files (not unnoticed ones in new/)
|
||||||
if message.relpath.startswith("cur/"):
|
if message.relpath.startswith("cur/"):
|
||||||
self.remove_file(message.relpath, mtime=message.mtime)
|
self.remove_file(message.relpath)
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
changed = True
|
changed = True
|
||||||
|
|||||||
@@ -6,13 +6,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from chatmaild.expire import (
|
from chatmaild.expire import FileEntry, MailboxStat, iter_mailboxes
|
||||||
FileEntry,
|
|
||||||
MailboxStat,
|
|
||||||
get_file_entry,
|
|
||||||
iter_mailboxes,
|
|
||||||
os_listdir_if_exists,
|
|
||||||
)
|
|
||||||
from chatmaild.expire import main as expiry_main
|
from chatmaild.expire import main as expiry_main
|
||||||
from chatmaild.fsreport import main as report_main
|
from chatmaild.fsreport import main as report_main
|
||||||
|
|
||||||
@@ -133,18 +127,3 @@ def test_expiry_cli_old_files(capsys, example_config, mbox1):
|
|||||||
pytest.fail(f"failed to remove {path}\n{err}")
|
pytest.fail(f"failed to remove {path}\n{err}")
|
||||||
|
|
||||||
assert "shouldstay" not in err
|
assert "shouldstay" not in err
|
||||||
|
|
||||||
|
|
||||||
def test_get_file_entry(tmp_path):
|
|
||||||
assert get_file_entry(str(tmp_path.joinpath("123123"))) is None
|
|
||||||
p = tmp_path.joinpath("x")
|
|
||||||
p.write_text("hello")
|
|
||||||
entry = get_file_entry(str(p))
|
|
||||||
assert entry.size == 5
|
|
||||||
assert entry.mtime
|
|
||||||
|
|
||||||
|
|
||||||
def test_os_listdir_if_exists(tmp_path):
|
|
||||||
tmp_path.joinpath("x").write_text("hello")
|
|
||||||
assert len(os_listdir_if_exists(str(tmp_path))) == 1
|
|
||||||
assert len(os_listdir_if_exists(str(tmp_path.joinpath("123123")))) == 0
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ request:
|
|||||||
provider: https://acme-v02.api.letsencrypt.org/directory
|
provider: https://acme-v02.api.letsencrypt.org/directory
|
||||||
key:
|
key:
|
||||||
type: rsa
|
type: rsa
|
||||||
rsa-size: 4096
|
|
||||||
challenge:
|
challenge:
|
||||||
webroot-paths:
|
webroot-paths:
|
||||||
- /var/www/html/.well-known/acme-challenge
|
- /var/www/html/.well-known/acme-challenge
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ smtp_tls_security_level=verify
|
|||||||
smtp_tls_servername = hostname
|
smtp_tls_servername = hostname
|
||||||
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
|
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
|
||||||
smtp_tls_policy_maps = inline:{nauta.cu=may}
|
smtp_tls_policy_maps = inline:{nauta.cu=may}
|
||||||
smtp_tls_protocols = >=TLSv1.2
|
|
||||||
smtpd_tls_protocols = >=TLSv1.2
|
smtpd_tls_protocols = >=TLSv1.2
|
||||||
|
|
||||||
# Disable anonymous cipher suites
|
# Disable anonymous cipher suites
|
||||||
|
|||||||
Reference in New Issue
Block a user