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

48 lines
1,008 B
Ruby
Raw Normal View History

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