diff --git a/app/mailers/notification_mailers/also_commented.rb b/app/mailers/notification_mailers/also_commented.rb index 8afa2498d..a92f3a2af 100644 --- a/app/mailers/notification_mailers/also_commented.rb +++ b/app/mailers/notification_mailers/also_commented.rb @@ -5,10 +5,10 @@ module NotificationMailers attr_accessor :comment def set_headers(comment_id) - @comment = Comment.find_by_id(comment_id) + @comment = Comment.find_by_id(comment_id) if mail? - @headers[:from] = "#{@comment.author.name} (Diaspora*) <#{AppConfig[:smtp_sender_address]}>" + @headers[:from] = "[#{@comment.author.name} (Diaspora*)] <#{AppConfig[:smtp_sender_address]}>" @headers[:subject] = truncate(@comment.parent.comment_email_subject, :length => TRUNCATION_LEN) @headers[:subject] = "Re: #{@headers[:subject]}" end diff --git a/app/mailers/notification_mailers/base.rb b/app/mailers/notification_mailers/base.rb index 134f90076..cc17db364 100644 --- a/app/mailers/notification_mailers/base.rb +++ b/app/mailers/notification_mailers/base.rb @@ -2,17 +2,16 @@ module NotificationMailers TRUNCATION_LEN = 70 class Base - attr_accessor :recipient, :recipient_name, :sender + attr_accessor :recipient, :sender def initialize(recipient_id, sender_id=nil, *args) @headers = {} @recipient = User.find_by_id(recipient_id) - @recipient_name = @recipient.profile.first_name @sender = Person.find_by_id(sender_id) if sender_id.present? log_mail(recipient_id, sender_id, self.class.to_s.underscore) - with_locale do + with_recipient_locale do set_headers(*args) end end @@ -22,19 +21,19 @@ module NotificationMailers end private - def default_headers headers = { + :from => AppConfig[:smtp_sender_address], :host => "#{AppConfig[:pod_uri]}", :to => "\"#{@recipient.name}\" <#{@recipient.email}>" } - headers[:from] = "\"#{@sender.name} (Diaspora)\" <#{AppConfig[:smtp_sender_address]}>" if @sender.present? + headers[:from] = "\"#{@sender.name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>" if @sender.present? headers end - def with_locale(&block) + def with_recipient_locale(&block) I18n.with_locale(@recipient.language, &block) end diff --git a/app/mailers/notification_mailers/comment_on_post.rb b/app/mailers/notification_mailers/comment_on_post.rb index 89be9e980..ffb29fbb5 100644 --- a/app/mailers/notification_mailers/comment_on_post.rb +++ b/app/mailers/notification_mailers/comment_on_post.rb @@ -7,7 +7,7 @@ module NotificationMailers def set_headers(comment_id) @comment = Comment.find(comment_id) - @headers[:from] = "#{@comment.author.name} (Diaspora*) <#{AppConfig[:smtp_sender_address]}>" + @headers[:from] = "[#{@comment.author.name} (Diaspora*)] <#{AppConfig[:smtp_sender_address]}>" @headers[:subject] = truncate(@comment.parent.comment_email_subject, :length => TRUNCATION_LEN) @headers[:subject] = "Re: #{@headers[:subject]}" end diff --git a/app/mailers/notification_mailers/confirm_email.rb b/app/mailers/notification_mailers/confirm_email.rb index fdd71ed79..cd94cc76f 100644 --- a/app/mailers/notification_mailers/confirm_email.rb +++ b/app/mailers/notification_mailers/confirm_email.rb @@ -1,7 +1,7 @@ module NotificationMailers class ConfirmEmail < NotificationMailers::Base def set_headers - @headers[:to] = "#{recipient_name} <#{@recipient.unconfirmed_email}>" + @headers[:to] = "#{@recipient.profile.first_name} <#{@recipient.unconfirmed_email}>" @headers[:subject] = I18n.t('notifier.confirm_email.subject', :unconfirmed_email => @recipient.unconfirmed_email) end end diff --git a/app/mailers/notification_mailers/private_message.rb b/app/mailers/notification_mailers/private_message.rb index 72fb46e35..2cbc655c3 100644 --- a/app/mailers/notification_mailers/private_message.rb +++ b/app/mailers/notification_mailers/private_message.rb @@ -7,7 +7,7 @@ module NotificationMailers @conversation = @message.conversation @participants = @conversation.participants - @headers[:from] = "#{@message.author.name} (Diaspora*) <#{AppConfig[:smtp_sender_address]}>" + @headers[:from] = "[#{@message.author.name} (Diaspora*)] <#{AppConfig[:smtp_sender_address]}>" @headers[:subject] = @conversation.subject.strip @headers[:subject] = "Re: #{@headers[:subject]}" if @conversation.messages.size > 1 end diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 19f718f11..bee70b83f 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -2,11 +2,7 @@ class Notifier < ActionMailer::Base helper :application helper :markdownify helper :notifier - - default :from => AppConfig[:smtp_sender_address] - - include NotifierHelper - + def self.admin(string, recipients, opts = {}) mails = [] recipients.each do |rec| @@ -24,71 +20,47 @@ class Notifier < ActionMailer::Base end def started_sharing(recipient_id, sender_id) - @notification = NotificationMailers::StartedSharing.new(recipient_id, sender_id) - - with_recipient_locale do - mail(@notification.headers) - end + send_notification(:started_sharing, recipient_id, sender_id) end def liked(recipient_id, sender_id, like_id) - @notification = NotificationMailers::Liked.new(recipient_id, sender_id, like_id) - - with_recipient_locale do - mail(@notification.headers) - end + send_notification(:liked, recipient_id, sender_id, like_id) end def reshared(recipient_id, sender_id, reshare_id) - @notification = NotificationMailers::Reshared.new(recipient_id, sender_id, reshare_id) - - with_recipient_locale do - mail(@notification.headers) - end + send_notification(:reshared, recipient_id, sender_id, reshare_id) end def mentioned(recipient_id, sender_id, target_id) - @notification = NotificationMailers::Mentioned.new(recipient_id, sender_id, target_id) - - with_recipient_locale do - mail(@notification.headers) - end + send_notification(:mentioned, recipient_id, sender_id, target_id) end def comment_on_post(recipient_id, sender_id, comment_id) - @notification = NotificationMailers::CommentOnPost.new(recipient_id, sender_id, comment_id) - - with_recipient_locale do - mail(@notification.headers) - end + send_notification(:comment_on_post, recipient_id, sender_id, comment_id) end def also_commented(recipient_id, sender_id, comment_id) - @notification = NotificationMailers::AlsoCommented.new(recipient_id, sender_id, comment_id) - - with_recipient_locale do - mail(@notification.headers) if @notification.mail? - end + send_notification(:also_commented, recipient_id, sender_id, comment_id) end def private_message(recipient_id, sender_id, message_id) - @notification = NotificationMailers::PrivateMessage.new(recipient_id, sender_id, message_id) - - with_recipient_locale do - mail(@notification.headers) - end + send_notification(:private_message, recipient_id, sender_id, message_id) end def confirm_email(recipient_id) - @notification = NotificationMailers::ConfirmEmail.new(recipient_id) + send_notification(:confirm_email, recipient_id) + end + + private + def send_notification(type, *args) + @notification = NotificationMailers.const_get(type.to_s.camelize).new(*args) with_recipient_locale do mail(@notification.headers) end end - private def with_recipient_locale(&block) I18n.with_locale(@notification.recipient.language, &block) end -end +end \ No newline at end of file diff --git a/app/views/notifier/confirm_email.html.haml b/app/views/notifier/confirm_email.html.haml index e4a78f321..bc0cfaf19 100644 --- a/app/views/notifier/confirm_email.html.haml +++ b/app/views/notifier/confirm_email.html.haml @@ -1,5 +1,5 @@ %p - = t('notifier.hello', :name => @notification.recipient_name) + = t('notifier.hello', :name => @notification.recipient.profile.first_name) %p != t('notifier.confirm_email.click_link', :unconfirmed_email => @notification.recipient.unconfirmed_email) %br diff --git a/app/views/notifier/confirm_email.text.haml b/app/views/notifier/confirm_email.text.haml index 3da0a8975..c4c5c1385 100644 --- a/app/views/notifier/confirm_email.text.haml +++ b/app/views/notifier/confirm_email.text.haml @@ -1,4 +1,4 @@ -!= t('notifier.hello', :name => @notification.recipient_name) +!= t('notifier.hello', :name => @notification.recipient.profile.first_name) != t('notifier.confirm_email.click_link', :unconfirmed_email => @notification.recipient.unconfirmed_email) != confirm_email_url(:token => @notification.recipient.confirm_email_token) diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 5af7b65d1..5ab77d1bd 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -48,7 +48,7 @@ describe Notifier do end describe ".started_sharing" do - let!(:request_mail) {Notifier.started_sharing(bob.id, person.id)} + let!(:request_mail) { Notifier.started_sharing(bob.id, person.id) } it 'goes to the right person' do request_mail.to.should == [bob.email] @@ -172,7 +172,7 @@ describe Notifier do end it "FROM: contains the sender's name" do - @mail.from.should == "[#{@cnv.author.name} (Diaspora)] <#{AppConfig[:smtp_sender_address]}>" + @mail["From"].to_s.should == "[#{@cnv.author.name} (Diaspora*)] <#{AppConfig[:smtp_sender_address]}>" end it 'SUBJECT: has a snippet of the post contents' do @@ -207,7 +207,7 @@ describe Notifier do end it "FROM: contains the sender's name" do - comment_mail.from.should == "[#{eve.name} (Diaspora)] <#{AppConfig[:smtp_sender_address]}>" + comment_mail["From"].to_s.should == "[#{eve.name} (Diaspora*)] <#{AppConfig[:smtp_sender_address]}>" end it 'SUBJECT: has a snippet of the post contents' do @@ -248,7 +248,7 @@ describe Notifier do end it 'FROM: has the name of person commenting as the sender' do - comment_mail.from.should == "[#{eve.name} (Diaspora)] <#{AppConfig[:smtp_sender_address]}>" + comment_mail["From"].to_s.should == "[#{eve.name} (Diaspora*)] <#{AppConfig[:smtp_sender_address]}>" end it 'SUBJECT: has a snippet of the post contents' do