From 04bf994c9ae99092e990552c7355f81294aeae63 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Fri, 18 Aug 2017 00:11:36 +0200 Subject: [PATCH] Override the mail method of Mailer to automatically add the foodcoop name --- app/mailers/mailer.rb | 19 ++++++++++++------- .../messages/app/mailers/messages_mailer.rb | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index 3c33c19b..d0fe4ead 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -19,7 +19,7 @@ class Mailer < ActionMailer::Base @link = new_password_url(id: @user.id, token: @user.reset_password_token) mail :to => @user.email, - :subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.reset_password.subject', :username => show_user(@user)) + subject: I18n.t('mailer.reset_password.subject', username: show_user(user)) end # Sends an invite email. @@ -28,7 +28,7 @@ class Mailer < ActionMailer::Base @link = accept_invitation_url(token: @invite.token) mail :to => @invite.email, - :subject => I18n.t('mailer.invite.subject') + subject: I18n.t('mailer.invite.subject') end # Notify user of upcoming task. @@ -37,7 +37,7 @@ class Mailer < ActionMailer::Base @task = task mail :to => user.email, - :subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.upcoming_tasks.subject') + subject: I18n.t('mailer.upcoming_tasks.subject') end # Sends order result for specific Ordergroup @@ -46,7 +46,7 @@ class Mailer < ActionMailer::Base @group_order = group_order mail :to => user.email, - :subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.order_result.subject', :name => group_order.order.name) + subject: I18n.t('mailer.order_result.subject', name: group_order.order.name) end # Notify user if account balance is less than zero @@ -55,7 +55,7 @@ class Mailer < ActionMailer::Base @transaction = transaction mail :to => user.email, - :subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.negative_balance.subject') + subject: I18n.t('mailer.negative_balance.subject') end def feedback(user, feedback) @@ -64,7 +64,7 @@ class Mailer < ActionMailer::Base mail :to => FoodsoftConfig[:notification]["error_recipients"], :from => "#{show_user user} <#{user.email}>", - :subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.feedback.subject', :email => user.email) + subject: I18n.t('mailer.feedback.subject', email: user.email) end def not_enough_users_assigned(task, user) @@ -72,7 +72,12 @@ class Mailer < ActionMailer::Base @user = user mail :to => user.email, - :subject => "[#{FoodsoftConfig[:name]}] " + I18n.t('mailer.not_enough_users_assigned.subject', :task => task.name) + subject: I18n.t('mailer.not_enough_users_assigned.subject', task: task.name) + end + + def mail(args) + args[:subject] = "[#{FoodsoftConfig[:name]}] #{args[:subject]}" + super end end diff --git a/plugins/messages/app/mailers/messages_mailer.rb b/plugins/messages/app/mailers/messages_mailer.rb index 77a7a4f6..347e289c 100644 --- a/plugins/messages/app/mailers/messages_mailer.rb +++ b/plugins/messages/app/mailers/messages_mailer.rb @@ -11,7 +11,7 @@ class MessagesMailer < Mailer reply_to = "#{show_user(message.sender)} <#{message.sender.email}>" end - mail subject: "[#{FoodsoftConfig[:name]}] " + message.subject, + mail subject: message.subject, to: recipient.email, from: "#{show_user(message.sender)} via #{I18n.t('layouts.foodsoft')} <#{FoodsoftConfig[:email_sender]}>", reply_to: reply_to