NeahNew/node_modules/imapflow/lib/commands/logout.js
2025-05-03 14:17:46 +02:00

35 lines
914 B
JavaScript

'use strict';
// Logs out user and closes connection
module.exports = async connection => {
if (connection.state === connection.states.LOGOUT) {
// nothing to do here
return false;
}
if (connection.state === connection.states.NOT_AUTHENTICATED) {
connection.state = connection.states.LOGOUT;
connection.close();
return false;
}
let response;
try {
response = await connection.exec('LOGOUT');
return true;
} catch (err) {
if (err.code === 'NoConnection') {
return true;
}
connection.log.warn({ err, cid: connection.id });
return false;
} finally {
// close even if command failed
connection.state = connection.states.LOGOUT;
if (response && typeof response.next === 'function') {
response.next();
}
connection.close();
}
};