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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
745 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2015-08-19 00:02:26 +00:00
module Gitlab
module IncomingEmail
2015-08-19 00:02:26 +00:00
class << self
include Gitlab::Email::Common
2015-08-19 00:02:26 +00:00
def config
incoming_email_config
2015-08-19 00:02:26 +00:00
end
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
private
def address_regex(wildcard_address)
return unless wildcard_address
2015-08-20 23:21:31 +00:00
regex = Regexp.escape(wildcard_address)
regex = regex.sub(Regexp.escape(WILDCARD_PLACEHOLDER), '(.+)')
Regexp.new(/\A<?#{regex}>?\z/).freeze
2015-08-19 00:02:26 +00:00
end
end
end
end