diff --git a/synapse/handlers/account_validity.py b/synapse/handlers/account_validity.py
index 947237d7da..795e9afe44 100644
--- a/synapse/handlers/account_validity.py
+++ b/synapse/handlers/account_validity.py
@@ -51,12 +51,10 @@ class AccountValidityHandler(object):
app_name = self.hs.config.email_app_name
self._subject = self._account_validity.renew_email_subject % {
- "app": app_name,
+ "app": app_name
}
- self._from_string = self.hs.config.email_notif_from % {
- "app": app_name,
- }
+ self._from_string = self.hs.config.email_notif_from % {"app": app_name}
except Exception:
# If substitution failed, fall back to the bare strings.
self._subject = self._account_validity.renew_email_subject
@@ -71,16 +69,10 @@ class AccountValidityHandler(object):
)
# Check the renewal emails to send and send them every 30min.
- self.clock.looping_call(
- self.send_renewal_emails,
- 30 * 60 * 1000,
- )
+ self.clock.looping_call(self.send_renewal_emails, 30 * 60 * 1000)
# Check every hour to remove expired users from the user directory
- self.clock.looping_call(
- self._mark_expired_users_as_inactive,
- 60 * 60 * 1000,
- )
+ self.clock.looping_call(self._mark_expired_users_as_inactive, 60 * 60 * 1000)
@defer.inlineCallbacks
def send_renewal_emails(self):
@@ -94,8 +86,7 @@ class AccountValidityHandler(object):
if expiring_users:
for user in expiring_users:
yield self._send_renewal_email(
- user_id=user["user_id"],
- expiration_ts=user["expiration_ts_ms"],
+ user_id=user["user_id"], expiration_ts=user["expiration_ts_ms"]
)
@defer.inlineCallbacks
@@ -154,32 +145,33 @@ class AccountValidityHandler(object):
for address in addresses:
raw_to = email.utils.parseaddr(address)[1]
- multipart_msg = MIMEMultipart('alternative')
- multipart_msg['Subject'] = self._subject
- multipart_msg['From'] = self._from_string
- multipart_msg['To'] = address
- multipart_msg['Date'] = email.utils.formatdate()
- multipart_msg['Message-ID'] = email.utils.make_msgid()
+ multipart_msg = MIMEMultipart("alternative")
+ multipart_msg["Subject"] = self._subject
+ multipart_msg["From"] = self._from_string
+ multipart_msg["To"] = address
+ multipart_msg["Date"] = email.utils.formatdate()
+ multipart_msg["Message-ID"] = email.utils.make_msgid()
multipart_msg.attach(text_part)
multipart_msg.attach(html_part)
logger.info("Sending renewal email to %s", address)
- yield make_deferred_yieldable(self.sendmail(
- self.hs.config.email_smtp_host,
- self._raw_from, raw_to, multipart_msg.as_string().encode('utf8'),
- reactor=self.hs.get_reactor(),
- port=self.hs.config.email_smtp_port,
- requireAuthentication=self.hs.config.email_smtp_user is not None,
- username=self.hs.config.email_smtp_user,
- password=self.hs.config.email_smtp_pass,
- requireTransportSecurity=self.hs.config.require_transport_security
- ))
-
- yield self.store.set_renewal_mail_status(
- user_id=user_id,
- email_sent=True,
- )
+ yield make_deferred_yieldable(
+ self.sendmail(
+ self.hs.config.email_smtp_host,
+ self._raw_from,
+ raw_to,
+ multipart_msg.as_string().encode("utf8"),
+ reactor=self.hs.get_reactor(),
+ port=self.hs.config.email_smtp_port,
+ requireAuthentication=self.hs.config.email_smtp_user is not None,
+ username=self.hs.config.email_smtp_user,
+ password=self.hs.config.email_smtp_pass,
+ requireTransportSecurity=self.hs.config.require_transport_security,
+ )
+ )
+
+ yield self.store.set_renewal_mail_status(user_id=user_id, email_sent=True)
@defer.inlineCallbacks
def _get_email_addresses_for_user(self, user_id):
@@ -264,15 +256,15 @@ class AccountValidityHandler(object):
expiration_ts = self.clock.time_msec() + self._account_validity.period
yield self.store.set_account_validity_for_user(
- user_id=user_id,
- expiration_ts=expiration_ts,
- email_sent=email_sent,
+ user_id=user_id, expiration_ts=expiration_ts, email_sent=email_sent
)
# Check if renewed users should be reintroduced to the user directory
if self._show_users_in_user_directory:
# Show the user in the directory again by setting them to active
- yield self.profile_handler.set_active(UserID.from_string(user_id), True, True)
+ yield self.profile_handler.set_active(
+ UserID.from_string(user_id), True, True
+ )
defer.returnValue(expiration_ts)
@@ -286,10 +278,7 @@ class AccountValidityHandler(object):
"""
# Get expired users
expired_user_ids = yield self.store.get_expired_users()
- expired_users = [
- UserID.from_string(user_id)
- for user_id in expired_user_ids
- ]
+ expired_users = [UserID.from_string(user_id) for user_id in expired_user_ids]
# Mark each one as non-active
for user in expired_users:
|