Include unnamed files as attachements and rename to 'Unnamed Attachement'

Summary: Fixes T2024 and renames unnamed files to Unnamed Attachment before appending the attachement component to message list

Test Plan: Added a test to ensure file without filename is renamed to Unnamed Attachment

Reviewers: bengotow

Reviewed By: bengotow

Maniphest Tasks: T2024

Differential Revision: https://phab.nylas.com/D1685
This commit is contained in:
Robert McQueen 2015-06-25 09:51:46 -07:00
parent 13f3669ebf
commit b42d102740
3 changed files with 9 additions and 18 deletions

View file

@ -39,7 +39,7 @@ class AttachmentComponent extends React.Component
fallback="file-fallback.png"
name="file-#{@_extension()}.png"/>
</span>
<span className="attachment-file-name">{@props.file.filename}</span>
<span className="attachment-file-name">{@props.file.filename ? "Unnamed Attachment"}</span>
</span>
</div>

View file

@ -296,12 +296,9 @@ class MessageItem extends React.Component
return otherAttachments.concat(imageAttachments)
# We ignore files with no name because they're actually mime-parts of the
# message being served by the API as files.
_isRealFile: (file) ->
hasName = file.filename and file.filename.length > 0
hasCIDInBody = file.contentId? and @props.message.body?.indexOf(file.contentId) > 0
return hasName and not hasCIDInBody
return not hasCIDInBody
_isForwardedMessage: =>
Utils.isForwardedMessage(@props.message)

View file

@ -53,11 +53,10 @@ file_cid_but_not_referenced_or_image = new File
contentId: 'file_cid_but_not_referenced_or_image'
contentType: 'text/plain'
size: 300
file_actually_a_mime_part = new File
id: 'file_actually_a_mime_part'
contentId: 'file_actually_a_mime_part'
contentType: 'text/html'
size: 300
file_without_filename = new File
id: 'file_without_filename'
contentType: 'image/png'
size: 10
download =
fileId: 'file_1_id'
@ -178,7 +177,7 @@ describe "MessageItem", ->
file_inline,
file_inline_downloading,
file_inline_not_downloaded,
file_actually_a_mime_part
file_without_filename
]
@message.body = """
<img alt=\"A\" src=\"cid:#{file_inline.contentId}\"/>
@ -198,17 +197,12 @@ describe "MessageItem", ->
it "should list attachments that are not mentioned in the body via cid", ->
attachments = ReactTestUtils.scryRenderedComponentsWithTypeAndProps(@component, InjectedComponent, matching: {role: 'Attachment'})
expect(attachments.length).toEqual(4)
expect(attachments.length).toEqual(5)
expect(attachments[0].props.exposedProps.file).toBe(file)
expect(attachments[1].props.exposedProps.file).toBe(file_not_downloaded)
expect(attachments[2].props.exposedProps.file).toBe(file_cid_but_not_referenced)
expect(attachments[3].props.exposedProps.file).toBe(file_cid_but_not_referenced_or_image)
it "should list attachments without a filename", ->
attachments = ReactTestUtils.scryRenderedComponentsWithTypeAndProps(@component, InjectedComponent, matching: {role: 'Attachment'})
for attachment in attachments
expect(attachment.props.exposedProps.file).not.toBe(file_actually_a_mime_part)
it "should provide file download state to each InjectedComponent", ->
attachments = ReactTestUtils.scryRenderedComponentsWithTypeAndProps(@component, InjectedComponent, matching: {role: 'Attachment'})
expect(attachments[0].props.exposedProps.download).toBe(download)
@ -218,7 +212,7 @@ describe "MessageItem", ->
@message.body = ""
@createComponent()
attachments = ReactTestUtils.scryRenderedComponentsWithTypeAndProps(@component, InjectedComponent, matching: {role: 'Attachment'})
expect(attachments.length).toEqual(7)
expect(attachments.length).toEqual(8)
describe "inline", ->
it "should never leave src=cid:// in the message body", ->