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

48 lines
1008 B
Ruby
Raw Normal View History

2015-08-19 00:02:26 +00:00
module Gitlab
module IncomingEmail
2015-08-19 00:02:26 +00:00
class << self
FALLBACK_MESSAGE_ID_REGEX = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\Z/.freeze
def enabled?
config.enabled && config.address
2015-08-19 00:02:26 +00:00
end
def reply_address(key)
config.address.gsub('%{key}', key)
2015-08-19 00:02:26 +00:00
end
def key_from_address(address)
2015-08-20 23:44:44 +00:00
regex = address_regex
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
def key_from_fallback_message_id(mail_id)
match = mail_id.match(FALLBACK_MESSAGE_ID_REGEX)
return unless match
match[1]
end
2015-08-19 00:02:26 +00:00
def config
Gitlab.config.incoming_email
2015-08-19 00:02:26 +00:00
end
private
2015-08-19 00:02:26 +00:00
def address_regex
2015-08-20 23:21:31 +00:00
wildcard_address = config.address
return nil unless wildcard_address
regex = Regexp.escape(wildcard_address)
regex = regex.gsub(Regexp.escape('%{key}'), "(.+)")
2015-08-20 23:21:31 +00:00
Regexp.new(regex).freeze
2015-08-19 00:02:26 +00:00
end
end
end
end