Class: Ishapi::EmailMessagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ishapi/email_messages_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#exception, #home, #long_term_token, #vote

Instance Method Details

#receiveObject

From lambda, ses



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/ishapi/email_messages_controller.rb', line 36

def receive
  if params[:secret] != AWS_SES_LAMBDA_SECRET
    render status: 400, json: { status: 400 }
    return
  end

  msg = Office::EmailMessageStub.new({
    object_key:  params[:object_key],
  })
  if msg.save
    ::Ishapi::EmailMessageIntakeJob.perform_later( msg.id.to_s )
    render status: :ok, json: { status: :ok }
  else
    puts! msg.errors.full_messages, 'Could not save EmailMessageStub'
    render status: 400, json: { status: 400 }
  end
end

#showObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/ishapi/email_messages_controller.rb', line 9

def show
  @msg = Office::EmailMessage.find( params[:id] )
  authorize! :show, @msg

  if params[:load_images]
    ;
  else
    if @msg.part_html
      doc = Nokogiri::HTML(@msg.part_html)
      images = doc.search('img')
      images.each do |img|
        img['src'] = 'missing'
      end
      @msg.part_html = doc
    end
  end

  respond_to do |format|
    format.json do
      render json: { item: @msg, }
    end
    format.html do
    end
  end
end