blob: b49cf1c633b873994775c3c94fccfca53a5f8c8b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
require 'yaml'
require 'json'
require_relative 'redis' unless defined?(Gitlab::Redis)
module Gitlab
module MailRoom
class << self
def enabled?
config[:enabled] && config[:address]
end
def config
@config ||= fetch_config
end
def reload_config!
@config = fetch_config
end
private
def fetch_config
return {} unless File.exist?(config_file)
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
config
end
def config_file
ENV['MAIL_ROOM_GITLAB_CONFIG_FILE'] || File.expand_path('../../../config/gitlab.yml', __FILE__)
end
end
end
end
|