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

65
imap.js
View file

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

View file

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