Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix redmine 3.1-stable workaround #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
name 'Redmine per Project Sender plugin'
author 'Christian A. Rodriguez'
description 'Redmine per Project Sender plugin for overriding notification settings per project'
version '0.2.3'
version '0.3.1'
requires_redmine :version_or_higher => '2.3.0'
end
37 changes: 23 additions & 14 deletions lib/mailer_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@ module InstanceMethods
# Overrides the mail method trying to
# get per project mail from configuration
def mail_with_project_sender(headers={}, &block)
headers.merge! 'X-Mailer' => 'Redmine',
headers.reverse_merge! 'X-Mailer' => 'Redmine',
'X-Redmine-Host' => Setting.host_name,
'X-Redmine-Site' => Setting.app_title,
'X-Auto-Response-Suppress' => 'OOF',
'X-Auto-Response-Suppress' => 'All',
'Auto-Submitted' => 'auto-generated',
'From' => mail_from_project_sender,
'List-Id' => "<#{mail_from_project_sender.to_s.gsub('@', '.')}>"

# Replaces users with their email addresses
[:to, :cc, :bcc].each do |key|
if headers[key].present?
headers[key] = self.class.email_addresses(headers[key])
end
end

# Removes the author from the recipients and cc
# if he doesn't want to receive notifications about what he does
# if the author does not want to receive notifications
# about what the author do
if @author && @author.logged? && @author.pref.no_self_notified
headers[:to].delete(@author.mail) if headers[:to].is_a?(Array)
headers[:cc].delete(@author.mail) if headers[:cc].is_a?(Array)
addresses = @author.mails
headers[:to] -= addresses if headers[:to].is_a?(Array)
headers[:cc] -= addresses if headers[:cc].is_a?(Array)
end

if @author && @author.logged?
Expand All @@ -46,17 +55,17 @@ def mail_with_project_sender(headers={}, &block)
headers[:references] = @references_objects.collect {|o| "<#{self.class.message_id_for(o)}>"}.join(' ')
end

m= super headers do |format|
format.text
format.html unless Setting.plain_text_mail?
m = if block_given?
super headers, &block
else
super headers do |format|
format.text
format.html unless Setting.plain_text_mail?
end
end

set_language_if_valid @initial_language


m
end

m
end
private
# try to return mail_from project configuration
def mail_from_project_sender
Expand Down