Class: MailView

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_view.rb,
lib/mail_view/mapper.rb

Defined Under Namespace

Classes: Mapper

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(env) ⇒ Object


19
20
21
# File 'lib/mail_view.rb', line 19

def call(env)
  new.call(env)
end

.default_email_template_pathObject


11
12
13
# File 'lib/mail_view.rb', line 11

def default_email_template_path
  File.expand_path('../mail_view/email.html.erb', __FILE__)
end

.default_index_template_pathObject


15
16
17
# File 'lib/mail_view.rb', line 15

def default_index_template_path
  File.expand_path('../mail_view/index.html.erb', __FILE__)
end

Instance Method Details

#call(env) ⇒ Object


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
56
57
58
59
60
61
62
63
64
# File 'lib/mail_view.rb', line 24

def call(env)
  request = Rack::Request.new(env)

  if request.path_info == "" || request.path_info == "/"
    links = self.actions.map do |action|
      [action, "#{request.script_name}/#{action}"]
    end

    ok index_template.render(Object.new, :links => links)

  elsif request.path =~ /([\w_]+)(\.\w+)?\z/
    name, ext = $1, $2
    format = Rack::Mime.mime_type(ext, nil)
    missing_format = ext && format.nil?

    if actions.include?(name) && !missing_format
      mail = build_mail(name)

      # Requested a specific bare MIME part. Render it verbatim.
      if part_type = request.params['part']
        if part = find_part(mail, part_type)
          body = part.body
          body = body.decoded if body.respond_to?(:decoded)
          ok body, part.content_type
        else
          not_found
        end

      # Otherwise, show our message headers & frame the body.
      else
        part = find_preferred_part(mail, [format, 'text/html', 'text/plain'])
        ok email_template.render(Object.new, :name => name, :mail => mail, :part => part, :part_url => part_body_url(part))
      end
    else
      not_found
    end

  else
    not_found(true)
  end
end