Commit 6a92da487c0ad774b952927991551638c61eb073
1 parent
148f7349
Exists in
master
and in
1 other branch
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.
Showing
2 changed files
with
8 additions
and
1 deletions
Show diff stats
app/mailers/mailer.rb
... | ... | @@ -10,7 +10,7 @@ class Mailer < ActionMailer::Base |
10 | 10 | @app = notice.app |
11 | 11 | |
12 | 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 | 14 | end |
15 | 15 | |
16 | 16 | def deploy_notification(deploy) | ... | ... |
spec/mailers/mailer_spec.rb
... | ... | @@ -19,6 +19,13 @@ describe Mailer do |
19 | 19 | it "should have inline css" do |
20 | 20 | email.should have_body_text('<p class="backtrace" style="') |
21 | 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 | 29 | end |
23 | 30 | end |
24 | 31 | ... | ... |