response = Net::HTTPS.post_form(URI.parse(uri), data)
debug "Response received: #{response.code}"
- puts "Request was denied by your Redmine server. " +
- "Please, make sure that 'WS for incoming emails' is enabled in application settings and that you provided the correct API key." if response.code == '403'
- response.code == '201' ? 0 : 1
+ case response.code.to_i
+ when 403
+ warn "Request was denied by your Redmine server. " +
+ "Make sure that 'WS for incoming emails' is enabled in application settings and that you provided the correct API key."
+ return 77
+ when 422
+ warn "Request was denied by your Redmine server. " +
+ "Possible reasons: email is sent from an invalid email address or is missing some information."
+ return 77
+ when 400..499
+ warn "Request was denied by your Redmine server (#{response.code})."
+ return 77
+ when 500..599
+ warn "Failed to contact your Redmine server (#{response.code})."
+ return 75
+ when 201
+ debug "Proccessed successfully"
+ return 0
+ else
+ return 1
+ end
end
private
end
handler = RedmineMailHandler.new
-handler.submit(STDIN.read)
+exit(handler.submit(STDIN.read))