RFC2822 specifies that you use parentheses to denote a mailbox list. Use the addr-name spec to specify a display name and the from address.
Check against the raw headers of the mail as @mail.from excludes the display name Extract shared logic between notifier methods
This commit is contained in:
parent
6b5928ca09
commit
814eb7b426
9 changed files with 31 additions and 60 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue