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

incoming_email.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d7be50bd43725d8cee76cf04299b0cc3d7b80308 (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
37
38
39
40
41
42
43
44
45
46
47
module Gitlab
  module IncomingEmail
    class << self
      FALLBACK_MESSAGE_ID_REGEX = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\Z/.freeze

      def enabled?
        config.enabled && config.address
      end

      def reply_address(key)
        config.address.gsub('%{key}', key)
      end

      def key_from_address(address)
        regex = address_regex
        return unless regex

        match = address.match(regex)
        return unless match

        match[1]
      end

      def key_from_fallback_message_id(mail_id)
        match = mail_id.match(FALLBACK_MESSAGE_ID_REGEX)
        return unless match

        match[1]
      end

      def config
        Gitlab.config.incoming_email
      end

      private

      def address_regex
        wildcard_address = config.address
        return nil unless wildcard_address

        regex = Regexp.escape(wildcard_address)
        regex = regex.gsub(Regexp.escape('%{key}'), "(.+)")
        Regexp.new(regex).freeze
      end
    end
  end
end