Dedupe email address
This commit is contained in:
parent
61e4455406
commit
d8ed1cbbc3
|
@ -1181,19 +1181,16 @@ class Contact(db.Model, ModelMixin):
|
||||||
or user.sender_format == SenderFormatEnum.VIA.value
|
or user.sender_format == SenderFormatEnum.VIA.value
|
||||||
):
|
):
|
||||||
new_name = f"{self.website_email} via SimpleLogin"
|
new_name = f"{self.website_email} via SimpleLogin"
|
||||||
elif user.sender_format == SenderFormatEnum.AT.value:
|
else:
|
||||||
name = self.name or ""
|
if user.sender_format == SenderFormatEnum.AT.value:
|
||||||
new_name = (
|
formatted_email = self.website_email.replace("@", " at ").strip()
|
||||||
name + (" - " if name else "") + self.website_email.replace("@", " at ")
|
|
||||||
).strip()
|
|
||||||
elif user.sender_format == SenderFormatEnum.A.value:
|
elif user.sender_format == SenderFormatEnum.A.value:
|
||||||
name = self.name or ""
|
formatted_email = self.website_email.replace("@", "(a)").strip()
|
||||||
new_name = (
|
|
||||||
name + (" - " if name else "") + self.website_email.replace("@", "(a)")
|
|
||||||
).strip()
|
|
||||||
elif user.sender_format == SenderFormatEnum.FULL.value:
|
elif user.sender_format == SenderFormatEnum.FULL.value:
|
||||||
name = self.name or ""
|
formatted_email = self.website_email.strip()
|
||||||
new_name = (name + (" - " if name else "") + self.website_email).strip()
|
|
||||||
|
# Prefix name to formatted email if available
|
||||||
|
new_name = (self.name + " - " + formatted_email) if self.name and self.name != self.website_email.strip() else formatted_email
|
||||||
|
|
||||||
new_addr = formataddr((new_name, self.reply_email)).strip()
|
new_addr = formataddr((new_name, self.reply_email)).strip()
|
||||||
return new_addr.strip()
|
return new_addr.strip()
|
||||||
|
|
|
@ -133,8 +133,19 @@ def test_new_addr(flask_client):
|
||||||
)
|
)
|
||||||
assert c1.new_addr() == '"abcd@example.com via SimpleLogin" <rep@SL>'
|
assert c1.new_addr() == '"abcd@example.com via SimpleLogin" <rep@SL>'
|
||||||
|
|
||||||
|
# set sender format = FULL
|
||||||
|
user.sender_format = SenderFormatEnum.FULL.value
|
||||||
|
db.session.commit()
|
||||||
|
assert c1.new_addr() == '"First Last - abcd@example.com" <rep@SL>'
|
||||||
|
|
||||||
|
# Make sure email isn't duplicated if sender name equals email
|
||||||
|
c1.name = "abcd@example.com"
|
||||||
|
db.session.commit()
|
||||||
|
assert c1.new_addr() == '"abcd@example.com" <rep@SL>'
|
||||||
|
|
||||||
# set sender_format = AT
|
# set sender_format = AT
|
||||||
user.sender_format = SenderFormatEnum.AT.value
|
user.sender_format = SenderFormatEnum.AT.value
|
||||||
|
c1.name = "First Last"
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
assert c1.new_addr() == '"First Last - abcd at example.com" <rep@SL>'
|
assert c1.new_addr() == '"First Last - abcd at example.com" <rep@SL>'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue