From c71b91a32f2b4b4d84e875c00d6ed48ef2527712 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Fri, 18 Aug 2017 00:25:17 +0200 Subject: [PATCH] Allow User objects in From mail field and set Reply-To if not set already --- app/mailers/mailer.rb | 7 ++++++- plugins/messages/app/mailers/messages_mailer.rb | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 8c31ecc0..c381163e 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -63,7 +63,7 @@ class Mailer < ActionMailer::Base @feedback = feedback mail to: FoodsoftConfig[:notification][:error_recipients], - :from => "#{show_user user} <#{user.email}>", + from: user, subject: I18n.t('mailer.feedback.subject', email: user.email) end @@ -78,6 +78,11 @@ class Mailer < ActionMailer::Base def mail(args) args[:subject] = "[#{FoodsoftConfig[:name]}] #{args[:subject]}" + if args[:from].is_a? User + args[:reply_to] = args[:from] unless args[:reply_to] + args[:from] = "#{show_user args[:from]} via #{I18n.t('layouts.foodsoft')} <#{FoodsoftConfig[:email_sender]}>" + 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 diff --git a/plugins/messages/app/mailers/messages_mailer.rb b/plugins/messages/app/mailers/messages_mailer.rb index 5ab4792c..d4b3a128 100644 --- a/plugins/messages/app/mailers/messages_mailer.rb +++ b/plugins/messages/app/mailers/messages_mailer.rb @@ -7,13 +7,11 @@ class MessagesMailer < Mailer if reply_email_domain hash = message.mail_hash_for_user recipient reply_to = "#{I18n.t('layouts.foodsoft')} <#{FoodsoftConfig.scope}.#{message.id}.#{recipient.id}.#{hash}@#{reply_email_domain}>" - else - reply_to = "#{show_user(message.sender)} <#{message.sender.email}>" end mail subject: message.subject, to: recipient, - from: "#{show_user(message.sender)} via #{I18n.t('layouts.foodsoft')} <#{FoodsoftConfig[:email_sender]}>", + from: message.sender, reply_to: reply_to end end