diff options
author | Andrew Morgan <andrew@amorgan.xyz> | 2020-02-11 16:18:29 +0000 |
---|---|---|
committer | Andrew Morgan <andrew@amorgan.xyz> | 2020-02-11 16:18:29 +0000 |
commit | 0295abdcf70548a7ba9d685598233f34c50127b5 (patch) | |
tree | 766e1facba2e4efefe8b058fb2e71bf7f2619a81 /synapse/handlers/account_validity.py | |
parent | Merge pull request #5042 from matrix-org/erikj/fix_get_missing_events_error (diff) | |
download | synapse-0295abdcf70548a7ba9d685598233f34c50127b5.tar.xz |
Dinsic Blacking with black==18.6b2
Diffstat (limited to 'synapse/handlers/account_validity.py')
-rw-r--r-- | synapse/handlers/account_validity.py | 75 |
1 files changed, 32 insertions, 43 deletions
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: |