Class: Gitlab::Email::Receiver

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/email/receiver.rb

Defined Under Namespace

Classes: AutoGeneratedEmailError, EmailUnparsableError, EmptyEmailError, InvalidNoteError, NoteableNotFoundError, ProcessingError, SentNotificationNotFoundError, UserBlockedError, UserNotAuthorizedError, UserNotFoundError

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Receiver


16
17
18
# File 'lib/gitlab/email/receiver.rb', line 16

def initialize(raw)
  @raw = raw
end

Instance Method Details

#executeObject

Raises:


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/gitlab/email/receiver.rb', line 20

def execute
  raise EmptyEmailError if @raw.blank?

  raise SentNotificationNotFoundError unless sent_notification

  raise AutoGeneratedEmailError if message.header.to_s =~ /auto-(generated|replied)/

  author = sent_notification.recipient

  raise UserNotFoundError unless author

  raise UserBlockedError if author.blocked?

  project = sent_notification.project

  raise UserNotAuthorizedError unless project && author.can?(:create_note, project)

  raise NoteableNotFoundError unless sent_notification.noteable

  reply = ReplyParser.new(message).execute.strip

  raise EmptyEmailError if reply.blank?

  reply = add_attachments(reply)

  note = create_note(reply)

  unless note.persisted?
    msg = "The comment could not be created for the following reasons:"
    note.errors.full_messages.each do |error|
      msg << "\n\n- #{error}"
    end

    raise InvalidNoteError, msg
  end
end