component: mail_from_realname config setting added to IPA-EPN

Adding mail_from_realname setting to configuration so that the real name of the sender of the password expiration notification can be customized. This addition does not affect existing configurations.

Fixes: https://pagure.io/freeipa/issue/9336

Signed-off-by: Simon Nussbaum <simon.nussbaum@adfinis.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Simon Nussbaum 2023-02-24 16:08:14 +01:00 committed by Rob Crittenden
parent a78c47b2d3
commit fcad9c9aa7
4 changed files with 17 additions and 4 deletions

View File

@ -86,6 +86,9 @@ Time to wait, in milliseconds, between each e-mail sent to try to avoid overload
Specifies the From: e-mail address value in the e-mails sent. The default is noreply@ipadefaultemaildomain. This value can be found by running Specifies the From: e-mail address value in the e-mails sent. The default is noreply@ipadefaultemaildomain. This value can be found by running
.I ipa config-show .I ipa config-show
.TP .TP
.B mail_from_name <name>
Specifies the From: name value in the e-mails sent. The default is IPA-EPN.
.TP
.B notify_ttls <list of days> .B notify_ttls <list of days>
This is the list of days before a password expiration when ipa-epn should notify a user that their password will soon require a reset. If this value is not specified then the default list will be used: 28, 14, 7, 3, 1. This is the list of days before a password expiration when ipa-epn should notify a user that their password will soon require a reset. If this value is not specified then the default list will be used: 28, 14, 7, 3, 1.
.TP .TP

View File

@ -60,6 +60,10 @@ smtp_delay = 0
# This value can be found by running ipa config-show. # This value can be found by running ipa config-show.
# mail_from = # mail_from =
# Specifies the From: name value in the e-mails-sent.
# The default when unset is IPA-EPN.
# mail_from_name =
# The list of days before a password expiration when ipa-epn should notify # The list of days before a password expiration when ipa-epn should notify
# a user that their password will soon require a reset. # a user that their password will soon require a reset.
notify_ttls = 28, 14, 7, 3, 1 notify_ttls = 28, 14, 7, 3, 1

View File

@ -64,6 +64,7 @@ EPN_CONFIG = {
"smtp_admin": "root@localhost", "smtp_admin": "root@localhost",
"smtp_delay": None, "smtp_delay": None,
"mail_from": None, "mail_from": None,
"mail_from_name": "IPA-EPN",
"notify_ttls": "28,14,7,3,1", "notify_ttls": "28,14,7,3,1",
"msg_charset": "utf8", "msg_charset": "utf8",
"msg_subtype": "plain", "msg_subtype": "plain",
@ -565,6 +566,7 @@ class EPN(admintool.AdminTool):
mail_body=body, mail_body=body,
subscribers=ast.literal_eval(entry["mail"]), subscribers=ast.literal_eval(entry["mail"]),
mail_from=mail_from, mail_from=mail_from,
mail_from_name=api.env.mail_from_name,
) )
now = datetime.utcnow() now = datetime.utcnow()
expdate = datetime.strptime( expdate = datetime.strptime(
@ -799,12 +801,13 @@ class MailUserAgent:
def send_message( def send_message(
self, mail_subject=None, mail_body=None, subscribers=None, self, mail_subject=None, mail_body=None, subscribers=None,
mail_from=None mail_from=None, mail_from_name=None
): ):
"""Given mail_subject, mail_body, and subscribers, composes """Given mail_subject, mail_body, and subscribers, composes
the message and sends it. the message and sends it.
""" """
if None in [mail_subject, mail_body, subscribers, mail_from]: if None in [mail_subject, mail_body, subscribers,
mail_from, mail_from_name]:
logger.error("IPA-EPN: Tried to send an empty message.") logger.error("IPA-EPN: Tried to send an empty message.")
return False return False
self._compose_message( self._compose_message(
@ -812,6 +815,7 @@ class MailUserAgent:
mail_body=mail_body, mail_body=mail_body,
subscribers=subscribers, subscribers=subscribers,
mail_from=mail_from, mail_from=mail_from,
mail_from_name=mail_from_name,
) )
self._mta_client.send_message( self._mta_client.send_message(
message_str=self._message_str, subscribers=subscribers message_str=self._message_str, subscribers=subscribers
@ -819,7 +823,8 @@ class MailUserAgent:
return True return True
def _compose_message( def _compose_message(
self, mail_subject, mail_body, subscribers, mail_from self, mail_subject, mail_body, subscribers,
mail_from, mail_from_name
): ):
"""The composer creates a MIME multipart message. """The composer creates a MIME multipart message.
""" """
@ -829,7 +834,7 @@ class MailUserAgent:
self._subscribers = subscribers self._subscribers = subscribers
self._msg = MIMEMultipart(_charset=self._charset) self._msg = MIMEMultipart(_charset=self._charset)
self._msg["From"] = formataddr(("IPA-EPN", mail_from)) self._msg["From"] = formataddr((mail_from_name, mail_from))
self._msg["To"] = ", ".join(self._subscribers) self._msg["To"] = ", ".join(self._subscribers)
self._msg["Date"] = formatdate(localtime=True) self._msg["Date"] = formatdate(localtime=True)
self._msg["Subject"] = Header(self._subject, self._charset) self._msg["Subject"] = Header(self._subject, self._charset)

View File

@ -513,6 +513,7 @@ AstroidBuilder(MANAGER).string_build(textwrap.dedent(
api.env.smtp_admin = "" api.env.smtp_admin = ""
api.env.smtp_delay = None api.env.smtp_delay = None
api.env.mail_from = None api.env.mail_from = None
api.env.mail_from_name = None
api.env.notify_ttls = "" api.env.notify_ttls = ""
api.env.msg_charset = "" api.env.msg_charset = ""
api.env.msg_subtype = "" api.env.msg_subtype = ""