ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

1369_port_rdm_mailhandler.patch

Max Resnick, 2015-01-21 12:53 am

Download (4.5 kB)

 
b/extra/mail_handler/rdm-mailhandler.rb
65 65
require 'net/http'
66 66
require 'net/https'
67 67
require 'uri'
68
require 'getoptlong'
69
require 'rdoc/usage'
68
require 'optparse'
70 69

  
71 70
module Net
72 71
  class HTTPS < HTTP
......
83 82
end
84 83

  
85 84
class RedmineMailHandler
86
  VERSION = '0.1'
85
  VERSION = '0.2'
87 86

  
88 87
  attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key
89

  
88
      @allow_override = []
90 89
  def initialize
90

  
91 91
    self.issue_attributes = {}
92 92

  
93
    opts = GetoptLong.new(
94
      [ '--help',           '-h', GetoptLong::NO_ARGUMENT ],
95
      [ '--version',        '-V', GetoptLong::NO_ARGUMENT ],
96
      [ '--verbose',        '-v', GetoptLong::NO_ARGUMENT ],
97
      [ '--url',            '-u', GetoptLong::REQUIRED_ARGUMENT ],
98
      [ '--key',            '-k', GetoptLong::REQUIRED_ARGUMENT],
99
      [ '--project',        '-p', GetoptLong::REQUIRED_ARGUMENT ],
100
      [ '--status',         '-s', GetoptLong::REQUIRED_ARGUMENT ],
101
      [ '--tracker',        '-t', GetoptLong::REQUIRED_ARGUMENT],
102
      [ '--category',             GetoptLong::REQUIRED_ARGUMENT],
103
      [ '--priority',             GetoptLong::REQUIRED_ARGUMENT],
104
      [ '--allow-override', '-o', GetoptLong::REQUIRED_ARGUMENT],
105
      [ '--unknown-user',         GetoptLong::REQUIRED_ARGUMENT],
106
      [ '--no-permission-check',  GetoptLong::NO_ARGUMENT]
107
    )
108

  
109
    opts.each do |opt, arg|
110
      case opt
111
      when '--url'
112
        self.url = arg.dup
113
      when '--key'
114
        self.key = arg.dup
115
      when '--help'
116
        usage
117
      when '--verbose'
118
        self.verbose = true
119
      when '--version'
120
        puts VERSION; exit
121
      when '--project', '--status', '--tracker', '--category', '--priority'
122
        self.issue_attributes[opt.gsub(%r{^\-\-}, '')] = arg.dup
123
      when '--allow-override'
124
        self.allow_override = arg.dup
125
      when '--unknown-user'
126
        self.unknown_user = arg.dup
127
      when '--no-permission-check'
128
        self.no_permission_check = '1'
93
    optparse = OptionParser.new do |opts|
94
      
95
      
96
      opts.banner = "rdm-mailhandler [options] --url=<Redmine URL> --key=<API key>"
97
      opts.separator("")
98
      opts.separator("Required arguments:")
99
      opts.on("-u", "--url URL",            "URL of the Redmine server") {|v| self.url = v}
100
      opts.on("-k", "--key KEY",            "Redmine API key") {|v| self.key = v}
101
      opts.separator("")
102
      opts.separator("Options:")
103
      opts.on("--unknown-user",             "how to handle emails from an unknown user",
104
                                            "ACTION can be one of the following values:",
105
                                            "ignore: email is ignored (default)",
106
                                            "accept: accept as anonymous user",
107
                                            "create: create a user account") {|v| self.unknown_user = v}
108
      opts.on("--no-permission-check",      "disable permission checking when receiving",
109
                                            "the email") {self.no_permission_check= '1'}
110
      opts.on("-v", "--verbose",            "verbose") {self.verbose = true}
111
      opts.on("-V", "--version",            "show version and exit") {puts VERSION; exit}
112
      opts.separator("")
113
      opts.separator("Issue attributes control options:")
114
      opts.on("-p", "--project PROJECT",    "identifier of the target project") {|v| self.project = v}
115
      opts.on("-s", "--status STATUS",      "name of the target status") {|v| self.status = v}
116
      opts.on("-t", "--tracker TRACKER",    "name of the target tracker") {|v| self.tracker = v}
117
      opts.on("--category CATEGORY",        "name of the target category") {|v| self.category = v}
118
      opts.on("--priority PRIORITY",        "name of the target priority") {|v| self.priority = v}
119
      opts.on("--allow-override OVERRIDE",  "allow email content to override attributes",
120
                                            "ATTRS is a comma separated list of attributes") {|v| self.allow_override = v}
121
      opts.on("-h", "--help",               "show help and exit") do
122
        puts opts
123
        exit 1
129 124
      end
130 125
    end
126
    optparse.parse!
131 127

  
132
    RDoc.usage if url.nil?
133 128
  end
134 129

  
135 130
  def submit(email)
......
178 173
end
179 174

  
180 175
handler = RedmineMailHandler.new
181
exit(handler.submit(STDIN.read))
176
exit(handler.submit(STDIN.read))