feat(attachments): forwarded messages get attachments too

Test Plan: edgehill --test

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://review.inboxapp.com/D1351
This commit is contained in:
Evan Morikawa 2015-03-25 21:25:08 -04:00
parent dff5465931
commit e728e5990a
4 changed files with 28 additions and 7 deletions

View file

@ -28,6 +28,7 @@ module.exports =
Thread: require '../src/flux/models/thread' Thread: require '../src/flux/models/thread'
Contact: require '../src/flux/models/contact' Contact: require '../src/flux/models/contact'
Message: require '../src/flux/models/message' Message: require '../src/flux/models/message'
MessageUtils: require '../src/flux/models/message-utils'
Namespace: require '../src/flux/models/namespace' Namespace: require '../src/flux/models/namespace'
Calendar: require '../src/flux/models/calendar' Calendar: require '../src/flux/models/calendar'
Event: require '../src/flux/models/event' Event: require '../src/flux/models/event'

View file

@ -3,7 +3,11 @@ _ = require 'underscore-plus'
EmailFrame = require './email-frame' EmailFrame = require './email-frame'
MessageParticipants = require "./message-participants" MessageParticipants = require "./message-participants"
MessageTimestamp = require "./message-timestamp" MessageTimestamp = require "./message-timestamp"
{ComponentRegistry, FileDownloadStore, Utils, Actions} = require 'inbox-exports' {Utils,
Actions,
MessageUtils,
ComponentRegistry,
FileDownloadStore} = require 'inbox-exports'
{RetinaImg} = require 'ui-components' {RetinaImg} = require 'ui-components'
Autolinker = require 'autolinker' Autolinker = require 'autolinker'
@ -170,8 +174,7 @@ MessageItem = React.createClass
# as the image is loaded, and we can estimate final height correctly. # as the image is loaded, and we can estimate final height correctly.
# Note that MessageBodyWidth must be updated if the UI is changed! # Note that MessageBodyWidth must be updated if the UI is changed!
cidRegex = /src=['"]cid:([^'"]*)['"]/g while (result = MessageUtils.cidRegex.exec(body)) isnt null
while (result = cidRegex.exec(body)) isnt null
imgstart = body.lastIndexOf('<', result.index) imgstart = body.lastIndexOf('<', result.index)
imgend = body.indexOf('/>', result.index) imgend = body.indexOf('/>', result.index)
@ -194,7 +197,7 @@ MessageItem = React.createClass
# Replace remaining cid:// references - we will not display them since they'll # Replace remaining cid:// references - we will not display them since they'll
# throw "unknown ERR_UNKNOWN_URL_SCHEME". Show a transparent pixel so that there's # throw "unknown ERR_UNKNOWN_URL_SCHEME". Show a transparent pixel so that there's
# no "missing image" region shown, just a space. # no "missing image" region shown, just a space.
body = body.replace(/src=['"]cid:[^'"]*['"]/g, "src=\"#{TransparentPixel}\"") body = body.replace(MessageUtils.cidRegex, "src=\"#{TransparentPixel}\"")
body body

View file

@ -0,0 +1,4 @@
module.exports =
class MessageUtils
@cidRegexString: "src=['\"]cid:([^'\"]*)['\"]"
@cidRegex: new RegExp(@cidRegexString, "g")

View file

@ -11,6 +11,7 @@ DestroyDraftTask = require '../tasks/destroy-draft'
Thread = require '../models/thread' Thread = require '../models/thread'
Message = require '../models/message' Message = require '../models/message'
MessageUtils = require '../models/message-utils'
Actions = require '../actions' Actions = require '../actions'
{subjectWithPrefix} = require '../models/utils' {subjectWithPrefix} = require '../models/utils'
@ -162,7 +163,7 @@ DraftStore = Reflux.createStore
# Waits for the query promises to resolve and then resolve with a hash # Waits for the query promises to resolve and then resolve with a hash
# of their resolved values. *swoon* # of their resolved values. *swoon*
Promise.props(queries).then ({thread, message}) -> Promise.props(queries).then ({thread, message}) =>
attributes = attributesCallback(thread, message) attributes = attributesCallback(thread, message)
attributes.subject ?= subjectWithPrefix(thread.subject, 'Re:') attributes.subject ?= subjectWithPrefix(thread.subject, 'Re:')
attributes.body ?= "" attributes.body ?= ""
@ -187,7 +188,7 @@ DraftStore = Reflux.createStore
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
#{attribution} #{attribution}
<br> <br>
#{msg.body} #{@_formatBodyForQuoting(msg.body)}
</blockquote>""" </blockquote>"""
delete attributes.quotedMessage delete attributes.quotedMessage
@ -201,6 +202,10 @@ DraftStore = Reflux.createStore
fields.push("CC: #{contactStrings(msg.cc)}") if msg.cc.length > 0 fields.push("CC: #{contactStrings(msg.cc)}") if msg.cc.length > 0
fields.push("BCC: #{contactStrings(msg.bcc)}") if msg.bcc.length > 0 fields.push("BCC: #{contactStrings(msg.bcc)}") if msg.bcc.length > 0
if msg.files?.length > 0
attributes.files ?= []
attributes.files = attributes.files.concat(msg.files)
attributes.subject = subjectWithPrefix(msg.subject, 'Fwd:') attributes.subject = subjectWithPrefix(msg.subject, 'Fwd:')
attributes.body = """ attributes.body = """
<br><br><blockquote class="gmail_quote" <br><br><blockquote class="gmail_quote"
@ -209,7 +214,7 @@ DraftStore = Reflux.createStore
<br><br> <br><br>
#{fields.join('<br>')} #{fields.join('<br>')}
<br><br> <br><br>
#{msg.body} #{@_formatBodyForQuoting(msg.body)}
</blockquote>""" </blockquote>"""
delete attributes.forwardedMessage delete attributes.forwardedMessage
@ -223,6 +228,14 @@ DraftStore = Reflux.createStore
DatabaseStore.persistModel(draft) DatabaseStore.persistModel(draft)
# Eventually we'll want a nicer solution for inline attachments
_formatBodyForQuoting: (body="") ->
cidRE = MessageUtils.cidRegexString
# Be sure to match over multiple lines with [\s\S]*
# Regex explanation here: https://regex101.com/r/vO6eN2/1
re = new RegExp("<img.*#{cidRE}[\\s\\S]*?>", "igm")
body.replace(re, "")
# The logic to create a new Draft used to be in the DraftStore (which is # The logic to create a new Draft used to be in the DraftStore (which is
# where it should be). It got moved to composer/lib/main.cjsx becaues # where it should be). It got moved to composer/lib/main.cjsx becaues
# of an obscure atom-shell/Chrome bug whereby database requests firing right # of an obscure atom-shell/Chrome bug whereby database requests firing right