Skip to content

Commit

Permalink
In email form, use HTML line breaks when the HTML body is copied from…
Browse files Browse the repository at this point in the history
… the plain text body.
  • Loading branch information
genglert committed Jan 2, 2025
1 parent 53822d8 commit 7aaab88
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
== Version 2.5.17 Work in progress (not released -- this is a draft) ==

Users side :
------------
# Apps :
* Emails :
- The email form uses HTML line breaks when the HTML body is copied
from the plain text body.

Developers side :
-----------------

Expand Down
7 changes: 4 additions & 3 deletions creme/emails/forms/mail.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
# Creme is a free/open-source Customer Relationship Management software
# Copyright (C) 2009-2022 Hybird
# Copyright (C) 2009-2025 Hybird
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand All @@ -24,7 +24,7 @@
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.db.transaction import atomic
from django.utils.html import escape
from django.utils.html import linebreaks # escape
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
from django.utils.translation import pgettext_lazy
Expand Down Expand Up @@ -196,7 +196,8 @@ def save(self):
body = get_data('body') or strip_html(get_data('body_html')).strip()
body_html = (
get_data('body_html')
or f'<html><body><code>{escape(body)}</code></body></html>'
# or f'<html><body><code>{escape(body)}</code></body></html>'
or f'<html><body><code>{linebreaks(body, autoescape=True)}</code></body></html>'
)
signature = get_data('signature')
attachments = get_data('attachments')
Expand Down
4 changes: 2 additions & 2 deletions creme/emails/tests/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_createview_empty_body01(self):
self.assertFalse(html_f.required)

sender = user.linked_contact.email
body = 'Fresh & tasty !'
body = 'Fresh & tasty!\nTry it now!'
response2 = self.client.post(
url,
data={
Expand All @@ -363,7 +363,7 @@ def test_createview_empty_body01(self):
email = self.get_object_or_fail(EntityEmail, sender=sender, recipient=recipient)
self.assertEqual(body, email.body)
self.assertEqual(
'<html><body><code>Fresh &amp; tasty !</code></body></html>',
'<html><body><code><p>Fresh &amp; tasty!<br>Try it now!</p></code></body></html>',
email.body_html,
)

Expand Down

0 comments on commit 7aaab88

Please sign in to comment.