do not COPY if QUOTA is full

This commit is contained in:
Andris Reinman 2020-09-08 10:00:17 +03:00
parent 977c36a0d5
commit c1abce1363
2 changed files with 237 additions and 216 deletions

View file

@ -88,9 +88,9 @@ module.exports = {
TEMP_PASS_WINDOW: 24 * 3600 * 1000,
// mongdb query TTL limits
DB_MAX_TIME_USERS: 1 * 1000,
DB_MAX_TIME_MAILBOXES: 800,
DB_MAX_TIME_MESSAGES: 60 * 1000,
DB_MAX_TIME_USERS: 3 * 1000,
DB_MAX_TIME_MAILBOXES: 3 * 1000,
DB_MAX_TIME_MESSAGES: 2 * 60 * 1000,
// what is the max username part after wildcard
MAX_ALLOWED_WILDCARD_LENGTH: 32,

View file

@ -18,6 +18,25 @@ module.exports = (server, messageHandler) => (mailbox, update, session, callback
update.destination
);
db.users.collection('users').findOne(
{
_id: session.user.id
},
{
maxTimeMS: consts.DB_MAX_TIME_USERS
},
(err, userData) => {
if (err) {
return callback(err);
}
if (!userData) {
return callback(new Error('User not found'));
}
if (userData.quota && userData.storageUsed > userData.quota) {
return callback(false, 'OVERQUOTA');
}
db.database.collection('mailboxes').findOne(
{
_id: mailbox
@ -266,4 +285,6 @@ module.exports = (server, messageHandler) => (mailbox, update, session, callback
);
}
);
}
);
};