diff --git a/packages/nylas-api/app.js b/packages/nylas-api/app.js index 01b8f0add..4b66b2764 100644 --- a/packages/nylas-api/app.js +++ b/packages/nylas-api/app.js @@ -50,6 +50,10 @@ const validate = (request, username, password, callback) => { return } token.getAccount().then((account) => { + if (!account) { + callback(new Error("Could not find Account referenced by AccountToken"), false, {}); + return; + } SchedulerUtils.notifyAccountIsActive(account.id) callback(null, true, account); }); diff --git a/packages/nylas-core/models/account/message.js b/packages/nylas-core/models/account/message.js index fe354dfdf..4cacb1f5a 100644 --- a/packages/nylas-core/models/account/message.js +++ b/packages/nylas-core/models/account/message.js @@ -22,6 +22,7 @@ module.exports = (sequelize, Sequelize) => { from: JSONARRAYType('from'), cc: JSONARRAYType('cc'), bcc: JSONARRAYType('bcc'), + replyTo: JSONARRAYType('replyTo'), categoryUID: { type: Sequelize.STRING, allowNull: true}, }, { indexes: [ @@ -72,6 +73,11 @@ module.exports = (sequelize, Sequelize) => { body: this.body, subject: this.subject, snippet: this.snippet, + to: this.to, + from: this.from, + cc: this.cc, + bcc: this.bcc, + reply_to: this.replyTo, date: this.date.getTime() / 1000.0, unread: this.unread, starred: this.starred, diff --git a/packages/nylas-core/models/account/thread.js b/packages/nylas-core/models/account/thread.js index 0bf6d3415..71f65b35f 100644 --- a/packages/nylas-core/models/account/thread.js +++ b/packages/nylas-core/models/account/thread.js @@ -15,6 +15,10 @@ module.exports = (sequelize, Sequelize) => { lastMessageSentDate: Sequelize.DATE, participants: JSONARRAYType('participants'), }, { + indexes: [ + { fields: ['subject'] }, + { fields: ['threadId'] }, + ], classMethods: { associate: ({Category, Message, ThreadCategory}) => { Thread.belongsToMany(Category, {through: ThreadCategory}) diff --git a/packages/nylas-message-processor/app.js b/packages/nylas-message-processor/app.js index 64474684e..295328f23 100644 --- a/packages/nylas-message-processor/app.js +++ b/packages/nylas-message-processor/app.js @@ -7,7 +7,7 @@ global.NylasError = NylasError; // List of the attributes of Message that the processor should be allowed to change. // The message may move between folders, get starred, etc. while it's being // processed, and it shouldn't overwrite changes to those fields. -const MessageAttributes = ['body', 'processed', 'to', 'from', 'cc', 'bcc', 'snippet', 'threadId'] +const MessageAttributes = ['body', 'processed', 'to', 'from', 'cc', 'replyTo', 'bcc', 'snippet', 'threadId'] const MessageProcessorVersion = 1; function runPipeline({db, accountId, message}) { diff --git a/packages/nylas-message-processor/processors/parsing.js b/packages/nylas-message-processor/processors/parsing.js index a525c8173..6763437e0 100644 --- a/packages/nylas-message-processor/processors/parsing.js +++ b/packages/nylas-message-processor/processors/parsing.js @@ -27,10 +27,11 @@ function processMessage({message}) { console.log("Received message has no body or snippet.") } - // extract data from the raw headers object - for (const field of ['to', 'from', 'cc', 'bcc']) { - message[field] = extractContacts(message.headers[field]); - } + message.to = extractContacts(message.headers.to); + message.cc = extractContacts(message.headers.cc); + message.bcc = extractContacts(message.headers.bcc); + message.from = extractContacts(message.headers.from); + message.replyTo = extractContacts(message.headers['reply-to']); return Promise.resolve(message); }