Skip to content

Commit

Permalink
fixed #51 #52
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jan 5, 2018
1 parent ba35a2f commit 06ad073
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 28 deletions.
18 changes: 9 additions & 9 deletions lib/api/addresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ module.exports = (db, server) => {
let pageNext = result.value.next;
let pagePrevious = result.value.previous;

let filter = query
? {
address: {
// cannot use dotless version as this would break domain search
$regex: query.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'),
$options: ''
}
}
: {};
let filter =
(query && {
address: {
// cannot use dotless version as this would break domain search
$regex: query.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'),
$options: ''
}
}) ||
{};

db.users.collection('addresses').count(filter, (err, total) => {
if (err) {
Expand Down
26 changes: 13 additions & 13 deletions lib/filter-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,13 @@ class FilterHandler {
sender,
recipient,

targets: forwardTargets.size
? Array.from(forwardTargets).map(row => ({
type: row[1].type,
value: row[1].value
}))
: false,
targets:
(forwardTargets.size &&
Array.from(forwardTargets).map(row => ({
type: row[1].type,
value: row[1].value
}))) ||
false,

chunks,
chunklen
Expand Down Expand Up @@ -570,13 +571,12 @@ class FilterHandler {
response: err ? err : 'Message stored as ' + info.id.toString(),
error: err
},
!isEncrypted
? {
// reuse parsed values
mimeTree: messageOpts.prepared.mimeTree,
maildata: messageOpts.maildata
}
: false
(!isEncrypted && {
// reuse parsed values
mimeTree: messageOpts.prepared.mimeTree,
maildata: messageOpts.maildata
}) ||
false
);
});
});
Expand Down
28 changes: 22 additions & 6 deletions lib/message-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ class MessageHandler {
// no need to load extra data when we only need to know the basics
queryOpts.fields = {
_id: true,
uid: true
uid: true,
outbound: true,
mailbox: true
};
}

Expand Down Expand Up @@ -535,7 +537,7 @@ class MessageHandler {

messageData._id = messageOpts.id;
messageData.uid = newUid;
messageOpts.modseq = newModseq;
messageData.modseq = newModseq;
messageData.flags = messageOpts.flags;

this.database.collection('messages').insertOne(messageData, err => {
Expand Down Expand Up @@ -570,7 +572,9 @@ class MessageHandler {
ignore: options.session && options.session.id,
uid: existingUid,
message: existingId,
unseen: messageData.unseen
unseen: messageData.unseen,
// modseq is needed to avoid updating mailbox entry
modseq: newModseq
},
() => {
this.notifier.addEntries(
Expand Down Expand Up @@ -775,9 +779,19 @@ class MessageHandler {
}
},
{
uidNext: true
returnOriginal: false,
projection: {
_id: true,
uidNext: true
}
},
() => {
(err, item) => {
if (err) {
return callback(err);
}

let newModseq = (item && item.value && item.value.modifyIndex) || 1;

let cursor = this.database
.collection('messages')
.find({
Expand Down Expand Up @@ -995,7 +1009,9 @@ class MessageHandler {
ignore: options.session && options.session.id,
uid: messageUid,
message: messageId,
unseen
unseen,
// modseq is needed to avoid updating mailbox entry
modseq: newModseq
});

if (options.showExpunged) {
Expand Down

0 comments on commit 06ad073

Please sign in to comment.