Adds a method for extracting MailHandler options from ENV.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11785 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
33afeea87a
commit
ed18b3359b
|
@ -46,6 +46,19 @@ class MailHandler < ActionMailer::Base
|
||||||
super(email)
|
super(email)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Extracts MailHandler options from environment variables
|
||||||
|
# Use when receiving emails with rake tasks
|
||||||
|
def self.extract_options_from_env(env)
|
||||||
|
options = {:issue => {}}
|
||||||
|
%w(project status tracker category priority).each do |option|
|
||||||
|
options[:issue][option.to_sym] = env[option] if env[option]
|
||||||
|
end
|
||||||
|
%w(allow_override unknown_user no_permission_check no_account_notice default_group).each do |option|
|
||||||
|
options[option.to_sym] = env[option] if env[option]
|
||||||
|
end
|
||||||
|
options
|
||||||
|
end
|
||||||
|
|
||||||
def logger
|
def logger
|
||||||
Rails.logger
|
Rails.logger
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,15 +55,7 @@ Examples:
|
||||||
END_DESC
|
END_DESC
|
||||||
|
|
||||||
task :read => :environment do
|
task :read => :environment do
|
||||||
options = { :issue => {} }
|
MailHandler.receive(STDIN.read, MailHandler.extract_options_from_env(ENV))
|
||||||
%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
|
|
||||||
options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
|
|
||||||
options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
|
|
||||||
options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
|
|
||||||
options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice']
|
|
||||||
options[:default_group] = ENV['default_group'] if ENV['default_group']
|
|
||||||
|
|
||||||
MailHandler.receive(STDIN.read, options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc <<-END_DESC
|
desc <<-END_DESC
|
||||||
|
@ -130,15 +122,7 @@ END_DESC
|
||||||
:move_on_success => ENV['move_on_success'],
|
:move_on_success => ENV['move_on_success'],
|
||||||
:move_on_failure => ENV['move_on_failure']}
|
:move_on_failure => ENV['move_on_failure']}
|
||||||
|
|
||||||
options = { :issue => {} }
|
Redmine::IMAP.check(imap_options, MailHandler.extract_options_from_env(ENV))
|
||||||
%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
|
|
||||||
options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
|
|
||||||
options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
|
|
||||||
options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
|
|
||||||
options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice']
|
|
||||||
options[:default_group] = ENV['default_group'] if ENV['default_group']
|
|
||||||
|
|
||||||
Redmine::IMAP.check(imap_options, options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc <<-END_DESC
|
desc <<-END_DESC
|
||||||
|
@ -165,15 +149,7 @@ END_DESC
|
||||||
:password => ENV['password'],
|
:password => ENV['password'],
|
||||||
:delete_unprocessed => ENV['delete_unprocessed']}
|
:delete_unprocessed => ENV['delete_unprocessed']}
|
||||||
|
|
||||||
options = { :issue => {} }
|
Redmine::POP3.check(pop_options, MailHandler.extract_options_from_env(ENV))
|
||||||
%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
|
|
||||||
options[:allow_override] = ENV['allow_override'] if ENV['allow_override']
|
|
||||||
options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user']
|
|
||||||
options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check']
|
|
||||||
options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice']
|
|
||||||
options[:default_group] = ENV['default_group'] if ENV['default_group']
|
|
||||||
|
|
||||||
Redmine::POP3.check(pop_options, options)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Send a test email to the user with the provided login name"
|
desc "Send a test email to the user with the provided login name"
|
||||||
|
|
|
@ -798,6 +798,19 @@ class MailHandlerTest < ActiveSupport::TestCase
|
||||||
assert_equal str2, user.lastname
|
assert_equal str2, user.lastname
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_extract_options_from_env_should_return_options
|
||||||
|
options = MailHandler.extract_options_from_env({
|
||||||
|
'tracker' => 'defect',
|
||||||
|
'project' => 'foo',
|
||||||
|
'unknown_user' => 'create'
|
||||||
|
})
|
||||||
|
|
||||||
|
assert_equal({
|
||||||
|
:issue => {:tracker => 'defect', :project => 'foo'},
|
||||||
|
:unknown_user => 'create'
|
||||||
|
}, options)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def submit_email(filename, options={})
|
def submit_email(filename, options={})
|
||||||
|
|
Loading…
Reference in New Issue