2015-08-18 20:02:26 -04:00
|
|
|
module Gitlab
|
2015-09-21 03:46:47 -04:00
|
|
|
module IncomingEmail
|
2015-08-18 20:02:26 -04:00
|
|
|
class << self
|
2016-05-20 19:21:58 -04:00
|
|
|
FALLBACK_MESSAGE_ID_REGEX = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\Z/.freeze
|
2015-08-20 17:03:04 -04:00
|
|
|
|
2016-03-17 15:03:51 -04:00
|
|
|
def enabled?
|
|
|
|
config.enabled && config.address
|
2015-08-18 20:02:26 -04:00
|
|
|
end
|
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
def reply_address(key)
|
|
|
|
config.address.gsub('%{key}', key)
|
2015-08-18 20:02:26 -04:00
|
|
|
end
|
|
|
|
|
2015-09-21 03:46:47 -04:00
|
|
|
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
|
|
|
|
|
2016-05-20 19:21:58 -04:00
|
|
|
def key_from_fallback_message_id(mail_id)
|
|
|
|
match = mail_id.match(FALLBACK_MESSAGE_ID_REGEX)
|
2016-03-17 15:03:51 -04:00
|
|
|
return unless match
|
|
|
|
|
|
|
|
match[1]
|
|
|
|
end
|
|
|
|
|
2015-08-18 20:02:26 -04:00
|
|
|
def config
|
2015-09-21 03:46:47 -04:00
|
|
|
Gitlab.config.incoming_email
|
2015-08-18 20:02:26 -04:00
|
|
|
end
|
|
|
|
|
2015-10-13 07:07:59 -04:00
|
|
|
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)
|
2015-09-21 03:46:47 -04:00
|
|
|
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
|