2018-10-22 07:00:50 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-19 00:02:26 +00:00
|
|
|
module Gitlab
|
2015-09-21 07:46:47 +00:00
|
|
|
module IncomingEmail
|
2015-08-19 00:02:26 +00:00
|
|
|
class << self
|
2022-11-04 15:07:23 +00:00
|
|
|
include Gitlab::Email::Common
|
2015-08-19 00:02:26 +00:00
|
|
|
|
2022-11-04 15:07:23 +00:00
|
|
|
def config
|
|
|
|
incoming_email_config
|
2015-08-19 00:02:26 +00:00
|
|
|
end
|
|
|
|
|
2020-02-27 18:09:21 +00:00
|
|
|
def key_from_address(address, wildcard_address: nil)
|
|
|
|
wildcard_address ||= config.address
|
|
|
|
regex = address_regex(wildcard_address)
|
2015-08-20 23:44:44 +00:00
|
|
|
return unless regex
|
2015-08-19 00:02:26 +00:00
|
|
|
|
2015-08-20 23:44:44 +00:00
|
|
|
match = address.match(regex)
|
2015-08-19 00:02:26 +00:00
|
|
|
return unless match
|
|
|
|
|
|
|
|
match[1]
|
|
|
|
end
|
|
|
|
|
2015-10-13 11:07:59 +00:00
|
|
|
private
|
|
|
|
|
2020-02-27 18:09:21 +00:00
|
|
|
def address_regex(wildcard_address)
|
2019-02-08 12:19:53 +00:00
|
|
|
return unless wildcard_address
|
2015-08-20 23:21:31 +00:00
|
|
|
|
|
|
|
regex = Regexp.escape(wildcard_address)
|
2016-10-12 17:07:36 +00:00
|
|
|
regex = regex.sub(Regexp.escape(WILDCARD_PLACEHOLDER), '(.+)')
|
2020-01-30 00:09:09 +00:00
|
|
|
Regexp.new(/\A<?#{regex}>?\z/).freeze
|
2015-08-19 00:02:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|