2015-09-25 12:07:36 +05:30
|
|
|
module Gitlab
|
|
|
|
module IncomingEmail
|
2017-08-17 22:00:37 +05:30
|
|
|
UNSUBSCRIBE_SUFFIX = '+unsubscribe'.freeze
|
|
|
|
WILDCARD_PLACEHOLDER = '%{key}'.freeze
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class << self
|
2016-06-02 11:05:42 +05:30
|
|
|
def enabled?
|
|
|
|
config.enabled && config.address
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def supports_wildcard?
|
|
|
|
config.address && config.address.include?(WILDCARD_PLACEHOLDER)
|
|
|
|
end
|
|
|
|
|
|
|
|
def supports_issue_creation?
|
|
|
|
enabled? && supports_wildcard?
|
|
|
|
end
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
def reply_address(key)
|
2017-08-17 22:00:37 +05:30
|
|
|
config.address.sub(WILDCARD_PLACEHOLDER, key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribe_address(key)
|
|
|
|
config.address.sub(WILDCARD_PLACEHOLDER, "#{key}#{UNSUBSCRIBE_SUFFIX}")
|
2015-09-25 12:07:36 +05:30
|
|
|
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)
|
2017-08-17 22:00:37 +05:30
|
|
|
message_id_regexp = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\z/
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
mail_id[message_id_regexp, 1]
|
|
|
|
end
|
|
|
|
|
|
|
|
def scan_fallback_references(references)
|
|
|
|
# It's looking for each <...>
|
|
|
|
references.scan(/(?!<)[^<>]+(?=>)/)
|
2016-06-02 11:05:42 +05:30
|
|
|
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)
|
2017-08-17 22:00:37 +05:30
|
|
|
regex = regex.sub(Regexp.escape(WILDCARD_PLACEHOLDER), '(.+)')
|
2015-09-25 12:07:36 +05:30
|
|
|
Regexp.new(regex).freeze
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|