plugin XEP-0106, tools (common/email): type hints.

This commit is contained in:
Goffi 2024-09-06 17:44:08 +02:00
commit a4f494ac70
2 changed files with 18 additions and 10 deletions

View file

@ -61,7 +61,7 @@ class XEP_0106(object):
def get_handler(self, client):
return XEP_0106_handler()
def escape(self, text):
def escape(self, text) -> str:
"""Escape text
@param text(unicode): text to escape
@ -78,7 +78,7 @@ class XEP_0106(object):
escaped.append(c)
return "".join(escaped)
def unescape(self, escaped):
def unescape(self, escaped) -> str:
"""Unescape text
@param escaped(unicode): text to unescape

View file

@ -20,7 +20,9 @@
"""email sending facilities"""
from configparser import ConfigParser
from email.mime.text import MIMEText
from twisted.internet import defer
from twisted.mail import smtp
from libervia.backend.core.constants import Const as C
from libervia.backend.tools import config as tools_config
@ -29,16 +31,22 @@ from libervia.backend.core.log import getLogger
log = getLogger(__name__)
def send_email(config, to_emails, subject="", body="", from_email=None):
"""Send an email using SàT configuration
def send_email(
config: ConfigParser,
to_emails: list[str] | str,
subject: str = "",
body: str = "",
from_email: str | None = None,
) -> defer.Deferred:
"""Send an email using Libervia configuration
@param config (ConfigParser): the configuration instance
@param to_emails(list[unicode], unicode): list of recipients
@param config: the configuration instance
@param to_emails: list of recipients
if unicode, it will be split to get emails
@param subject(unicode): subject of the message
@param body(unicode): body of the message
@param from_email(unicode): address of the sender
@return (D): same as smtp.sendmail
@param subject: subject of the message
@param body: body of the message
@param from_email: address of the sender
@return:Same as smtp.sendmail.
"""
if isinstance(to_emails, str):
to_emails = to_emails.split()