Welcome to mirror list, hosted at ThFree Co, Russian Federation.

incoming_email.rb « email « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a0a01ae0d704c03a0465a977654424a398dc78be (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
# frozen_string_literal: true

module Gitlab
  module Email
    module IncomingEmail
      class << self
        include Gitlab::Email::Common

        def config
          incoming_email_config
        end

        def key_from_address(address, wildcard_address: nil)
          wildcard_address ||= config.address
          regex = address_regex(wildcard_address)
          return unless regex

          match = address.match(regex)
          return unless match

          match[1]
        end

        private

        def address_regex(wildcard_address)
          return unless wildcard_address

          regex = Regexp.escape(wildcard_address)
          regex = regex.sub(Regexp.escape(WILDCARD_PLACEHOLDER), '(.+)')
          Regexp.new(/\A<?#{regex}>?\z/).freeze
        end
      end
    end
  end
end