[local-sync] Add support for inline-images

Summary:
Extract files for inline attachments and store their content id

Fixes T7414

Test Plan: tested locally

Reviewers: evan, spang

Reviewed By: spang

Maniphest Tasks: T7414

Differential Revision: https://phab.nylas.com/D3609
This commit is contained in:
Halla Moore 2017-01-09 10:44:31 -08:00
parent 2c0fd79707
commit 1ba4a6eaf2
2 changed files with 15 additions and 2 deletions

View file

@ -7,12 +7,22 @@ function collectFilesFromStruct({db, message, struct, fileIds = new Set()}) {
collected = collected.concat(collectFilesFromStruct({db, message, struct: part, fileIds}));
} else {
const disposition = part.disposition || {}
const isAttachment = /attachment/gi.test(disposition.type);
const filename = (disposition.params || {}).filename;
// Note that the contentId is stored in part.id, while the MIME part id
// is stored in part.partID
const match = /^<(.*)>$/.exec(part.id) // extract id from <id>
const contentId = match ? match[1] : part.id;
// Check if the part is an attachment. If it's inline, we also need
// to ensure that there is a filename and contentId because some clients
// use "inline" for text in the body.
const isAttachment = /(attachment)/gi.test(disposition.type) ||
(/(inline)/gi.test(disposition.type) && filename && contentId);
if (!isAttachment) continue
const partId = part.partID
const filename = (disposition.params || {}).filename;
const fileId = `${message.id}-${partId}-${part.size}`
if (!fileIds.has(fileId)) {
collected.push(File.build({
@ -24,6 +34,7 @@ function collectFilesFromStruct({db, message, struct, fileIds = new Set()}) {
messageId: message.id,
accountId: message.accountId,
contentType: `${part.type}/${part.subtype}`,
contentId,
}));
fileIds.add(fileId)
}

View file

@ -12,6 +12,7 @@ module.exports = (sequelize, Sequelize) => {
messageId: { type: Sequelize.STRING, allowNull: false },
accountId: { type: Sequelize.STRING, allowNull: false },
contentType: Sequelize.STRING(500),
contentId: Sequelize.STRING(500),
}, {
indexes: [
{fields: ['messageId']},
@ -54,6 +55,7 @@ module.exports = (sequelize, Sequelize) => {
message_id: this.messageId,
account_id: this.accountId,
content_type: this.contentType,
content_id: this.contentId,
};
},
},