Class: Gitlab::Email::Handler::UnsubscribeHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Gitlab::Email::Handler::UnsubscribeHandler
show all
- Defined in:
- lib/gitlab/email/handler/unsubscribe_handler.rb
Constant Summary
collapse
- HANDLER_REGEX_FOR =
->(suffix) {
/\A(?<reply_token>#{::SentNotification::FULL_REPLY_KEY_REGEX})#{Regexp.escape(suffix)}\z/
}.freeze
- HANDLER_REGEX =
HANDLER_REGEX_FOR.call(Gitlab::Email::Common::UNSUBSCRIBE_SUFFIX).freeze
- HANDLER_REGEX_LEGACY =
HANDLER_REGEX_FOR.call(Gitlab::Email::Common::UNSUBSCRIBE_SUFFIX_LEGACY).freeze
Constants inherited
from BaseHandler
BaseHandler::HANDLER_ACTION_BASE_REGEX
Instance Attribute Summary
Attributes inherited from BaseHandler
#mail, #mail_key
Instance Method Summary
collapse
Methods inherited from BaseHandler
#metrics_params
Constructor Details
Returns a new instance of UnsubscribeHandler.
20
21
22
23
24
25
|
# File 'lib/gitlab/email/handler/unsubscribe_handler.rb', line 20
def initialize(mail, mail_key)
super(mail, mail_key)
matched = HANDLER_REGEX.match(mail_key.to_s) || HANDLER_REGEX_LEGACY.match(mail_key.to_s)
@reply_token = matched[:reply_token] if matched
end
|
Instance Method Details
#can_handle? ⇒ Boolean
27
28
29
|
# File 'lib/gitlab/email/handler/unsubscribe_handler.rb', line 27
def can_handle?
reply_token.present?
end
|
#execute ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/gitlab/email/handler/unsubscribe_handler.rb', line 31
def execute
raise SentNotificationNotFoundError unless sent_notification
return unless sent_notification.unsubscribable?
noteable = sent_notification.noteable
raise NoteableNotFoundError unless noteable
noteable.unsubscribe(sent_notification.recipient)
end
|
#metrics_event ⇒ Object
41
42
43
|
# File 'lib/gitlab/email/handler/unsubscribe_handler.rb', line 41
def metrics_event
:receive_email_unsubscribe
end
|