diff --git a/Changelog.md b/Changelog.md index 1860999607cd3ae3a071d3cc16eeb7a13bb0c6b4..0eabfc2a9b195095f123d6f3ac655111cb85b37a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,6 +17,7 @@ Ruby 2.1 is no longer officially supported. * Always link comment count text on mobile [#7483](https://github.com/diaspora/diaspora/pull/7483) * Switch to new federation protocol [#7436](https://github.com/diaspora/diaspora/pull/7436) * Send public profiles publicly [#7501](https://github.com/diaspora/diaspora/pull/7501) +* Change sender for mails [#7495](https://github.com/diaspora/diaspora/pull/7495) ## Bug fixes diff --git a/app/mailers/notification_mailers/base.rb b/app/mailers/notification_mailers/base.rb index bf3569fad24e35d44377373e16815de9d561a403..a8496df47700a1a4bbd8ef8beaf938b17e8ee291 100644 --- a/app/mailers/notification_mailers/base.rb +++ b/app/mailers/notification_mailers/base.rb @@ -34,12 +34,13 @@ module NotificationMailers def default_headers headers = { - from: AppConfig.mail.sender_address.get, + from: "\"#{AppConfig.settings.pod_name}\" <#{AppConfig.mail.sender_address}>", host: "#{AppConfig.pod_uri.host}", to: name_and_address(@recipient.name, @recipient.email) } - - headers[:from] = "\"#{@sender.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>" if @sender.present? + return headers if @sender.blank? + sender_in_header = @sender.profile.full_name.empty? ? @sender.username : @sender.name + headers[:from] = "\"#{AppConfig.settings.pod_name} (#{sender_in_header})\" <#{AppConfig.mail.sender_address}>" headers end diff --git a/app/mailers/report_mailer.rb b/app/mailers/report_mailer.rb index dbb3c2f125bcf96ef511cd84a7fdbf269049af5a..498413367aa4ca4b74071027cd2a11edcf8367ff 100644 --- a/app/mailers/report_mailer.rb +++ b/app/mailers/report_mailer.rb @@ -1,5 +1,5 @@ class ReportMailer < ActionMailer::Base - default from: AppConfig.mail.sender_address + default from: "\"#{AppConfig.settings.pod_name}\" <#{AppConfig.mail.sender_address}>" def self.new_report(report_id) report = Report.find_by_id(report_id) diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 3adaca1326a519940d3913d921bc6438684ec788..6594f840889366ca9ae8578aacbd94073b153eb0 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -1,5 +1,7 @@ describe Notifier, type: :mailer do let(:person) { FactoryGirl.create(:person) } + let(:pod_name) { AppConfig.settings.pod_name } + before do Notifier.deliveries = [] @@ -246,7 +248,7 @@ describe Notifier, type: :mailer do end it "FROM: contains the sender's name" do - expect(@mail["From"].to_s).to eq("\"#{@cnv.author.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") + expect(@mail["From"].to_s).to eq("\"#{pod_name} (#{@cnv.author.name})\" <#{AppConfig.mail.sender_address}>") end it "should use a generic subject" do @@ -290,7 +292,7 @@ describe Notifier, type: :mailer do end it "FROM: contains the sender's name" do - expect(comment_mail["From"].to_s).to eq("\"#{eve.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") + expect(comment_mail["From"].to_s).to eq("\"#{pod_name} (#{eve.name})\" <#{AppConfig.mail.sender_address}>") end it "SUBJECT: has a snippet of the post contents, without markdown and without newlines" do @@ -331,7 +333,7 @@ describe Notifier, type: :mailer do end it "FROM: has the name of person commenting as the sender" do - expect(comment_mail["From"].to_s).to eq("\"#{eve.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") + expect(comment_mail["From"].to_s).to eq("\"#{pod_name} (#{eve.name})\" <#{AppConfig.mail.sender_address}>") end it "SUBJECT: has a snippet of the post contents, without markdown and without newlines" do @@ -386,7 +388,7 @@ describe Notifier, type: :mailer do end it "FROM: contains the sender's name" do - expect(mail["From"].to_s).to eq("\"#{bob.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") + expect(mail["From"].to_s).to eq("\"#{pod_name} (#{bob.name})\" <#{AppConfig.mail.sender_address}>") end it "SUBJECT: does not show the limited post" do @@ -411,7 +413,7 @@ describe Notifier, type: :mailer do end it "FROM: contains the sender's name" do - expect(mail["From"].to_s).to eq("\"#{bob.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") + expect(mail["From"].to_s).to eq("\"#{pod_name} (#{bob.name})\" <#{AppConfig.mail.sender_address}>") end it "SUBJECT: does not show the limited post" do @@ -442,7 +444,7 @@ describe Notifier, type: :mailer do end it "FROM: contains the sender's name" do - expect(mail["From"].to_s).to eq("\"#{bob.name} (diaspora*)\" <#{AppConfig.mail.sender_address}>") + expect(mail["From"].to_s).to eq("\"#{pod_name} (#{bob.name})\" <#{AppConfig.mail.sender_address}>") end it "SUBJECT: does not show the limited post" do @@ -478,7 +480,11 @@ describe Notifier, type: :mailer do expect(@confirm_email.to).to eq([bob.unconfirmed_email]) end - it "has the unconfirmed emil in the subject" do + it "FROM: header should be the pod name with default sender address" do + expect(@confirm_email["From"].to_s).to eq("#{pod_name} <#{AppConfig.mail.sender_address}>") + end + + it "has the unconfirmed email in the subject" do expect(@confirm_email.subject).to include(bob.unconfirmed_email) end @@ -502,6 +508,10 @@ describe Notifier, type: :mailer do expect(email.to).to eq([alice.email]) end + it "FROM: header should be the pod name + default sender address" do + expect(email["From"].to_s).to eq("#{pod_name} <#{AppConfig.mail.sender_address}>") + end + it "has the correct subject" do expect(email.subject).to eq(I18n.translate("notifier.csrf_token_fail.subject", name: alice.name)) end @@ -535,5 +545,11 @@ describe Notifier, type: :mailer do Notifier.send_notification("started_sharing", bob.id, person.id) }.to_not raise_error end + + it "FROM: header should be 'pod_name (username)' when there is no first and last name" do + bob.person.profile.update_attributes(first_name: "", last_name: "") + mail = Notifier.send_notification("started_sharing", alice.id, bob.person.id) + expect(mail["From"].to_s).to eq("\"#{pod_name} (#{bob.person.username})\" <#{AppConfig.mail.sender_address}>") + end end end diff --git a/spec/mailers/report_spec.rb b/spec/mailers/report_spec.rb index ce168bb3b4ac21fd4dc8d85321a998d290f69093..96699f5625479fb53f339016050016e49d132913 100644 --- a/spec/mailers/report_spec.rb +++ b/spec/mailers/report_spec.rb @@ -41,6 +41,12 @@ describe Report, type: :mailer do expect(ActionMailer::Base.deliveries[1].to[0]).to include(@user2.email) end + it "FROM: header should be the pod name + default sender address" do + ReportMailer.new_report(@post_report.id).each(&:deliver_now) + pod_name = AppConfig.settings.pod_name + expect(ReportMailer.default[:from].to_s).to eq("\"#{pod_name}\" <#{AppConfig.mail.sender_address}>") + end + it "should send mail in recipent's prefered language" do ReportMailer.new_report(@post_report.id).each(&:deliver_now) expect(ActionMailer::Base.deliveries[0].subject).to match("Ein neuer post wurde als anstößig markiert")