After authing an account, close IMAP connection

This commit is contained in:
Ben Gotow 2016-07-13 16:42:13 -07:00
parent 87905d0145
commit 35c32a3645
2 changed files with 14 additions and 8 deletions

View file

@ -148,7 +148,10 @@ module.exports = (server) => {
db: dbStub,
}));
Promise.all(connectionChecks).then(() => {
Promise.all(connectionChecks).then((conns) => {
for (const conn of conns) {
if (conn) { conn.end(); }
}
return buildAccountWith({
name: name,
email: email,
@ -234,15 +237,18 @@ module.exports = (server) => {
db: {},
}),
])
.then(() =>
buildAccountWith({
.then((conns) => {
for (const conn of conns) {
if (conn) { conn.end(); }
}
return buildAccountWith({
name: profile.name,
email: profile.email,
provider: Provider.Gmail,
settings,
credentials,
})
)
})
.then(({account, token}) => {
const response = account.toJSON();
response.token = token.value;

View file

@ -46,9 +46,9 @@ class IMAPConnection extends EventEmitter {
connect() {
if (!this._connectPromise) {
this._connectPromise = this._resolveIMAPSettings().then((settings) =>
this._buildUnderlyingConnection(settings)
);
this._connectPromise = this._resolveIMAPSettings()
.then((settings) => this._buildUnderlyingConnection(settings))
.thenReturn(this);
}
return this._connectPromise;
}
@ -107,7 +107,7 @@ class IMAPConnection extends EventEmitter {
this._imap.on('update', () => this.emit('update'))
this._imap.once('ready', () => {
resolve(this)
resolve()
});
this._imap.once('error', (err) => {