2017-08-17 22:00:37 +05:30
|
|
|
require 'gitlab/email/handler/base_handler'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Email
|
|
|
|
module Handler
|
|
|
|
class UnsubscribeHandler < BaseHandler
|
|
|
|
delegate :project, to: :sent_notification, allow_nil: true
|
|
|
|
|
|
|
|
def can_handle?
|
|
|
|
mail_key =~ /\A\w+#{Regexp.escape(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX)}\z/
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
raise SentNotificationNotFoundError unless sent_notification
|
|
|
|
return unless sent_notification.unsubscribable?
|
|
|
|
|
|
|
|
noteable = sent_notification.noteable
|
|
|
|
raise NoteableNotFoundError unless noteable
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
noteable.unsubscribe(sent_notification.recipient)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def sent_notification
|
|
|
|
@sent_notification ||= SentNotification.for(reply_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_key
|
|
|
|
mail_key.sub(Gitlab::IncomingEmail::UNSUBSCRIBE_SUFFIX, '')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|