2015-07-24 01:57:13 +08:00
|
|
|
Autolinker = require 'autolinker'
|
2015-11-28 03:49:24 +08:00
|
|
|
{MessageViewExtension} = require 'nylas-exports'
|
2015-07-24 01:57:13 +08:00
|
|
|
|
2015-11-28 03:49:24 +08:00
|
|
|
class AutolinkerExtension extends MessageViewExtension
|
2015-07-24 01:57:13 +08:00
|
|
|
|
|
|
|
@formatMessageBody: (message) ->
|
|
|
|
# Apply the autolinker pass to make emails and links clickable
|
|
|
|
message.body = Autolinker.link(message.body, {twitter: false})
|
|
|
|
|
2015-11-26 10:29:59 +08:00
|
|
|
# Ensure that the hrefs in the email always have alt text so you can't hide
|
|
|
|
# the target of links
|
|
|
|
# https://regex101.com/r/cH0qM7/1
|
|
|
|
message.body = message.body.replace /href[ ]*=[ ]*?['"]([^'"]*)(['"]+)/gi, (match, url, quoteCharacter) =>
|
|
|
|
return "#{match} title=#{quoteCharacter}#{url}#{quoteCharacter} "
|
|
|
|
|
2015-07-24 01:57:13 +08:00
|
|
|
module.exports = AutolinkerExtension
|