Class: Gitlab::Email::Handler::UnsubscribeHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Gitlab::Email::Handler::UnsubscribeHandler
- Defined in:
- lib/gitlab/email/handler/unsubscribe_handler.rb
Constant Summary collapse
- HANDLER_REGEX_FOR =
-> (suffix) { /\A(?<reply_token>\w+)#{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
Instance Attribute Summary
Attributes inherited from BaseHandler
Instance Method Summary collapse
- #can_handle? ⇒ Boolean
- #execute ⇒ Object
-
#initialize(mail, mail_key) ⇒ UnsubscribeHandler
constructor
A new instance of UnsubscribeHandler.
- #metrics_event ⇒ Object
Methods inherited from BaseHandler
Constructor Details
#initialize(mail, mail_key) ⇒ UnsubscribeHandler
Returns a new instance of UnsubscribeHandler.
18 19 20 21 22 23 |
# File 'lib/gitlab/email/handler/unsubscribe_handler.rb', line 18 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
25 26 27 |
# File 'lib/gitlab/email/handler/unsubscribe_handler.rb', line 25 def can_handle? reply_token.present? end |
#execute ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/gitlab/email/handler/unsubscribe_handler.rb', line 29 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
39 40 41 |
# File 'lib/gitlab/email/handler/unsubscribe_handler.rb', line 39 def metrics_event :receive_email_unsubscribe end |