Project

General

Profile

Defect #6759 ยป 0170-Add-port-option-to-mail-handler.-Fixes-issue-with-po.patch

Stephanie Collett, 2010-10-27 20:46

View differences:

extra/mail_handler/rdm-mailhandler.rb
1
#!/usr/bin/env ruby
1
#!/usr/bin/env /app/redmine/redmine-1.0/local/bin/ruby
2 2
# == Synopsis
3 3
#
......
71 71
class RedmineMailHandler
72 72
  VERSION = '0.1'
73
  attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key
73
  attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key, :port
74 74
  def initialize
75 75
    self.issue_attributes = {}
......
89 89
      [ '--priority',             GetoptLong::REQUIRED_ARGUMENT],
90 90
      [ '--allow-override', '-o', GetoptLong::REQUIRED_ARGUMENT],
91 91
      [ '--unknown-user',         GetoptLong::REQUIRED_ARGUMENT],
92
      [ '--no-permission-check',  GetoptLong::NO_ARGUMENT]
92
      [ '--no-permission-check',  GetoptLong::NO_ARGUMENT],
93
      [ '--port',                  GetoptLong::REQUIRED_ARGUMENT]
93 94
    )
94 95
    opts.each do |opt, arg|
......
112 113
        self.unknown_user = arg.dup
113 114
      when '--no-permission-check'
114 115
        self.no_permission_check = '1'
116
      when '--port'
117
        self.port = arg.dup
115 118
      end
116 119
    end
......
119 122
  end
120 123
  def submit(email)
121
    uri = url.gsub(%r{/*$}, '') + '/mail_handler'
122

  
124
    uri = URI.parse(url.gsub(%r{/*$}, '') + '/mail_handler')
125
    uri.port = self.port unless self.port.nil?
126

  
123 127
    data = { 'key' => key, 'email' => email,
124 128
                           'allow_override' => allow_override,
125 129
                           'unknown_user' => unknown_user,
126 130
                           'no_permission_check' => no_permission_check}
127 131
    issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
128
    debug "Posting to #{uri}..."
129
    response = Net::HTTPS.post_form(URI.parse(uri), data)
132
    debug "Posting to #{uri.to_s}..."
133
    response = Net::HTTPS.post_form(uri, data)
130 134
    debug "Response received: #{response.code}"
131 135
    case response.code.to_i
    (1-1/1)