Mercurial > libervia-backend
comparison sat/tools/common/email.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | 2c187445a3d3 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
27 from sat.core.log import getLogger | 27 from sat.core.log import getLogger |
28 | 28 |
29 log = getLogger(__name__) | 29 log = getLogger(__name__) |
30 | 30 |
31 | 31 |
32 def sendEmail(config, to_emails, subject="", body="", from_email=None): | 32 def send_email(config, to_emails, subject="", body="", from_email=None): |
33 """Send an email using SàT configuration | 33 """Send an email using SàT configuration |
34 | 34 |
35 @param config (SafeConfigParser): the configuration instance | 35 @param config (SafeConfigParser): the configuration instance |
36 @param to_emails(list[unicode], unicode): list of recipients | 36 @param to_emails(list[unicode], unicode): list of recipients |
37 if unicode, it will be split to get emails | 37 if unicode, it will be split to get emails |
40 @param from_email(unicode): address of the sender | 40 @param from_email(unicode): address of the sender |
41 @return (D): same as smtp.sendmail | 41 @return (D): same as smtp.sendmail |
42 """ | 42 """ |
43 if isinstance(to_emails, str): | 43 if isinstance(to_emails, str): |
44 to_emails = to_emails.split() | 44 to_emails = to_emails.split() |
45 email_host = tools_config.getConfig(config, None, "email_server") or "localhost" | 45 email_host = tools_config.config_get(config, None, "email_server") or "localhost" |
46 email_from = from_email or tools_config.getConfig(config, None, "email_from") | 46 email_from = from_email or tools_config.config_get(config, None, "email_from") |
47 | 47 |
48 # we suppose that email domain and XMPP domain are identical | 48 # we suppose that email domain and XMPP domain are identical |
49 domain = tools_config.getConfig(config, None, "xmpp_domain") | 49 domain = tools_config.config_get(config, None, "xmpp_domain") |
50 if domain is None: | 50 if domain is None: |
51 if email_from is not None: | 51 if email_from is not None: |
52 domain = email_from.split("@", 1)[-1] | 52 domain = email_from.split("@", 1)[-1] |
53 else: | 53 else: |
54 domain = "example.net" | 54 domain = "example.net" |
55 | 55 |
56 if email_from is None: | 56 if email_from is None: |
57 email_from = "no_reply@" + domain | 57 email_from = "no_reply@" + domain |
58 email_sender_domain = tools_config.getConfig( | 58 email_sender_domain = tools_config.config_get( |
59 config, None, "email_sender_domain", domain | 59 config, None, "email_sender_domain", domain |
60 ) | 60 ) |
61 email_port = int(tools_config.getConfig(config, None, "email_port", 25)) | 61 email_port = int(tools_config.config_get(config, None, "email_port", 25)) |
62 email_username = tools_config.getConfig(config, None, "email_username") | 62 email_username = tools_config.config_get(config, None, "email_username") |
63 email_password = tools_config.getConfig(config, None, "email_password") | 63 email_password = tools_config.config_get(config, None, "email_password") |
64 email_auth = C.bool(tools_config.getConfig(config, None, "email_auth", C.BOOL_FALSE)) | 64 email_auth = C.bool(tools_config.config_get(config, None, "email_auth", C.BOOL_FALSE)) |
65 email_starttls = C.bool(tools_config.getConfig(config, None, "email_starttls", | 65 email_starttls = C.bool(tools_config.config_get(config, None, "email_starttls", |
66 C.BOOL_FALSE)) | 66 C.BOOL_FALSE)) |
67 | 67 |
68 msg = MIMEText(body, "plain", "UTF-8") | 68 msg = MIMEText(body, "plain", "UTF-8") |
69 msg["Subject"] = subject | 69 msg["Subject"] = subject |
70 msg["From"] = email_from | 70 msg["From"] = email_from |