blob: d34c19bc9fcf575e55e27711a07a5995bd602fff (
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
|
# frozen_string_literal: true
module Gitlab
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
|