##// END OF EJS Templates
remove trailing white-spaces from extra/mail_handler/rdm-mailhandler.rb...
Toshi MARUYAMA -
r9158:be04f1dd6270
parent child
Show More
@@ -10,10 +10,10
10 # rdm-mailhandler [options] --url=<Redmine URL> --key=<API key>
10 # rdm-mailhandler [options] --url=<Redmine URL> --key=<API key>
11 #
11 #
12 # == Arguments
12 # == Arguments
13 #
13 #
14 # -u, --url URL of the Redmine server
14 # -u, --url URL of the Redmine server
15 # -k, --key Redmine API key
15 # -k, --key Redmine API key
16 #
16 #
17 # General options:
17 # General options:
18 # --unknown-user=ACTION how to handle emails from an unknown user
18 # --unknown-user=ACTION how to handle emails from an unknown user
19 # ACTION can be one of the following values:
19 # ACTION can be one of the following values:
@@ -30,7 +30,7
30 # -h, --help show this help
30 # -h, --help show this help
31 # -v, --verbose show extra information
31 # -v, --verbose show extra information
32 # -V, --version show version information and exit
32 # -V, --version show version information and exit
33 #
33 #
34 # Issue attributes control options:
34 # Issue attributes control options:
35 # -p, --project=PROJECT identifier of the target project
35 # -p, --project=PROJECT identifier of the target project
36 # -s, --status=STATUS name of the target status
36 # -s, --status=STATUS name of the target status
@@ -40,15 +40,15
40 # -o, --allow-override=ATTRS allow email content to override attributes
40 # -o, --allow-override=ATTRS allow email content to override attributes
41 # specified by previous options
41 # specified by previous options
42 # ATTRS is a comma separated list of attributes
42 # ATTRS is a comma separated list of attributes
43 #
43 #
44 # == Examples
44 # == Examples
45 # No project specified. Emails MUST contain the 'Project' keyword:
45 # No project specified. Emails MUST contain the 'Project' keyword:
46 #
46 #
47 # rdm-mailhandler --url http://redmine.domain.foo --key secret
47 # rdm-mailhandler --url http://redmine.domain.foo --key secret
48 #
48 #
49 # Fixed project and default tracker specified, but emails can override
49 # Fixed project and default tracker specified, but emails can override
50 # both tracker and priority attributes using keywords:
50 # both tracker and priority attributes using keywords:
51 #
51 #
52 # rdm-mailhandler --url https://domain.foo/redmine --key secret \\
52 # rdm-mailhandler --url https://domain.foo/redmine --key secret \\
53 # --project foo \\
53 # --project foo \\
54 # --tracker bug \\
54 # --tracker bug \\
@@ -79,12 +79,12 end
79
79
80 class RedmineMailHandler
80 class RedmineMailHandler
81 VERSION = '0.1'
81 VERSION = '0.1'
82
82
83 attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key, :no_check_certificate
83 attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key, :no_check_certificate
84
84
85 def initialize
85 def initialize
86 self.issue_attributes = {}
86 self.issue_attributes = {}
87
87
88 opts = GetoptLong.new(
88 opts = GetoptLong.new(
89 [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
89 [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
90 [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
90 [ '--version', '-V', GetoptLong::NO_ARGUMENT ],
@@ -134,28 +134,28 class RedmineMailHandler
134 self.no_check_certificate = true
134 self.no_check_certificate = true
135 end
135 end
136 end
136 end
137
137
138 RDoc.usage if url.nil?
138 RDoc.usage if url.nil?
139 end
139 end
140
140
141 def submit(email)
141 def submit(email)
142 uri = url.gsub(%r{/*$}, '') + '/mail_handler'
142 uri = url.gsub(%r{/*$}, '') + '/mail_handler'
143
143
144 headers = { 'User-Agent' => "Redmine mail handler/#{VERSION}" }
144 headers = { 'User-Agent' => "Redmine mail handler/#{VERSION}" }
145
145
146 data = { 'key' => key, 'email' => email,
146 data = { 'key' => key, 'email' => email,
147 'allow_override' => allow_override,
147 'allow_override' => allow_override,
148 'unknown_user' => unknown_user,
148 'unknown_user' => unknown_user,
149 'no_permission_check' => no_permission_check}
149 'no_permission_check' => no_permission_check}
150 issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
150 issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
151
151
152 debug "Posting to #{uri}..."
152 debug "Posting to #{uri}..."
153 response = Net::HTTPS.post_form(URI.parse(uri), data, headers, :no_check_certificate => no_check_certificate)
153 response = Net::HTTPS.post_form(URI.parse(uri), data, headers, :no_check_certificate => no_check_certificate)
154 debug "Response received: #{response.code}"
154 debug "Response received: #{response.code}"
155
155
156 case response.code.to_i
156 case response.code.to_i
157 when 403
157 when 403
158 warn "Request was denied by your Redmine server. " +
158 warn "Request was denied by your Redmine server. " +
159 "Make sure that 'WS for incoming emails' is enabled in application settings and that you provided the correct API key."
159 "Make sure that 'WS for incoming emails' is enabled in application settings and that you provided the correct API key."
160 return 77
160 return 77
161 when 422
161 when 422
@@ -175,9 +175,9 class RedmineMailHandler
175 return 1
175 return 1
176 end
176 end
177 end
177 end
178
178
179 private
179 private
180
180
181 def debug(msg)
181 def debug(msg)
182 puts msg if verbose
182 puts msg if verbose
183 end
183 end
General Comments 0
You need to be logged in to leave comments. Login now