gitlab-org--gitlab-foss/lib/gitlab/incoming_email.rb

44 lines
891 B
Ruby
Raw Normal View History

2015-08-18 20:02:26 -04:00
module Gitlab
module IncomingEmail
2015-08-18 20:02:26 -04:00
class << self
def enabled?
config.enabled && address_formatted_correctly?
end
def address_formatted_correctly?
config.address &&
config.address.include?("%{key}")
2015-08-18 20:02:26 -04:00
end
def reply_address(key)
config.address.gsub('%{key}', key)
2015-08-18 20:02:26 -04:00
end
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
Gitlab.config.incoming_email
2015-08-18 20:02:26 -04:00
end
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)
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