-
-
Notifications
You must be signed in to change notification settings - Fork 61
Support setup with only an IPv4 address, but no domain #894
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
Changes from all commits
bbacd74
808eb3e
f152b0f
8522324
8ae2c47
26c5e1e
2ba19fd
1651917
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import ipaddress | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
|
|
@@ -20,7 +21,10 @@ def read_config(inipath): | |
| class Config: | ||
| def __init__(self, inipath, params): | ||
| self._inipath = inipath | ||
| self.mail_domain = params["mail_domain"] | ||
| if is_valid_ipv4(params["mail_domain"]): | ||
| self.mail_domain = f"[{params.get('mail_domain')}]" | ||
| else: | ||
| self.mail_domain = params["mail_domain"] | ||
| self.max_user_send_per_minute = int(params.get("max_user_send_per_minute", 60)) | ||
| self.max_user_send_burst_size = int(params.get("max_user_send_burst_size", 10)) | ||
| self.max_mailbox_size = params["max_mailbox_size"] | ||
|
|
@@ -76,7 +80,7 @@ def __init__(self, inipath, params): | |
| ) | ||
| self.tls_cert_mode = "external" | ||
| self.tls_cert_path, self.tls_key_path = parts | ||
| elif self.mail_domain.startswith("_"): | ||
| elif self.mail_domain.startswith("_") or is_valid_ipv4(params["mail_domain"]): | ||
| self.tls_cert_mode = "self" | ||
| self.tls_cert_path = "/etc/ssl/certs/mailserver.pem" | ||
| self.tls_key_path = "/etc/ssl/private/mailserver.key" | ||
|
|
@@ -157,3 +161,12 @@ def get_default_config_content(mail_domain, **overrides): | |
| lines.append(line) | ||
| content = "\n".join(lines) | ||
| return content | ||
|
|
||
|
|
||
| def is_valid_ipv4(address: str) -> bool: | ||
| """Check if a mail_domain is an IPv4 address.""" | ||
| try: | ||
| ipaddress.IPv4Address(address) | ||
| return True | ||
| except ValueError: | ||
| return False | ||
|
Comment on lines
+166
to
+172
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would introduce something like |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,11 @@ | |
| from cmdeploy.cmdeploy import main | ||
|
|
||
|
|
||
| def test_init(tmp_path, maildomain): | ||
| def test_init(tmp_path, maildomain_sanitized): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the tests i would make maildomain fixture return the "[]"-stripped ip-address so you don't need to change tests much. "config.mail_domain" would still have the "[]" spelling where needed. sshdomain/imap/smtp fixtures can use maildomain directly then. |
||
| inipath = tmp_path.joinpath("chatmail.ini") | ||
| main(["init", "--config", str(inipath), maildomain]) | ||
| main(["init", "--config", str(inipath), maildomain_sanitized]) | ||
| config = read_config(inipath) | ||
| assert config.mail_domain == maildomain | ||
| assert config.mail_domain.strip("[").strip("]") == maildomain_sanitized | ||
|
|
||
|
|
||
| def test_capabilities(imap): | ||
|
|
@@ -92,7 +92,7 @@ def login_smtp_imap(smtp, imap): | |
| def test_no_vrfy(chatmail_config): | ||
| domain = chatmail_config.mail_domain | ||
|
|
||
| s = smtplib.SMTP(domain) | ||
| s = smtplib.SMTP(domain.strip("[").strip("]")) | ||
| s.starttls() | ||
|
|
||
| s.putcmd("vrfy", f"wrongaddress@{chatmail_config.mail_domain}") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,8 +61,13 @@ def maildomain(chatmail_config): | |
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def sshdomain(maildomain): | ||
| return os.environ.get("CHATMAIL_SSH", maildomain) | ||
| def maildomain_sanitized(maildomain): | ||
| return maildomain.strip("[").strip("]") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is good, should be used everywhere. |
||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def sshdomain(maildomain_sanitized): | ||
| return os.environ.get("CHATMAIL_SSH", maildomain_sanitized) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
|
@@ -75,7 +80,7 @@ def maildomain2(): | |
|
|
||
| @pytest.fixture | ||
| def sshdomain2(maildomain2): | ||
| return os.environ.get("CHATMAIL_SSH2", maildomain2) | ||
| return os.environ.get("CHATMAIL_SSH2", maildomain2.strip("[").strip("]")) | ||
|
|
||
|
|
||
| def pytest_report_header(): | ||
|
|
@@ -176,14 +181,14 @@ def ssl_context(chatmail_config): | |
|
|
||
|
|
||
| @pytest.fixture | ||
| def imap(maildomain, ssl_context): | ||
| return ImapConn(maildomain, ssl_context=ssl_context) | ||
| def imap(maildomain_sanitized, ssl_context): | ||
| return ImapConn(maildomain_sanitized, ssl_context=ssl_context) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def make_imap_connection(maildomain, ssl_context): | ||
| def make_imap_connection(maildomain_sanitized, ssl_context): | ||
| def make_imap_connection(): | ||
| conn = ImapConn(maildomain, ssl_context=ssl_context) | ||
| conn = ImapConn(maildomain_sanitized, ssl_context=ssl_context) | ||
| conn.connect() | ||
| return conn | ||
|
|
||
|
|
@@ -227,14 +232,14 @@ def fetch_all_messages(self): | |
|
|
||
|
|
||
| @pytest.fixture | ||
| def smtp(maildomain, ssl_context): | ||
| return SmtpConn(maildomain, ssl_context=ssl_context) | ||
| def smtp(maildomain_sanitized, ssl_context): | ||
| return SmtpConn(maildomain_sanitized, ssl_context=ssl_context) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def make_smtp_connection(maildomain, ssl_context): | ||
| def make_smtp_connection(maildomain_sanitized, ssl_context): | ||
| def make_smtp_connection(): | ||
| conn = SmtpConn(maildomain, ssl_context=ssl_context) | ||
| conn = SmtpConn(maildomain_sanitized, ssl_context=ssl_context) | ||
| conn.connect() | ||
| return conn | ||
|
|
||
|
|
@@ -321,8 +326,8 @@ def _make_transport(self, domain): | |
| "password": password, | ||
| # Setting server explicitly skips requesting autoconfig XML, | ||
| # see https://datatracker.ietf.org/doc/draft-ietf-mailmaint-autoconfig/ | ||
| "imapServer": domain, | ||
| "smtpServer": domain, | ||
| "imapServer": domain.strip("[").strip("]"), | ||
| "smtpServer": domain.strip("[").strip("]"), | ||
| } | ||
| if self.chatmail_config.tls_cert_mode == "self": | ||
| transport["certificateChecks"] = "acceptInvalidCertificates" | ||
|
|
@@ -454,7 +459,7 @@ def gen_users(self, num): | |
|
|
||
| class CMUser: | ||
| def __init__(self, maildomain, addr, password, ssl_context=None): | ||
| self.maildomain = maildomain | ||
| self.maildomain = maildomain.strip("[").strip("]") | ||
| self.addr = addr | ||
| self.password = password | ||
| self.ssl_context = ssl_context | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.