Skip to content

Commit

Permalink
Merge pull request #963 from koriaf/dev-subject-length
Browse files Browse the repository at this point in the history
fix(emails): Avoid 'value too long for type character varying(200) ' …
  • Loading branch information
gwasser committed Aug 5, 2021
2 parents df05ce2 + 86c4ceb commit 9fd5d46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions helpdesk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,9 @@ def save(self, *args, **kwargs):

self.modified = timezone.now()

if len(self.title) > 200:
self.title = self.title[:197] + "..."

super(Ticket, self).save(*args, **kwargs)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion helpdesk/tests/test_files/blank-body-with-attachment.eml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
To: helpdesk@auto-mat.cz
From: Timothy Hobbs <timothy.hobbs@auto-mat.cz>
Subject: Attachment without body
Subject: Attachment without body - and a looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong subject
Openpgp: preference=signencrypt
Message-ID: <b05893cd-77b5-3450-4b84-9a1ad5119def@auto-mat.cz>
Date: Fri, 15 Feb 2019 13:58:05 +0100
Expand Down
8 changes: 7 additions & 1 deletion helpdesk/tests/test_get_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ def test_email_with_blank_body_and_attachment(self):
with open(os.path.join(THIS_DIR, "test_files/blank-body-with-attachment.eml")) as fd:
test_email = fd.read()
ticket = helpdesk.email.object_from_message(test_email, self.queue_public, self.logger)
self.assertEqual(ticket.title, "Attachment without body")

# title got truncated because of max_lengh of the model.title field
assert ticket.title == (
"Attachment without body - and a loooooooooooooooooooooooooooooooooo"
"ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
"ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..."
)
self.assertEqual(ticket.description, "")

def test_email_with_quoted_printable_body(self):
Expand Down

0 comments on commit 9fd5d46

Please sign in to comment.