2015-08-18 20:02:26 -04:00
|
|
|
module Gitlab
|
2015-09-21 03:46:47 -04:00
|
|
|
module IncomingEmail
|
2015-08-18 20:02:26 -04:00
|
|
|
class << self
|
|
|
|
def enabled?
|
2015-08-20 17:03:04 -04:00
|
|
|
config.enabled && address_formatted_correctly?
|
|
|
|
end
|
|
|
|
|
|
|
|
def address_formatted_correctly?
|
|
|
|
config.address &&
|
2015-09-21 03:46:47 -04:00
|
|
|
config.address.include?("%{key}")
|
2015-08-18 20:02:26 -04:00
|
|
|
end
|
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
def reply_address(key)
|
|
|
|
config.address.gsub('%{key}', key)
|
2015-08-18 20:02:26 -04:00
|
|
|
end
|
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
def key_from_address(address)
|
2015-08-20 19:44:44 -04:00
|
|
|
regex = address_regex
|
|
|
|
return unless regex
|
2015-08-18 20:02:26 -04:00
|
|
|
|
2015-08-20 19:44:44 -04:00
|
|
|
match = address.match(regex)
|
2015-08-18 20:02:26 -04:00
|
|
|
return unless match
|
|
|
|
|
|
|
|
match[1]
|
|
|
|
end
|
|
|
|
|
|
|
|
def config
|
2015-09-21 03:46:47 -04:00
|
|
|
Gitlab.config.incoming_email
|
2015-08-18 20:02:26 -04:00
|
|
|
end
|
|
|
|
|
2015-10-13 07:07:59 -04:00
|
|
|
private
|
|
|
|
|
2015-08-18 20:02:26 -04:00
|
|
|
def address_regex
|
2015-08-20 19:21:31 -04:00
|
|
|
wildcard_address = config.address
|
|
|
|
return nil unless wildcard_address
|
|
|
|
|
|
|
|
regex = Regexp.escape(wildcard_address)
|
2015-09-21 03:46:47 -04:00
|
|
|
regex = regex.gsub(Regexp.escape('%{key}'), "(.+)")
|
2015-08-20 19:21:31 -04:00
|
|
|
Regexp.new(regex).freeze
|
2015-08-18 20:02:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|