From c597a4b9fed3667e46e0adbb05b04db8c72410d8 Mon Sep 17 00:00:00 2001 From: Son NK Date: Sun, 15 Mar 2020 23:02:06 +0100 Subject: [PATCH] do not use formataddr to generate website email --- app/models.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models.py b/app/models.py index 32e312e8..d3582640 100644 --- a/app/models.py +++ b/app/models.py @@ -729,11 +729,18 @@ class ForwardEmail(db.Model, ModelMixin): website_name, _ = parseaddr(self.website_from) if website_name: - return formataddr( - (website_name + " " + self.website_email, self.reply_email) - ) + # remove all double quote + website_name = website_name.replace('"', "") + return f'"{website_name} {self.website_email}" <{self.reply_email}>' - return formataddr((self.website_email.replace("@", " at "), self.reply_email)) + # cannot use formataddr here as this field is for email client, not for MTA + # return formataddr( + # (website_name + " " + self.website_email, self.reply_email) + # ) + + name = self.website_email.replace("@", " at ").replace('"', "") + return f'"{name}" <{self.reply_email}>' + # return formataddr((self.website_email.replace("@", " at "), self.reply_email)) def last_reply(self) -> "ForwardEmailLog": """return the most recent reply"""