diff --git a/cron.py b/cron.py index 3f2f8ef5..7c15d308 100644 --- a/cron.py +++ b/cron.py @@ -915,7 +915,7 @@ def notify_hibp(): user.email, f"You were in a data breach", render( - "transactional/hibp-new-breaches.txt", + "transactional/hibp-new-breaches.txt.jinja2", user=user, breached_aliases=new_breaches, ), diff --git a/templates/emails/transactional/hibp-new-breaches.html b/templates/emails/transactional/hibp-new-breaches.html index 77f97544..b58cfe4b 100644 --- a/templates/emails/transactional/hibp-new-breaches.html +++ b/templates/emails/transactional/hibp-new-breaches.html @@ -1,30 +1,44 @@ {% extends "base.html" %} {% block content %} - {{ render_text("Hi") }} + {% call text() %} +

+ {{ breached_aliases|count }} of your aliases are found in data breaches. +

+ {% endcall %} - {%- for alias in breached_aliases %} - {%- if loop.index == 11 and loop.length > 10 %} - And {{ breached_aliases|length - 10 }} more aliases... - {%- elif loop.index > 11 %} - {%- else %} - {{ render_text("Your alias " + alias.email + " was found in one or more data breaches:") }} +
    + {%- for alias in breached_aliases[:10] %} +
  1. {% call text() %} + {{ alias.email }} was found in {{ alias.hibp_breaches_not_notified_user|count }} data breaches.
    - {%- for breach in alias.hibp_breaches_not_notified_user|sort(attribute='date', reverse=True) %} - {%- if loop.index == 4 and loop.length > 4 %} - {{ render_text("And " + ((alias.hibp_breaches_not_notified_user|length) - 3)|string + " more data breaches...") }} - {%- elif loop.index > 4 %} - {%- else %} - {{ render_text(breach.name + " (" + breach.date.format('YYYY-MM-DD') + ")") }} - {{ render_text(breach.description) }} + - {{ render_text("Breached data: " + breach.data_classes|join(', ', attribute='attribute')) }} - {%- endif %} - {%- endfor %} - {%- endif %} - {%- endfor %} + {% if breaches|length > 4 %} + And {{ breaches|length - 4 }} more data breaches... + {% endif %} - {{ render_text("For more information, check HaveIBeenPwned.com.") }} + {% endcall %}
  2. + {%- endfor %} + +
+ + {% if breached_aliases|length > 10 %} + {% call text() %} + And {{ breached_aliases|length - 10 }} more aliases... + {% endcall %} + {% endif %} + + {{ render_text("For more information, please check HaveIBeenPwned.com.") }} {{ render_text('Best,
SimpleLogin Team.') }} {% endblock %} diff --git a/templates/emails/transactional/hibp-new-breaches.txt b/templates/emails/transactional/hibp-new-breaches.txt deleted file mode 100644 index 03db98db..00000000 --- a/templates/emails/transactional/hibp-new-breaches.txt +++ /dev/null @@ -1,30 +0,0 @@ -Hi - -{%- for alias in breached_aliases %} -{%- if loop.index == 11 and loop.length > 10 %} -And {{ breached_aliases|length - 10 }} more aliases... -{%- elif loop.index > 11 %} -{%- else %} - -Your alias {{ alias.email }} was found in one or more data breaches: - -{%- for breach in alias.hibp_breaches_not_notified_user|sort(attribute='date', reverse=True) %} -{%- if loop.index == 4 and loop.length > 4 %} - -And {{ (alias.hibp_breaches_not_notified_user|length) - 3 }} more data breaches... -{%- elif loop.index > 4 %} -{%- else %} - -{{ breach.name }} ({{ breach.date.format('YYYY-MM-DD') }}) -{{ breach.description|striptags }} - -Breached data: {{ breach.data_classes|join(', ', attribute='attribute') }} -{%- endif %} -{%- endfor %} -{%- endif %} -{%- endfor %} - -For more information, check https://haveibeenpwned.com/. - -Best, -SimpleLogin Team. diff --git a/templates/emails/transactional/hibp-new-breaches.txt.jinja2 b/templates/emails/transactional/hibp-new-breaches.txt.jinja2 new file mode 100644 index 00000000..9b27688b --- /dev/null +++ b/templates/emails/transactional/hibp-new-breaches.txt.jinja2 @@ -0,0 +1,24 @@ +{{ breached_aliases|count }} of your aliases are found in data breaches. + +{% for alias in breached_aliases[:10] %} + {{ loop.index }} ) {{ alias.email }} was found in {{ alias.hibp_breaches_not_notified_user|count }} data breaches. + + {%- set breaches = alias.hibp_breaches_not_notified_user|sort(attribute='date', reverse=True) %} + {% for breach in breaches[:4] %} + - {{ breach.name }} ({{ breach.date.format('YYYY-MM-DD') }}). Breached data includes {{ breach.data_classes|join(', ', attribute='attribute') }}. + {%- endfor %} + + + {%- if breaches|length > 4 %} + And {{ breaches|length - 4 }} more data breaches... + {% endif %} +{% endfor %} + +{%- if breached_aliases|length > 10 %} + And {{ breached_aliases|length - 10 }} more aliases... +{%- endif %} + +For more information, please check https://haveibeenpwned.com/. + +Best, +SimpleLogin Team.