Class: MailsViewer::HomeController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/mails_viewer/home_controller.rb

Instance Method Summary collapse

Instance Method Details

#attachmentObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/mails_viewer/home_controller.rb', line 42

def attachment
  if @filename
    mail = Mail.read(@filename)
    attachment = mail.attachments[params[:attachment]]

    if attachment
      send_data attachment.body.decoded, filename: params[:attachment], type: attachment.content_type and return
    end
  end

  head :not_found
end

#htmlObject



23
24
25
26
27
28
29
30
31
# File 'app/controllers/mails_viewer/home_controller.rb', line 23

def html
  if @filename
    mail = Mail.read(@filename)
    body = mail.html_part ? mail.html_part.body : mail.body
    render text: body
  else
    head :not_found
  end
end

#indexObject



7
8
9
10
11
12
13
# File 'app/controllers/mails_viewer/home_controller.rb', line 7

def index
  Dir.chdir(mails_path) do
    @mails = Dir["**/*"]
      .select{|f| File.file?(f)}
      .map{|f| [Mail.read(f), f]}
  end
end

#plainObject



33
34
35
36
37
38
39
40
# File 'app/controllers/mails_viewer/home_controller.rb', line 33

def plain
  if @filename
    mail = Mail.read(@filename)
    @body = mail.text_part ? mail.text_part.body.to_s : mail.body.to_s
  else
    head :not_found
  end
end

#rawObject



15
16
17
18
19
20
21
# File 'app/controllers/mails_viewer/home_controller.rb', line 15

def raw
  if @filename
    render text: File.read(@filename)
  else
    head :not_found
  end
end