| 23 |
23 |
end
|
| 24 |
24 |
|
| 25 |
25 |
class RedmineMailHandler
|
| 26 |
|
VERSION = '0.2.1'
|
|
26 |
VERSION = '0.2.3'
|
| 27 |
27 |
|
| 28 |
|
attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key, :no_check_certificate
|
|
28 |
attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :default_group, :no_permission_check,
|
|
29 |
:url, :key, :no_check_certificate, :no_account_notice, :no_notification
|
| 29 |
30 |
|
| 30 |
31 |
def initialize
|
| 31 |
32 |
self.issue_attributes = {}
|
| ... | ... | |
| 40 |
41 |
opts.on("-k", "--key KEY", "Redmine API key") {|v| self.key = v}
|
| 41 |
42 |
opts.separator("")
|
| 42 |
43 |
opts.separator("General options:")
|
| 43 |
|
opts.on("--unknown-user ACTION", "how to handle emails from an unknown user",
|
| 44 |
|
"ACTION can be one of the following values:",
|
| 45 |
|
"* ignore: email is ignored (default)",
|
| 46 |
|
"* accept: accept as anonymous user",
|
| 47 |
|
"* create: create a user account") {|v| self.unknown_user = v}
|
| 48 |
44 |
opts.on("--no-permission-check", "disable permission checking when receiving",
|
| 49 |
45 |
"the email") {self.no_permission_check = '1'}
|
| 50 |
46 |
opts.on("--key-file FILE", "path to a file that contains the Redmine",
|
| ... | ... | |
| 56 |
52 |
opts.on("-v", "--verbose", "show extra information") {self.verbose = true}
|
| 57 |
53 |
opts.on("-V", "--version", "show version information and exit") {puts VERSION; exit}
|
| 58 |
54 |
opts.separator("")
|
|
55 |
opts.separator("User creation options:")
|
|
56 |
opts.on("--unknown-user ACTION", "how to handle emails from an unknown user",
|
|
57 |
"ACTION can be one of the following values:",
|
|
58 |
"* ignore: email is ignored (default)",
|
|
59 |
"* accept: accept as anonymous user",
|
|
60 |
"* create: create a user account") {|v| self.unknown_user = v}
|
|
61 |
opts.on("--default-group GROUP", "add created user to GROUP (none by default)",
|
|
62 |
"GROUP can be a comma separated list of groups") { |v| self.default_group = v}
|
|
63 |
opts.on("--no-account-notice", "don't send account information to the newly",
|
|
64 |
"created user") { |v| self.no_account_notice = '1'}
|
|
65 |
opts.on("--no-notification", "disable email notifications for the created",
|
|
66 |
"user") { |v| self.no_notification = '1'}
|
|
67 |
opts.separator("")
|
| 59 |
68 |
opts.separator("Issue attributes control options:")
|
| 60 |
69 |
opts.on("-p", "--project PROJECT", "identifier of the target project") {|v| self.issue_attributes['project'] = v}
|
| 61 |
70 |
opts.on("-s", "--status STATUS", "name of the target status") {|v| self.issue_attributes['status'] = v}
|
| ... | ... | |
| 95 |
104 |
data = { 'key' => key, 'email' => email,
|
| 96 |
105 |
'allow_override' => allow_override,
|
| 97 |
106 |
'unknown_user' => unknown_user,
|
|
107 |
'default_group' => default_group,
|
|
108 |
'no_account_notice' => no_account_notice,
|
|
109 |
'no_notification' => no_notification,
|
| 98 |
110 |
'no_permission_check' => no_permission_check}
|
| 99 |
111 |
issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
|
| 100 |
112 |
|
| 101 |
113 |
debug "Posting to #{uri}..."
|
| 102 |
|
response = Net::HTTPS.post_form(URI.parse(uri), data, headers, :no_check_certificate => no_check_certificate)
|
|
114 |
begin
|
|
115 |
response = Net::HTTPS.post_form(URI.parse(uri), data, headers, :no_check_certificate => no_check_certificate)
|
|
116 |
rescue SystemCallError => e # connection refused, etc.
|
|
117 |
warn "An error occured while contacting your Redmine server: #{e.message}"
|
|
118 |
return 75 # temporary failure
|
|
119 |
end
|
| 103 |
120 |
debug "Response received: #{response.code}"
|
| 104 |
121 |
|
| 105 |
122 |
case response.code.to_i
|