mirror of
https://github.com/moparisthebest/mailcatcher
synced 2025-03-11 06:50:12 -04:00
Merge pull request #97 from igneus/url-clickable-in-plain-text
New display format: plain text with clickable URLs
This commit is contained in:
commit
61f0fdede3
@ -48,7 +48,7 @@ class MailCatcher::Web < Sinatra::Base
|
||||
"formats" => [
|
||||
"source",
|
||||
("html" if MailCatcher::Mail.message_has_html? id),
|
||||
("plain" if MailCatcher::Mail.message_has_plain? id),
|
||||
("plain" 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'])}"})
|
||||
@ -69,9 +69,6 @@ class MailCatcher::Web < Sinatra::Base
|
||||
# Rewrite body to link to embedded attachments served by cid
|
||||
body.gsub! /cid:([^'"> ]+)/, "#{id}/parts/\\1"
|
||||
|
||||
# Rewrite body to open links in a new window
|
||||
body.gsub! /<a\s+/, '<a target="_blank" '
|
||||
|
||||
body
|
||||
else
|
||||
not_found
|
||||
|
@ -22,6 +22,9 @@ class MailCatcher
|
||||
$('#message .views .analysis.tab a').live 'click', (e) =>
|
||||
e.preventDefault()
|
||||
@loadMessageAnalysis @selectedMessage()
|
||||
|
||||
$('#message iframe').load =>
|
||||
@decorateMessageBody()
|
||||
|
||||
$('#resizer').live
|
||||
mousedown: (e) =>
|
||||
@ -253,6 +256,22 @@ class MailCatcher
|
||||
if id?
|
||||
$('#message iframe').attr "src", "/messages/#{id}.#{format}"
|
||||
|
||||
app = this
|
||||
|
||||
decorateMessageBody: ->
|
||||
format = $('#message .views .tab.format.selected').attr 'data-message-format'
|
||||
|
||||
switch format
|
||||
when 'html'
|
||||
body = $('#message iframe').contents().find('body')
|
||||
$("a", body).attr("target", "_blank")
|
||||
when 'plain'
|
||||
message_iframe = $('#message iframe').contents()
|
||||
text = message_iframe.text()
|
||||
text = text.replace(/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?)/g, '<a href="$1" target="_blank">$1</a>')
|
||||
text = text.replace(/\n/g, '<br/>')
|
||||
message_iframe.find('html').html('<html><body>' + text + '</html></body>')
|
||||
|
||||
loadMessageAnalysis: (id) ->
|
||||
id ||= @selectedMessage()
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
(function() {
|
||||
var MailCatcher,
|
||||
_this = this;
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||
|
||||
jQuery.expr[':'].icontains = function(a, i, m) {
|
||||
var _ref, _ref1;
|
||||
@ -8,24 +8,13 @@
|
||||
};
|
||||
|
||||
MailCatcher = (function() {
|
||||
|
||||
function MailCatcher() {
|
||||
this.nextTab = __bind(this.nextTab, this);
|
||||
this.previousTab = __bind(this.previousTab, this);
|
||||
this.openTab = __bind(this.openTab, this);
|
||||
this.selectedTab = __bind(this.selectedTab, this);
|
||||
this.getTab = __bind(this.getTab, this);
|
||||
var _this = this;
|
||||
this.nextTab = function(tab) {
|
||||
return MailCatcher.prototype.nextTab.apply(_this, arguments);
|
||||
};
|
||||
this.previousTab = function(tab) {
|
||||
return MailCatcher.prototype.previousTab.apply(_this, arguments);
|
||||
};
|
||||
this.openTab = function(i) {
|
||||
return MailCatcher.prototype.openTab.apply(_this, arguments);
|
||||
};
|
||||
this.selectedTab = function() {
|
||||
return MailCatcher.prototype.selectedTab.apply(_this, arguments);
|
||||
};
|
||||
this.getTab = function(i) {
|
||||
return MailCatcher.prototype.getTab.apply(_this, arguments);
|
||||
};
|
||||
$('#messages tr').live('click', function(e) {
|
||||
e.preventDefault();
|
||||
return _this.loadMessage($(e.currentTarget).attr('data-message-id'));
|
||||
@ -47,6 +36,9 @@
|
||||
e.preventDefault();
|
||||
return _this.loadMessageAnalysis(_this.selectedMessage());
|
||||
});
|
||||
$('#message iframe').load(function() {
|
||||
return _this.decorateMessageBody();
|
||||
});
|
||||
$('#resizer').live({
|
||||
mousedown: function(e) {
|
||||
var events;
|
||||
@ -333,13 +325,31 @@
|
||||
};
|
||||
|
||||
MailCatcher.prototype.loadMessageBody = function(id, format) {
|
||||
var app;
|
||||
id || (id = this.selectedMessage());
|
||||
format || (format = $('#message .views .tab.format.selected').attr('data-message-format'));
|
||||
format || (format = 'html');
|
||||
$("#message .views .tab[data-message-format=\"" + format + "\"]:not(.selected)").addClass('selected');
|
||||
$("#message .views .tab:not([data-message-format=\"" + format + "\"]).selected").removeClass('selected');
|
||||
if (id != null) {
|
||||
return $('#message iframe').attr("src", "/messages/" + id + "." + format);
|
||||
$('#message iframe').attr("src", "/messages/" + id + "." + format);
|
||||
return app = this;
|
||||
}
|
||||
};
|
||||
|
||||
MailCatcher.prototype.decorateMessageBody = function() {
|
||||
var body, format, message_iframe, text;
|
||||
format = $('#message .views .tab.format.selected').attr('data-message-format');
|
||||
switch (format) {
|
||||
case 'html':
|
||||
body = $('#message iframe').contents().find('body');
|
||||
return $("a", body).attr("target", "_blank");
|
||||
case 'plain':
|
||||
message_iframe = $('#message iframe').contents();
|
||||
text = message_iframe.text();
|
||||
text = text.replace(/((http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?)/g, '<a href="$1" target="_blank">$1</a>');
|
||||
text = text.replace(/\n/g, '<br/>');
|
||||
return message_iframe.find('html').html('<html><body>' + text + '</html></body>');
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user