mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-01 10:33:14 +08:00
[client-sync] Refactor raw message IMAP connection pool use
Summary: In preparation for removing timeout handling from IMAPConnectionPool. Test Plan: Run locally Reviewers: juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D4168
This commit is contained in:
parent
acd3bf5954
commit
19528ca78a
1 changed files with 27 additions and 21 deletions
|
@ -141,31 +141,37 @@ module.exports = (sequelize, Sequelize) => {
|
|||
const folder = await this.getFolder();
|
||||
let numTimeoutErrors = 0;
|
||||
let result = null;
|
||||
|
||||
const onConnected = async ([connection]) => {
|
||||
const imapBox = await connection.openBox(folder.name);
|
||||
const message = await imapBox.fetchMessage(this.folderImapUID);
|
||||
if (!message) {
|
||||
throw new Error(`Unable to fetch raw message for Message ${this.id}`);
|
||||
}
|
||||
// TODO: this can mangle the raw body of the email because it
|
||||
// does not respect the charset specified in the headers, which
|
||||
// MUST be decoded before you can figure out how to interpret the
|
||||
// body MIME bytes
|
||||
result = `${message.headers}${message.parts.TEXT}`;
|
||||
};
|
||||
|
||||
const onTimeout = (socketTimeout) => {
|
||||
numTimeoutErrors += 1;
|
||||
Actions.recordUserEvent('Timeout error downloading raw message', {
|
||||
accountId: account.id,
|
||||
provider: account.provider,
|
||||
socketTimeout,
|
||||
numTimeoutErrors,
|
||||
});
|
||||
};
|
||||
|
||||
await IMAPConnectionPool.withConnectionsForAccount(account, {
|
||||
desiredCount: 1,
|
||||
logger,
|
||||
onConnected: async ([connection]) => {
|
||||
const imapBox = await connection.openBox(folder.name);
|
||||
const message = await imapBox.fetchMessage(this.folderImapUID);
|
||||
if (!message) {
|
||||
throw new Error(`Unable to fetch raw message for Message ${this.id}`);
|
||||
}
|
||||
// TODO: this can mangle the raw body of the email because it
|
||||
// does not respect the charset specified in the headers, which
|
||||
// MUST be decoded before you can figure out how to interpret the
|
||||
// body MIME bytes
|
||||
result = `${message.headers}${message.parts.TEXT}`;
|
||||
},
|
||||
onTimeout: (socketTimeout) => {
|
||||
numTimeoutErrors += 1;
|
||||
Actions.recordUserEvent('Timeout error downloading raw message', {
|
||||
accountId: account.id,
|
||||
provider: account.provider,
|
||||
socketTimeout,
|
||||
numTimeoutErrors,
|
||||
});
|
||||
},
|
||||
onConnected,
|
||||
onTimeout,
|
||||
});
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue