mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-18 10:34:50 +08:00
[local-sync] Set threading headers when uploading message to Sent folder
Summary: We weren't, which meant that us sending with multi-send or generic IMAP broke threading. :( Test Plan: manual Reviewers: juan, evan Reviewed By: juan, evan Differential Revision: https://phab.nylas.com/D3718
This commit is contained in:
parent
107fcbf355
commit
944b677d3e
3 changed files with 24 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
|||
const {SendmailClient, Provider, Errors: {APIError}} = require('isomorphic-core')
|
||||
const IMAPHelpers = require('../imap-helpers')
|
||||
const SyncbackTask = require('./syncback-task')
|
||||
const {getReplyHeaders} = require('../../shared/message-factory')
|
||||
|
||||
/**
|
||||
* Ensures that sent messages show up in the sent folder.
|
||||
|
@ -24,7 +25,7 @@ class EnsureMessageInSentFolderIMAP extends SyncbackTask {
|
|||
}
|
||||
|
||||
async run(db, imap) {
|
||||
const {Message} = db
|
||||
const {Message, Reference} = db
|
||||
const {messageId, sentPerRecipient} = this.syncbackRequestObject().props
|
||||
const {account, logger} = imap
|
||||
if (!account) {
|
||||
|
@ -38,6 +39,20 @@ class EnsureMessageInSentFolderIMAP extends SyncbackTask {
|
|||
throw new APIError(`Couldn't find message ${messageId} to stuff in sent folder`, 500)
|
||||
}
|
||||
|
||||
// Since we store References in a separate table for indexing and don't
|
||||
// create these objects until the sent message is picked up via the
|
||||
// account's sync (since that's when we create the Thread object and the
|
||||
// references must be linked to the thread), we have to reconstruct the
|
||||
// threading headers here before saving the message to the Sent folder.
|
||||
const replyToMessage = await Message.findById(
|
||||
baseMessage.inReplyToLocalMessageId,
|
||||
{ include: [{model: Reference, as: 'references', attributes: ['id', 'rfc2822MessageId']}] });
|
||||
if (replyToMessage) {
|
||||
const {inReplyTo, references} = getReplyHeaders(replyToMessage);
|
||||
baseMessage.inReplyTo = inReplyTo;
|
||||
baseMessage.references = references;
|
||||
}
|
||||
|
||||
const {provider} = account
|
||||
const {headerMessageId} = baseMessage
|
||||
|
||||
|
|
|
@ -45,6 +45,9 @@ module.exports = (sequelize, Sequelize) => {
|
|||
}),
|
||||
folderImapUID: { type: Sequelize.STRING, allowNull: true},
|
||||
folderImapXGMLabels: { type: Sequelize.TEXT, allowNull: true},
|
||||
// Only used for reconstructing In-Reply-To/References when
|
||||
// placing newly sent messages in sent folder for generic IMAP/multi-send
|
||||
inReplyToLocalMessageId: { type: Sequelize.STRING(65), allowNull: true },
|
||||
// an array of IDs to Reference objects, specifying which order they
|
||||
// appeared on the original message (so we don't muck up the order when
|
||||
// sending replies, which could break other mail clients)
|
||||
|
|
|
@ -341,7 +341,9 @@ async function buildForSend(db, json) {
|
|||
|
||||
let thread;
|
||||
let replyHeaders = {};
|
||||
let inReplyToLocalMessageId;
|
||||
if (replyToMessage) {
|
||||
inReplyToLocalMessageId = replyToMessage.id;
|
||||
replyHeaders = getReplyHeaders(replyToMessage);
|
||||
thread = await replyToMessage.getThread();
|
||||
} else if (replyToThread) {
|
||||
|
@ -349,6 +351,7 @@ async function buildForSend(db, json) {
|
|||
const previousMessages = thread.messages.filter(msg => !msg.isDraft);
|
||||
if (previousMessages.length > 0) {
|
||||
const lastMessage = previousMessages[previousMessages.length - 1]
|
||||
inReplyToLocalMessageId = lastMessage.id;
|
||||
replyHeaders = getReplyHeaders(lastMessage);
|
||||
}
|
||||
}
|
||||
|
@ -371,6 +374,7 @@ async function buildForSend(db, json) {
|
|||
isSent: false,
|
||||
version: 0,
|
||||
date: date,
|
||||
inReplyToLocalMessageId: inReplyToLocalMessageId,
|
||||
uploads: json.uploads,
|
||||
}
|
||||
// We have to clone the message and change the date for hashing because the
|
||||
|
@ -392,6 +396,7 @@ async function buildForSend(db, json) {
|
|||
|
||||
module.exports = {
|
||||
buildForSend,
|
||||
getReplyHeaders,
|
||||
parseFromImap,
|
||||
parseSnippet,
|
||||
parseContacts,
|
||||
|
|
Loading…
Add table
Reference in a new issue