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
65
66
|
# 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 sub_type = request.params['part']
if part = find_part(mail, sub_type)
body = part.body
body = body.decoded if body.respond_to?(:decoded)
ok body, part.content_type
else
not_found
end
else
part = find_part(mail, format || 'text/*') || mail
part_type = [part.main_type, part.sub_type].compact.join('/')
part_url = "#{request.path}?part=#{Rack::Utils.escape part_type}"
ok email_template.render(Object.new, :name => name, :mail => mail, :part => part, :part_url => part_url)
end
else
not_found
end
else
not_found(true)
end
end
|