2016-05-30 17:13:42 -04:00
|
|
|
require 'yaml'
|
|
|
|
require 'json'
|
2017-07-10 23:35:47 -04:00
|
|
|
require_relative 'redis/queues' unless defined?(Gitlab::Redis::Queues)
|
2016-05-30 17:13:42 -04:00
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module MailRoom
|
2017-09-12 13:02:11 -04:00
|
|
|
DEFAULT_CONFIG = {
|
|
|
|
enabled: false,
|
|
|
|
port: 143,
|
|
|
|
ssl: false,
|
|
|
|
start_tls: false,
|
|
|
|
mailbox: 'inbox',
|
|
|
|
idle_timeout: 60
|
|
|
|
}.freeze
|
|
|
|
|
2016-05-30 17:13:42 -04:00
|
|
|
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
|
|
|
|
2017-09-12 13:02:11 -04:00
|
|
|
config = YAML.load_file(config_file)[rails_env].deep_symbolize_keys[:incoming_email] || {}
|
|
|
|
config = DEFAULT_CONFIG.merge(config) do |_key, oldval, newval|
|
|
|
|
newval.nil? ? oldval : newval
|
|
|
|
end
|
2016-05-30 17:13:42 -04:00
|
|
|
|
|
|
|
if config[:enabled] && config[:address]
|
2017-07-10 23:35:47 -04:00
|
|
|
gitlab_redis_queues = Gitlab::Redis::Queues.new(rails_env)
|
|
|
|
config[:redis_url] = gitlab_redis_queues.url
|
2016-10-25 09:50:41 -04:00
|
|
|
|
2017-07-10 23:35:47 -04:00
|
|
|
if gitlab_redis_queues.sentinels?
|
|
|
|
config[:sentinels] = gitlab_redis_queues.sentinels
|
2016-10-25 09:50:41 -04:00
|
|
|
end
|
2016-05-30 17:13:42 -04:00
|
|
|
end
|
2016-07-07 21:33:37 -04:00
|
|
|
|
|
|
|
config
|
2016-05-30 17:13:42 -04:00
|
|
|
end
|
|
|
|
|
2017-09-12 13:02:11 -04:00
|
|
|
def rails_env
|
|
|
|
@rails_env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
|
|
|
end
|
|
|
|
|
2016-05-30 17:13:42 -04:00
|
|
|
def config_file
|
2018-07-02 06:43:06 -04:00
|
|
|
ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] || File.expand_path('../../config/gitlab.yml', __dir__)
|
2016-05-30 17:13:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|