debian-mirror-gitlab/lib/gitlab/incoming_email.rb

48 lines
1,008 B
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
module Gitlab
module IncomingEmail
class << self
2016-09-13 17:45:13 +05:30
FALLBACK_MESSAGE_ID_REGEX = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\Z/.freeze
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
def enabled?
config.enabled && config.address
2015-09-25 12:07:36 +05:30
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
2016-09-13 17:45:13 +05:30
def key_from_fallback_message_id(mail_id)
match = mail_id.match(FALLBACK_MESSAGE_ID_REGEX)
2016-06-02 11:05:42 +05:30
return unless match
match[1]
end
2015-09-25 12:07:36 +05:30
def config
Gitlab.config.incoming_email
end
2015-10-24 18:46:33 +05:30
private
2015-09-25 12:07:36 +05:30
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