2016-05-30 17:13:42 -04:00
|
|
|
require 'yaml'
|
|
|
|
require 'json'
|
2016-07-07 21:33:37 -04:00
|
|
|
require_relative 'redis' unless defined?(Gitlab::Redis)
|
2016-05-30 17:13:42 -04:00
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module MailRoom
|
|
|
|
class << self
|
|
|
|
def enabled?
|
|
|
|
config[:enabled] && config[:address]
|
|
|
|
end
|
|
|
|
|
|
|
|
def config
|
|
|
|
@config ||= fetch_config
|
|
|
|
end
|
|
|
|
|
2016-08-04 12:55:24 -04:00
|
|
|
def reset_config!
|
|
|
|
@config = nil
|
2016-07-09 11:13:19 -04:00
|
|
|
end
|
|
|
|
|
2016-05-30 17:13:42 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_config
|
2016-07-07 21:33:37 -04:00
|
|
|
return {} unless File.exist?(config_file)
|
2016-05-30 17:13:42 -04:00
|
|
|
|
|
|
|
rails_env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
|
|
|
all_config = YAML.load_file(config_file)[rails_env].deep_symbolize_keys
|
|
|
|
|
|
|
|
config = all_config[:incoming_email] || {}
|
|
|
|
config[:enabled] = false if config[:enabled].nil?
|
|
|
|
config[:port] = 143 if config[:port].nil?
|
|
|
|
config[:ssl] = false if config[:ssl].nil?
|
|
|
|
config[:start_tls] = false if config[:start_tls].nil?
|
|
|
|
config[:mailbox] = 'inbox' if config[:mailbox].nil?
|
|
|
|
|
|
|
|
if config[:enabled] && config[:address]
|
|
|
|
config[:redis_url] = Gitlab::Redis.new(rails_env).url
|
|
|
|
end
|
2016-07-07 21:33:37 -04:00
|
|
|
|
|
|
|
config
|
2016-05-30 17:13:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def config_file
|
2016-07-07 21:33:37 -04:00
|
|
|
ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] || File.expand_path('../../../config/gitlab.yml', __FILE__)
|
2016-05-30 17:13:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|