updated SEARCH, fixed partial journal

This commit is contained in:
Andris Reinman 2017-04-12 22:51:13 +03:00
parent fd24c25e32
commit b90856a8d5
2 changed files with 35 additions and 31 deletions

55
imap.js
View file

@ -1202,24 +1202,18 @@ server.onSearch = function (path, options, session, callback) {
// prepare query
let query = {
mailbox: mailbox._id,
$and: []
mailbox: mailbox._id
};
let hasAll = false;
let nothing = false;
let walkQuery = (parent, ne, node) => {
if (hasAll || nothing) {
return;
}
node.forEach(term => {
switch (term.key) {
case 'all':
if (!ne) {
hasAll = true;
query = {
mailbox: mailbox._id
};
if (ne) {
parent.push({
// should not match anything
_id: -1
});
}
break;
@ -1230,14 +1224,17 @@ server.onSearch = function (path, options, session, callback) {
case 'or':
{
let $or = [];
parent.push({
$or
});
[].concat(term.value || []).forEach(entry => {
walkQuery($or, false, [].concat(entry || []));
});
if ($or.length) {
parent.push({
$or
});
}
break;
}
@ -1252,7 +1249,10 @@ server.onSearch = function (path, options, session, callback) {
});
} else {
// can not search by text
nothing = true;
parent.push({
// should not match anything
_id: -1
});
}
break;
@ -1273,11 +1273,19 @@ server.onSearch = function (path, options, session, callback) {
highestModseq: 0
});
}
if (term.value.length !== session.selected.uidList.length) {
// not 1:*
parent.push({
uid: {
[!ne ? '$in' : '$nin']: term.value
}
});
} else if (ne) {
parent.push({
// should not match anything
_id: -1
});
}
} else {
parent.push({
uid: {
@ -1457,19 +1465,14 @@ server.onSearch = function (path, options, session, callback) {
});
};
walkQuery(query.$and, false, options.query);
//}
let $and = [];
walkQuery($and, false, options.query);
if ($and.length) {
query.$and = $and;
}
this.logger.info('SEARCH %s', JSON.stringify(query));
if (nothing) {
// reject immediatelly
return callback(null, {
uidList: [],
highestModseq: 0
});
}
let cursor = db.database.collection('messages').
find(query).
project({

View file

@ -204,6 +204,7 @@ class ImapNotifier extends EventEmitter {
entries.forEach(entry => {
entry.modseq = entry.modseq || modseq;
entry.created = entry.created || created;
entry.mailbox = entry.mailbox || mailbox._id;
});
if (updated.length) {