mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-08 21:55:54 +08:00
fix(reply/fwd): Fix for quoted text in new messages
This commit is contained in:
parent
0c97de1bff
commit
6c6e1f2466
3 changed files with 45 additions and 26 deletions
|
@ -153,7 +153,7 @@ describe "DraftStore", ->
|
||||||
it "should include quoted text in the new message", ->
|
it "should include quoted text in the new message", ->
|
||||||
@_callNewMessageWithContext {threadId: fakeThread.id}
|
@_callNewMessageWithContext {threadId: fakeThread.id}
|
||||||
, (thread, message) ->
|
, (thread, message) ->
|
||||||
quotedMessage: fakeMessage1
|
replyToMessage: fakeMessage1
|
||||||
, (model) ->
|
, (model) ->
|
||||||
expect(model.body.indexOf('gmail_quote') > 0).toBe(true)
|
expect(model.body.indexOf('gmail_quote') > 0).toBe(true)
|
||||||
expect(model.body.indexOf('Fake Message 1') > 0).toBe(true)
|
expect(model.body.indexOf('Fake Message 1') > 0).toBe(true)
|
||||||
|
@ -161,14 +161,14 @@ describe "DraftStore", ->
|
||||||
it "should include the `On ... wrote:` line", ->
|
it "should include the `On ... wrote:` line", ->
|
||||||
@_callNewMessageWithContext {threadId: fakeThread.id}
|
@_callNewMessageWithContext {threadId: fakeThread.id}
|
||||||
, (thread, message) ->
|
, (thread, message) ->
|
||||||
quotedMessage: fakeMessage1
|
replyToMessage: fakeMessage1
|
||||||
, (model) ->
|
, (model) ->
|
||||||
expect(model.body.indexOf('On Jan 17 1970, at 1:16 am, Customer <customer@example.com> wrote') > 0).toBe(true)
|
expect(model.body.indexOf('On Jan 17 1970, at 1:16 am, Customer <customer@example.com> wrote') > 0).toBe(true)
|
||||||
|
|
||||||
it "should only include the sender's name if it was available", ->
|
it "should only include the sender's name if it was available", ->
|
||||||
@_callNewMessageWithContext {threadId: fakeThread.id}
|
@_callNewMessageWithContext {threadId: fakeThread.id}
|
||||||
, (thread, message) ->
|
, (thread, message) ->
|
||||||
quotedMessage: fakeMessage2
|
replyToMessage: fakeMessage2
|
||||||
, (model) ->
|
, (model) ->
|
||||||
expect(model.body.indexOf('On Jan 17 1970, at 1:16 am, ben@nilas.com wrote:') > 0).toBe(true)
|
expect(model.body.indexOf('On Jan 17 1970, at 1:16 am, ben@nilas.com wrote:') > 0).toBe(true)
|
||||||
|
|
||||||
|
|
|
@ -21,12 +21,6 @@ class Contact extends Model
|
||||||
json['name'] ||= json['email']
|
json['name'] ||= json['email']
|
||||||
json
|
json
|
||||||
|
|
||||||
displayFullContact: ->
|
|
||||||
if @name and @name isnt @email
|
|
||||||
return "#{@name} <#{@email}>"
|
|
||||||
else
|
|
||||||
return @email
|
|
||||||
|
|
||||||
displayName: ->
|
displayName: ->
|
||||||
return "You" if @email == NamespaceStore.current().emailAddress
|
return "You" if @email == NamespaceStore.current().emailAddress
|
||||||
@_nameParts().join(' ')
|
@_nameParts().join(' ')
|
||||||
|
|
|
@ -96,8 +96,7 @@ DraftStore = Reflux.createStore
|
||||||
|
|
||||||
_onComposeReply: (context) ->
|
_onComposeReply: (context) ->
|
||||||
@_newMessageWithContext context, (thread, message) ->
|
@_newMessageWithContext context, (thread, message) ->
|
||||||
replyToMessageId: message.id
|
replyToMessage: message
|
||||||
quotedMessage: message
|
|
||||||
to: message.from
|
to: message.from
|
||||||
|
|
||||||
_onComposeReplyAll: (context) ->
|
_onComposeReplyAll: (context) ->
|
||||||
|
@ -105,8 +104,7 @@ DraftStore = Reflux.createStore
|
||||||
excluded = message.from.map (c) -> c.email
|
excluded = message.from.map (c) -> c.email
|
||||||
excluded.push(NamespaceStore.current().me().email)
|
excluded.push(NamespaceStore.current().me().email)
|
||||||
|
|
||||||
replyToMessageId: message.id
|
replyToMessage: message
|
||||||
quotedMessage: message
|
|
||||||
to: message.from
|
to: message.from
|
||||||
cc: [].concat(message.cc, message.to).filter (p) ->
|
cc: [].concat(message.cc, message.to).filter (p) ->
|
||||||
!_.contains(excluded, p.email)
|
!_.contains(excluded, p.email)
|
||||||
|
@ -114,7 +112,7 @@ DraftStore = Reflux.createStore
|
||||||
_onComposeForward: (context) ->
|
_onComposeForward: (context) ->
|
||||||
@_newMessageWithContext context, (thread, message) ->
|
@_newMessageWithContext context, (thread, message) ->
|
||||||
subject: "Fwd: " + thread.subject
|
subject: "Fwd: " + thread.subject
|
||||||
quotedMessage: message
|
forwardMessage: message
|
||||||
|
|
||||||
_newMessageWithContext: ({threadId, messageId}, attributesCallback) ->
|
_newMessageWithContext: ({threadId, messageId}, attributesCallback) ->
|
||||||
queries = {}
|
queries = {}
|
||||||
|
@ -130,24 +128,51 @@ DraftStore = Reflux.createStore
|
||||||
attributes = attributesCallback(thread, message)
|
attributes = attributesCallback(thread, message)
|
||||||
attributes.subject ?= thread.subject
|
attributes.subject ?= thread.subject
|
||||||
|
|
||||||
if attributes.quotedMessage
|
# A few helpers for formatting
|
||||||
contact = attributes.quotedMessage.from[0] ? new Contact(name: 'Unknown', email:'Unknown')
|
contactString = (c) ->
|
||||||
quoteDate = moment(attributes.quotedMessage.date).format("MMM D YYYY, [at] h:mm a")
|
if c.name then "#{c.name} <#{c.email}>" else c.email
|
||||||
|
contactStrings = (cs) ->
|
||||||
|
_.map(cs, contactString).join(", ")
|
||||||
|
messageDate = (d) ->
|
||||||
|
moment(d).format("MMM D YYYY, [at] h:mm a")
|
||||||
|
|
||||||
if contact.name
|
if attributes.replyToMessage
|
||||||
quoteAttribution = "On #{quoteDate}, #{contact.name} <#{contact.email}> wrote:"
|
msg = attributes.replyToMessage
|
||||||
else
|
contact = msg.from[0] ? new Contact(name: 'Unknown', email:'Unknown')
|
||||||
quoteAttribution = "On #{quoteDate}, #{contact.email} wrote:"
|
attribution = "On #{messageDate(msg.date)}, #{contactString(contact)} wrote:"
|
||||||
|
|
||||||
|
attributes.replyToMessageId = msg.id
|
||||||
|
attributes.body = """
|
||||||
|
<br><br>
|
||||||
|
<blockquote class="gmail_quote"
|
||||||
|
style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
|
||||||
|
#{attribution}
|
||||||
|
<br>
|
||||||
|
#{msg.body}
|
||||||
|
</blockquote>"""
|
||||||
|
delete attributes.quotedMessage
|
||||||
|
|
||||||
|
if attributes.forwardMessage
|
||||||
|
msg = attributes.forwardMessage
|
||||||
|
fields = []
|
||||||
|
fields.push("From: #{contactStrings(msg.from)}") if msg.from.length > 0
|
||||||
|
fields.push("Subject: #{msg.subject}")
|
||||||
|
fields.push("Date: #{messageDate(msg.date)}")
|
||||||
|
fields.push("To: #{contactStrings(msg.to)}") if msg.to.length > 0
|
||||||
|
fields.push("CC: #{contactStrings(msg.cc)}") if msg.cc.length > 0
|
||||||
|
fields.push("BCC: #{contactStrings(msg.bcc)}") if msg.bcc.length > 0
|
||||||
|
|
||||||
attributes.body = """
|
attributes.body = """
|
||||||
<br><br>
|
<br><br>
|
||||||
<blockquote class="gmail_quote"
|
<blockquote class="gmail_quote"
|
||||||
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;">
|
||||||
#{quoteAttribution}
|
Begin forwarded message:
|
||||||
<br>
|
<br><br>
|
||||||
#{attributes.quotedMessage.body}
|
#{fields.join('<br>')}
|
||||||
|
<br><br>
|
||||||
|
#{msg.body}
|
||||||
</blockquote>"""
|
</blockquote>"""
|
||||||
delete attributes.quotedMessage
|
delete attributes.forwardedMessage
|
||||||
|
|
||||||
draft = new Message _.extend {}, attributes,
|
draft = new Message _.extend {}, attributes,
|
||||||
from: [NamespaceStore.current().me()]
|
from: [NamespaceStore.current().me()]
|
||||||
|
|
Loading…
Add table
Reference in a new issue