Module: Gitlab::IncomingEmail

Defined in:
lib/gitlab/incoming_email.rb

Constant Summary collapse

UNSUBSCRIBE_SUFFIX =
'-unsubscribe'
UNSUBSCRIBE_SUFFIX_LEGACY =
'+unsubscribe'
WILDCARD_PLACEHOLDER =
'%{key}'

Class Method Summary collapse

Class Method Details

.configObject


53
54
55
# File 'lib/gitlab/incoming_email.rb', line 53

def config
  Gitlab.config.incoming_email
end

.enabled?Boolean

Returns:

  • (Boolean)

10
11
12
# File 'lib/gitlab/incoming_email.rb', line 10

def enabled?
  config.enabled && config.address.present?
end

.key_from_address(address, wildcard_address: nil) ⇒ Object


31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/incoming_email.rb', line 31

def key_from_address(address, wildcard_address: nil)
  wildcard_address ||= config.address
  regex = address_regex(wildcard_address)
  return unless regex

  match = address.match(regex)
  return unless match

  match[1]
end

.key_from_fallback_message_id(mail_id) ⇒ Object


42
43
44
45
46
# File 'lib/gitlab/incoming_email.rb', line 42

def key_from_fallback_message_id(mail_id)
  message_id_regexp = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\z/

  mail_id[message_id_regexp, 1]
end

.reply_address(key) ⇒ Object


22
23
24
# File 'lib/gitlab/incoming_email.rb', line 22

def reply_address(key)
  config.address.sub(WILDCARD_PLACEHOLDER, key)
end

.scan_fallback_references(references) ⇒ Object


48
49
50
51
# File 'lib/gitlab/incoming_email.rb', line 48

def scan_fallback_references(references)
  # It's looking for each <...>
  references.scan(/(?!<)[^<>]+(?=>)/)
end

.supports_issue_creation?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/gitlab/incoming_email.rb', line 18

def supports_issue_creation?
  enabled? && supports_wildcard?
end

.supports_wildcard?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/gitlab/incoming_email.rb', line 14

def supports_wildcard?
  config.address.present? && config.address.include?(WILDCARD_PLACEHOLDER)
end

.unsubscribe_address(key) ⇒ Object

example: [email protected]itlab.com


27
28
29
# File 'lib/gitlab/incoming_email.rb', line 27

def unsubscribe_address(key)
  config.address.sub(WILDCARD_PLACEHOLDER, "#{key}#{UNSUBSCRIBE_SUFFIX}")
end