Skip to content

Commit b2b92d1

Browse files
committed
fix: split the mail_host to check for a port value
1 parent b390cc6 commit b2b92d1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/vsc/utils/mail.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,26 @@ def __init__(
7777
smtp_auth_password=None,
7878
smtp_use_starttls=False,
7979
mail_config=None):
80+
"""
81+
- If there is a config file provided, its values take precedence over the arguments passed to __init__
82+
- If the mail_host is of the format host:port, that port takes precedence over mail_port
83+
"""
8084

8185
mail_options = ConfigParser()
8286
if mail_config:
8387
logging.info("Reading config file: %s", mail_config)
8488
with open(mail_config, "r") as mc:
8589
mail_options.read_file(mc)
8690

87-
self.mail_host = mail_options.get("main", "mail_host", fallback=mail_host)
88-
self.mail_port = int(mail_options.get("main", "mail_port", fallback=mail_port))
91+
# we can have cases where the host part is actually host:port
92+
_mail_host = mail_options.get("main", "mail_host", fallback=mail_host)
93+
try:
94+
self.mail_host, _mail_port = _mail_host.split(":")
95+
except ValueError:
96+
self.mail_host = _mail_host
97+
_mail_port = mail_options.get("main", "mail_port", fallback=mail_port)
98+
99+
self.mail_port = int(_mail_port)
89100
self.smtp_auth_user = mail_options.get("main", "smtp_auth_user", fallback=smtp_auth_user)
90101
self.smtp_auth_password = mail_options.get("main", "smtp_auth_password", fallback=smtp_auth_password)
91102
self.smtp_use_starttls = mail_options.get("main", "smtp_use_starttls", fallback=smtp_use_starttls)

0 commit comments

Comments
 (0)