Use Mail::Address to create email addresses with display names
This class escapes special characters in addresses correctly.
This commit is contained in:
parent
f509f85327
commit
bce9d9a8c2
1 changed files with 11 additions and 3 deletions
|
@ -98,16 +98,16 @@ class Mailer < ActionMailer::Base
|
|||
|
||||
if args[:from].is_a? User
|
||||
args[:reply_to] ||= args[:from]
|
||||
args[:from] = "#{I18n.t('mailer.from_via_foodsoft', name: show_user(args[:from]))} <#{FoodsoftConfig[:email_sender]}>"
|
||||
args[:from] = format_address(FoodsoftConfig[:email_sender], I18n.t('mailer.from_via_foodsoft', name: show_user(args[:from])))
|
||||
end
|
||||
|
||||
[:bcc, :cc, :reply_to, :sender, :to].each do |k|
|
||||
user = args[k]
|
||||
args[k] = "#{show_user user} <#{user.email}>" if user.is_a? User
|
||||
args[k] = format_address(user.email, show_user(user)) if user.is_a? User
|
||||
end
|
||||
|
||||
if contact_email = FoodsoftConfig[:contact][:email]
|
||||
args[:reply_to] ||= "#{FoodsoftConfig[:name]} <#{contact_email}>"
|
||||
args[:reply_to] ||= format_address(contact_email, FoodsoftConfig[:name])
|
||||
end
|
||||
|
||||
reply_email_domain = FoodsoftConfig[:reply_email_domain]
|
||||
|
@ -140,4 +140,12 @@ class Mailer < ActionMailer::Base
|
|||
attachments['order.csv'] = OrderCsv.new(order, options).to_csv
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format_address(email, name)
|
||||
address = Mail::Address.new email
|
||||
address.display_name = name
|
||||
address.format
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue