diff --git a/api/tasks/mail_change_mail_task.py b/api/tasks/mail_change_mail_task.py index 17b534e246..da44040b7d 100644 --- a/api/tasks/mail_change_mail_task.py +++ b/api/tasks/mail_change_mail_task.py @@ -29,63 +29,44 @@ def send_change_mail_task(language: str, to: str, code: str, phase: str): "old_email": { "subject": "检测您现在的邮箱", "template_with_brand": "change_mail_confirm_old_template_zh-CN.html", - "template_without_brand": "without-brand/change_mail_confirm_old_template_zh-CN.html" + "template_without_brand": "without-brand/change_mail_confirm_old_template_zh-CN.html", }, "new_email": { "subject": "确认您的邮箱地址变更", "template_with_brand": "change_mail_confirm_new_template_zh-CN.html", - "template_without_brand": "without-brand/change_mail_confirm_new_template_zh-CN.html" - } + "template_without_brand": "without-brand/change_mail_confirm_new_template_zh-CN.html", + }, }, "en": { "old_email": { "subject": "Check your current email", "template_with_brand": "change_mail_confirm_old_template_en-US.html", - "template_without_brand": "without-brand/change_mail_confirm_old_template_en-US.html" + "template_without_brand": "without-brand/change_mail_confirm_old_template_en-US.html", }, "new_email": { "subject": "Confirm your new email address", "template_with_brand": "change_mail_confirm_new_template_en-US.html", - "template_without_brand": "without-brand/change_mail_confirm_new_template_en-US.html" - } - } + "template_without_brand": "without-brand/change_mail_confirm_new_template_en-US.html", + }, + }, } # send change email mail using different languages try: system_features = FeatureService.get_system_features() - if language == "zh-Hans": - if phase == "old_email": - subject = "检测您现在的邮箱" - if system_features.branding.enabled: - template = "without-brand/change_mail_confirm_old_template_zh-CN.html" - else: - template = "change_mail_confirm_old_template_zh-CN.html" - elif phase == "new_email": - subject = "确认您的邮箱地址变更" - if system_features.branding.enabled: - template = "without-brand/change_mail_confirm_new_template_zh-CN.html" - else: - template = "change_mail_confirm_new_template_zh-CN.html" - else: - raise ValueError("Invalid phase") + lang_key = "zh-Hans" if language == "zh-Hans" else "en" + + if phase not in ["old_email", "new_email"]: + raise ValueError("Invalid phase") + + config = email_config[lang_key][phase] + subject = config["subject"] + + if system_features.branding.enabled: + template = config["template_without_brand"] else: - if phase == "old_email": - subject = "Check your current email" - if system_features.branding.enabled: - template = "without-brand/change_mail_confirm_old_template_en-US.html" - else: - template = "change_mail_confirm_old_template_en-US.html" - elif phase == "new_email": - subject = "Confirm your new email address" - if system_features.branding.enabled: - template = "without-brand/change_mail_confirm_new_template_en-US.html" - else: - template = "change_mail_confirm_new_template_en-US.html" - else: - raise ValueError("Invalid phase") + template = config["template_with_brand"] - html_content = render_template(template, to=to, code=code) mail.send(to=to, subject=subject, html=html_content)