new display format: plain text with clickable URLs

This commit is contained in:
Jakub Pavlík jn 2013-07-13 16:15:41 +02:00
parent fb13a62589
commit ef09b0fde3
2 changed files with 16 additions and 0 deletions

View File

@ -49,6 +49,7 @@ class MailCatcher::Web < Sinatra::Base
"source",
("html" if MailCatcher::Mail.message_has_html? id),
("plain" if MailCatcher::Mail.message_has_plain? id),
("lessplain" if MailCatcher::Mail.message_has_plain? id),
].compact,
"attachments" => MailCatcher::Mail.message_attachments(id).map do |attachment|
attachment.merge({"href" => "/messages/#{escape(id)}/parts/#{escape(attachment['cid'])}"})
@ -88,6 +89,19 @@ class MailCatcher::Web < Sinatra::Base
end
end
get "/messages/:id.lessplain" do
id = params[:id].to_i
if part = MailCatcher::Mail.message_part_plain(id)
content_type "text/html", :charset => (part["charset"] || "utf8")
body = part["body"]
body.gsub!(/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?)/, '<a href="\\1">\\1</a>')
body.gsub!("\n", "<br/>\n")
"<html><body>" + body + "</body></html>"
else
not_found
end
end
get "/messages/:id.source" do
id = params[:id].to_i
if message = MailCatcher::Mail.message(id)

View File

@ -53,6 +53,8 @@
%a{:href => '#'} HTML
%li.format.tab.plain{'data-message-format' => 'plain'}
%a{:href => '#'}Plain Text
%li.format.tab.plain{'data-message-format' => 'lessplain'}
%a{:href => '#'}Less Plain Text
%li.format.tab.source{'data-message-format' => 'source'}
%a{:href => '#'}Source
%li.tab.analysis