From 4083e7e62270186d61782eec7e5861cee89e2619 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sun, 20 Jun 2010 16:22:36 +0000 Subject: [PATCH] Truncate incoming email subject lines to 255 characters. #5698 Contributed by Jan git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3801 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 2 +- .../mail_handler/ticket_with_long_subject.eml | 57 +++++++++++++++++++ test/unit/mail_handler_test.rb | 6 ++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/mail_handler/ticket_with_long_subject.eml diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 2b57e1ab48..518f0433f1 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -134,7 +134,7 @@ class MailHandler < ActionMailer::Base if status && issue.new_statuses_allowed_to(user).include?(status) issue.status = status end - issue.subject = email.subject.chomp + issue.subject = email.subject.chomp[0,255] if issue.subject.blank? issue.subject = '(no subject)' end diff --git a/test/fixtures/mail_handler/ticket_with_long_subject.eml b/test/fixtures/mail_handler/ticket_with_long_subject.eml new file mode 100644 index 0000000000..ee0bfcffd2 --- /dev/null +++ b/test/fixtures/mail_handler/ticket_with_long_subject.eml @@ -0,0 +1,57 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +From: "John Smith" +To: +Subject: New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say... +Date: Sun, 22 Jun 2008 12:28:07 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + format=flowed; + charset="iso-8859-1"; + reply-type=original +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2900.2869 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 + +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet +turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus +blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti +sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In +in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras +sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum +id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus +eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique +sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse +platea dictumst. + +--- This line starts with a delimiter and should not be stripped + +This paragraph is before delimiters. + +BREAK + +This paragraph is between delimiters. + +--- + +This paragraph is after the delimiter so it shouldn't appear. + +Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque +sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem. +Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et, +dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed, +massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo +pulvinar dui, a gravida orci mi eget odio. Nunc a lacus. + +Project: onlinestore +Status: Resolved +due date: 2010-12-31 +Start Date:2010-01-01 +Assigned to: John Smith + diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 467084f1b3..e0ff8a2a7f 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -349,6 +349,12 @@ class MailHandlerTest < ActiveSupport::TestCase end end end + + def test_email_with_long_subject_line + issue = submit_email('ticket_with_long_subject.eml') + assert issue.is_a?(Issue) + assert_equal issue.subject, 'New ticket on a given project with a very long subject line which exceeds 255 chars and should not be ignored but chopped off. And if the subject line is still not long enough, we just add more text. And more text. Wow, this is really annoying. Especially, if you have nothing to say...'[0,255] + end private