generate recipient header with Mail::Address to properly handle non-ASCII characters

This commit is contained in:
MrZYX 2012-01-21 18:56:32 +01:00
parent b831a9b4db
commit 1ab9520b36
2 changed files with 9 additions and 3 deletions

View file

@ -20,12 +20,18 @@ module NotificationMailers
default_headers.merge(@headers)
end
def name_and_address(name, email)
address = Mail::Address.new email
address.display_name = name
address.format
end
private
def default_headers
headers = {
:from => AppConfig[:smtp_sender_address],
:host => "#{AppConfig[:pod_uri]}",
:to => "\"#{@recipient.name}\" <#{@recipient.email}>"
:to => name_and_address(@recipient.name, @recipient.email)
}
headers[:from] = "\"#{@sender.name} (Diaspora*)\" <#{AppConfig[:smtp_sender_address]}>" if @sender.present?
@ -48,4 +54,4 @@ module NotificationMailers
Rails.logger.info(log_string)
end
end
end
end

View file

@ -1,7 +1,7 @@
module NotificationMailers
class ConfirmEmail < NotificationMailers::Base
def set_headers
@headers[:to] = "#{@recipient.profile.first_name} <#{@recipient.unconfirmed_email}>"
@headers[:to] = name_and_address(@recipient.profile.first_name, @recipient.unconfirmed_email)
@headers[:subject] = I18n.t('notifier.confirm_email.subject', :unconfirmed_email => @recipient.unconfirmed_email)
end
end