@@ -46,6 +46,19 class MailHandler < ActionMailer::Base | |||||
46 | super(email) |
|
46 | super(email) | |
47 | end |
|
47 | end | |
48 |
|
48 | |||
|
49 | # Extracts MailHandler options from environment variables | |||
|
50 | # Use when receiving emails with rake tasks | |||
|
51 | def self.extract_options_from_env(env) | |||
|
52 | options = {:issue => {}} | |||
|
53 | %w(project status tracker category priority).each do |option| | |||
|
54 | options[:issue][option.to_sym] = env[option] if env[option] | |||
|
55 | end | |||
|
56 | %w(allow_override unknown_user no_permission_check no_account_notice default_group).each do |option| | |||
|
57 | options[option.to_sym] = env[option] if env[option] | |||
|
58 | end | |||
|
59 | options | |||
|
60 | end | |||
|
61 | ||||
49 | def logger |
|
62 | def logger | |
50 | Rails.logger |
|
63 | Rails.logger | |
51 | end |
|
64 | end |
@@ -55,15 +55,7 Examples: | |||||
55 | END_DESC |
|
55 | END_DESC | |
56 |
|
56 | |||
57 | task :read => :environment do |
|
57 | task :read => :environment do | |
58 | options = { :issue => {} } |
|
58 | MailHandler.receive(STDIN.read, MailHandler.extract_options_from_env(ENV)) | |
59 | %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } |
|
|||
60 | options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] |
|
|||
61 | options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] |
|
|||
62 | options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] |
|
|||
63 | options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice'] |
|
|||
64 | options[:default_group] = ENV['default_group'] if ENV['default_group'] |
|
|||
65 |
|
||||
66 | MailHandler.receive(STDIN.read, options) |
|
|||
67 | end |
|
59 | end | |
68 |
|
60 | |||
69 | desc <<-END_DESC |
|
61 | desc <<-END_DESC | |
@@ -130,15 +122,7 END_DESC | |||||
130 | :move_on_success => ENV['move_on_success'], |
|
122 | :move_on_success => ENV['move_on_success'], | |
131 | :move_on_failure => ENV['move_on_failure']} |
|
123 | :move_on_failure => ENV['move_on_failure']} | |
132 |
|
124 | |||
133 | options = { :issue => {} } |
|
125 | Redmine::IMAP.check(imap_options, MailHandler.extract_options_from_env(ENV)) | |
134 | %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } |
|
|||
135 | options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] |
|
|||
136 | options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] |
|
|||
137 | options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] |
|
|||
138 | options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice'] |
|
|||
139 | options[:default_group] = ENV['default_group'] if ENV['default_group'] |
|
|||
140 |
|
||||
141 | Redmine::IMAP.check(imap_options, options) |
|
|||
142 | end |
|
126 | end | |
143 |
|
127 | |||
144 | desc <<-END_DESC |
|
128 | desc <<-END_DESC | |
@@ -165,15 +149,7 END_DESC | |||||
165 | :password => ENV['password'], |
|
149 | :password => ENV['password'], | |
166 | :delete_unprocessed => ENV['delete_unprocessed']} |
|
150 | :delete_unprocessed => ENV['delete_unprocessed']} | |
167 |
|
151 | |||
168 | options = { :issue => {} } |
|
152 | Redmine::POP3.check(pop_options, MailHandler.extract_options_from_env(ENV)) | |
169 | %w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] } |
|
|||
170 | options[:allow_override] = ENV['allow_override'] if ENV['allow_override'] |
|
|||
171 | options[:unknown_user] = ENV['unknown_user'] if ENV['unknown_user'] |
|
|||
172 | options[:no_permission_check] = ENV['no_permission_check'] if ENV['no_permission_check'] |
|
|||
173 | options[:no_account_notice] = ENV['no_account_notice'] if ENV['no_account_notice'] |
|
|||
174 | options[:default_group] = ENV['default_group'] if ENV['default_group'] |
|
|||
175 |
|
||||
176 | Redmine::POP3.check(pop_options, options) |
|
|||
177 | end |
|
153 | end | |
178 |
|
154 | |||
179 | desc "Send a test email to the user with the provided login name" |
|
155 | desc "Send a test email to the user with the provided login name" |
@@ -798,6 +798,19 class MailHandlerTest < ActiveSupport::TestCase | |||||
798 | assert_equal str2, user.lastname |
|
798 | assert_equal str2, user.lastname | |
799 | end |
|
799 | end | |
800 |
|
800 | |||
|
801 | def test_extract_options_from_env_should_return_options | |||
|
802 | options = MailHandler.extract_options_from_env({ | |||
|
803 | 'tracker' => 'defect', | |||
|
804 | 'project' => 'foo', | |||
|
805 | 'unknown_user' => 'create' | |||
|
806 | }) | |||
|
807 | ||||
|
808 | assert_equal({ | |||
|
809 | :issue => {:tracker => 'defect', :project => 'foo'}, | |||
|
810 | :unknown_user => 'create' | |||
|
811 | }, options) | |||
|
812 | end | |||
|
813 | ||||
801 | private |
|
814 | private | |
802 |
|
815 | |||
803 | def submit_email(filename, options={}) |
|
816 | def submit_email(filename, options={}) |
General Comments 0
You need to be logged in to leave comments.
Login now