mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-03 19:43:04 +08:00
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:
parent
dff5465931
commit
e728e5990a
4 changed files with 28 additions and 7 deletions
|
@ -28,6 +28,7 @@ module.exports =
|
|||
Thread: require '../src/flux/models/thread'
|
||||
Contact: require '../src/flux/models/contact'
|
||||
Message: require '../src/flux/models/message'
|
||||
MessageUtils: require '../src/flux/models/message-utils'
|
||||
Namespace: require '../src/flux/models/namespace'
|
||||
Calendar: require '../src/flux/models/calendar'
|
||||
Event: require '../src/flux/models/event'
|
||||
|
|
|
@ -3,7 +3,11 @@ _ = require 'underscore-plus'
|
|||
EmailFrame = require './email-frame'
|
||||
MessageParticipants = require "./message-participants"
|
||||
MessageTimestamp = require "./message-timestamp"
|
||||
{ComponentRegistry, FileDownloadStore, Utils, Actions} = require 'inbox-exports'
|
||||
{Utils,
|
||||
Actions,
|
||||
MessageUtils,
|
||||
ComponentRegistry,
|
||||
FileDownloadStore} = require 'inbox-exports'
|
||||
{RetinaImg} = require 'ui-components'
|
||||
Autolinker = require 'autolinker'
|
||||
|
||||
|
@ -170,8 +174,7 @@ MessageItem = React.createClass
|
|||
# as the image is loaded, and we can estimate final height correctly.
|
||||
# Note that MessageBodyWidth must be updated if the UI is changed!
|
||||
|
||||
cidRegex = /src=['"]cid:([^'"]*)['"]/g
|
||||
while (result = cidRegex.exec(body)) isnt null
|
||||
while (result = MessageUtils.cidRegex.exec(body)) isnt null
|
||||
imgstart = body.lastIndexOf('<', 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
|
||||
# throw "unknown ERR_UNKNOWN_URL_SCHEME". Show a transparent pixel so that there's
|
||||
# no "missing image" region shown, just a space.
|
||||
body = body.replace(/src=['"]cid:[^'"]*['"]/g, "src=\"#{TransparentPixel}\"")
|
||||
body = body.replace(MessageUtils.cidRegex, "src=\"#{TransparentPixel}\"")
|
||||
|
||||
body
|
||||
|
||||
|
|
4
src/flux/models/message-utils.coffee
Normal file
4
src/flux/models/message-utils.coffee
Normal file
|
@ -0,0 +1,4 @@
|
|||
module.exports =
|
||||
class MessageUtils
|
||||
@cidRegexString: "src=['\"]cid:([^'\"]*)['\"]"
|
||||
@cidRegex: new RegExp(@cidRegexString, "g")
|
|
@ -11,6 +11,7 @@ DestroyDraftTask = require '../tasks/destroy-draft'
|
|||
|
||||
Thread = require '../models/thread'
|
||||
Message = require '../models/message'
|
||||
MessageUtils = require '../models/message-utils'
|
||||
Actions = require '../actions'
|
||||
|
||||
{subjectWithPrefix} = require '../models/utils'
|
||||
|
@ -162,7 +163,7 @@ DraftStore = Reflux.createStore
|
|||
|
||||
# Waits for the query promises to resolve and then resolve with a hash
|
||||
# of their resolved values. *swoon*
|
||||
Promise.props(queries).then ({thread, message}) ->
|
||||
Promise.props(queries).then ({thread, message}) =>
|
||||
attributes = attributesCallback(thread, message)
|
||||
attributes.subject ?= subjectWithPrefix(thread.subject, 'Re:')
|
||||
attributes.body ?= ""
|
||||
|
@ -187,7 +188,7 @@ DraftStore = Reflux.createStore
|
|||
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
|
||||
#{attribution}
|
||||
<br>
|
||||
#{msg.body}
|
||||
#{@_formatBodyForQuoting(msg.body)}
|
||||
</blockquote>"""
|
||||
delete attributes.quotedMessage
|
||||
|
||||
|
@ -201,6 +202,10 @@ DraftStore = Reflux.createStore
|
|||
fields.push("CC: #{contactStrings(msg.cc)}") if msg.cc.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.body = """
|
||||
<br><br><blockquote class="gmail_quote"
|
||||
|
@ -209,7 +214,7 @@ DraftStore = Reflux.createStore
|
|||
<br><br>
|
||||
#{fields.join('<br>')}
|
||||
<br><br>
|
||||
#{msg.body}
|
||||
#{@_formatBodyForQuoting(msg.body)}
|
||||
</blockquote>"""
|
||||
delete attributes.forwardedMessage
|
||||
|
||||
|
@ -223,6 +228,14 @@ DraftStore = Reflux.createStore
|
|||
|
||||
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
|
||||
# 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
|
||||
|
|
Loading…
Reference in a new issue