mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-07 16:38:17 +08:00
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const db = require('../db');
|
|
|
|
// STATUS (X Y X)
|
|
module.exports = server => (path, session, callback) => {
|
|
server.logger.debug(
|
|
{
|
|
tnx: 'status',
|
|
cid: session.id
|
|
},
|
|
'[%s] Requested status for "%s"',
|
|
session.id,
|
|
path
|
|
);
|
|
db.database.collection('mailboxes').findOne({
|
|
user: session.user.id,
|
|
path
|
|
}, (err, mailbox) => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
if (!mailbox) {
|
|
return callback(null, 'NONEXISTENT');
|
|
}
|
|
|
|
db.database
|
|
.collection('messages')
|
|
.find({
|
|
mailbox: mailbox._id
|
|
})
|
|
.count((err, total) => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
db.database
|
|
.collection('messages')
|
|
.find({
|
|
mailbox: mailbox._id,
|
|
seen: false
|
|
})
|
|
.count((err, unseen) => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
|
|
return callback(null, {
|
|
messages: total,
|
|
uidNext: mailbox.uidNext,
|
|
uidValidity: mailbox.uidValidity,
|
|
unseen
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|