Revision 912:5e80956cc792 extra/mail_handler
| extra/mail_handler/rdm-mailhandler.rb | ||
|---|---|---|
| 22 | 22 |
# create: create a user account |
| 23 | 23 |
# --no-permission-check disable permission checking when receiving |
| 24 | 24 |
# the email |
| 25 |
# --key-file=PATH path to a file that contains the Redmine |
|
| 26 |
# API key (use this option instead of --key |
|
| 27 |
# if you don't the key to appear in the |
|
| 28 |
# command line) |
|
| 29 |
# --no-check-certificate do not check server certificate |
|
| 25 | 30 |
# -h, --help show this help |
| 26 | 31 |
# -v, --verbose show extra information |
| 27 | 32 |
# -V, --version show version information and exit |
| ... | ... | |
| 57 | 62 |
|
| 58 | 63 |
module Net |
| 59 | 64 |
class HTTPS < HTTP |
| 60 |
def self.post_form(url, params, headers) |
|
| 65 |
def self.post_form(url, params, headers, options={})
|
|
| 61 | 66 |
request = Post.new(url.path) |
| 62 | 67 |
request.form_data = params |
| 63 | 68 |
request.basic_auth url.user, url.password if url.user |
| 64 | 69 |
request.initialize_http_header(headers) |
| 65 | 70 |
http = new(url.host, url.port) |
| 66 | 71 |
http.use_ssl = (url.scheme == 'https') |
| 72 |
if options[:no_check_certificate] |
|
| 73 |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE |
|
| 74 |
end |
|
| 67 | 75 |
http.start {|h| h.request(request) }
|
| 68 | 76 |
end |
| 69 | 77 |
end |
| ... | ... | |
| 72 | 80 |
class RedmineMailHandler |
| 73 | 81 |
VERSION = '0.1' |
| 74 | 82 |
|
| 75 |
attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key |
|
| 83 |
attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key, :no_check_certificate
|
|
| 76 | 84 |
|
| 77 | 85 |
def initialize |
| 78 | 86 |
self.issue_attributes = {}
|
| ... | ... | |
| 83 | 91 |
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ], |
| 84 | 92 |
[ '--url', '-u', GetoptLong::REQUIRED_ARGUMENT ], |
| 85 | 93 |
[ '--key', '-k', GetoptLong::REQUIRED_ARGUMENT], |
| 94 |
[ '--key-file', GetoptLong::REQUIRED_ARGUMENT], |
|
| 86 | 95 |
[ '--project', '-p', GetoptLong::REQUIRED_ARGUMENT ], |
| 87 | 96 |
[ '--status', '-s', GetoptLong::REQUIRED_ARGUMENT ], |
| 88 | 97 |
[ '--tracker', '-t', GetoptLong::REQUIRED_ARGUMENT], |
| ... | ... | |
| 90 | 99 |
[ '--priority', GetoptLong::REQUIRED_ARGUMENT], |
| 91 | 100 |
[ '--allow-override', '-o', GetoptLong::REQUIRED_ARGUMENT], |
| 92 | 101 |
[ '--unknown-user', GetoptLong::REQUIRED_ARGUMENT], |
| 93 |
[ '--no-permission-check', GetoptLong::NO_ARGUMENT] |
|
| 102 |
[ '--no-permission-check', GetoptLong::NO_ARGUMENT], |
|
| 103 |
[ '--no-check-certificate', GetoptLong::NO_ARGUMENT] |
|
| 94 | 104 |
) |
| 95 | 105 |
|
| 96 | 106 |
opts.each do |opt, arg| |
| ... | ... | |
| 99 | 109 |
self.url = arg.dup |
| 100 | 110 |
when '--key' |
| 101 | 111 |
self.key = arg.dup |
| 112 |
when '--key-file' |
|
| 113 |
begin |
|
| 114 |
self.key = File.read(arg).strip |
|
| 115 |
rescue Exception => e |
|
| 116 |
$stderr.puts "Unable to read the key from #{arg}: #{e.message}"
|
|
| 117 |
exit 1 |
|
| 118 |
end |
|
| 102 | 119 |
when '--help' |
| 103 | 120 |
usage |
| 104 | 121 |
when '--verbose' |
| ... | ... | |
| 113 | 130 |
self.unknown_user = arg.dup |
| 114 | 131 |
when '--no-permission-check' |
| 115 | 132 |
self.no_permission_check = '1' |
| 133 |
when '--no-check-certificate' |
|
| 134 |
self.no_check_certificate = true |
|
| 116 | 135 |
end |
| 117 | 136 |
end |
| 118 | 137 |
|
| ... | ... | |
| 131 | 150 |
issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
|
| 132 | 151 |
|
| 133 | 152 |
debug "Posting to #{uri}..."
|
| 134 |
response = Net::HTTPS.post_form(URI.parse(uri), data, headers) |
|
| 153 |
response = Net::HTTPS.post_form(URI.parse(uri), data, headers, :no_check_certificate => no_check_certificate)
|
|
| 135 | 154 |
debug "Response received: #{response.code}"
|
| 136 | 155 |
|
| 137 | 156 |
case response.code.to_i |
Also available in: Unified diff