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)
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
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
|