Commit 6a92da487c0ad774b952927991551638c61eb073

Authored by mh
1 parent 148f7349
Exists in master and in 1 other branch production

fix #352 - truncate long messages so subject is truncated

The message of the notice can be very long and mailservers will reject
emails containing such long subjects.
By truncating the message after 50 characters in the subject we avoid
these kind of problems.
app/mailers/mailer.rb
@@ -10,7 +10,7 @@ class Mailer < ActionMailer::Base @@ -10,7 +10,7 @@ class Mailer < ActionMailer::Base
10 @app = notice.app 10 @app = notice.app
11 11
12 mail :to => @app.notification_recipients, 12 mail :to => @app.notification_recipients,
13 - :subject => "[#{@app.name}][#{@notice.environment_name}] #{@notice.message}" 13 + :subject => "[#{@app.name}][#{@notice.environment_name}] #{@notice.message.truncate(50)}"
14 end 14 end
15 15
16 def deploy_notification(deploy) 16 def deploy_notification(deploy)
spec/mailers/mailer_spec.rb
@@ -19,6 +19,13 @@ describe Mailer do @@ -19,6 +19,13 @@ describe Mailer do
19 it "should have inline css" do 19 it "should have inline css" do
20 email.should have_body_text('<p class="backtrace" style="') 20 email.should have_body_text('<p class="backtrace" style="')
21 end 21 end
  22 +
  23 + context 'with a very long message' do
  24 + let(:notice) { Fabricate(:notice, :message => 6.times.collect{|a| "0123456789" }.join('')) }
  25 + it "should truncate the long message" do
  26 + email.subject.should =~ / \d{47}\.{3}$/
  27 + end
  28 + end
22 end 29 end
23 end 30 end
24 31