From 1c08896f2d9e96ac730bcb5967f27f529099c884 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 24 Jun 2016 12:21:29 -0500 Subject: [PATCH] debug the reason why the message did not match --- imap-probe.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/imap-probe.js b/imap-probe.js index a34a31a..276f85a 100644 --- a/imap-probe.js +++ b/imap-probe.js @@ -129,14 +129,27 @@ function searchMessage(message, needle) { assert.strictEqual(typeof message, 'object'); assert.strictEqual(typeof needle, 'object'); - debug('searchMessage : %s %s %s %s', message.seqno, message.from[0], message.to[0], message.subject[0]); + var reason = [ ]; - if (needle.subject && message.subject[0].match(needle.subject) === null) return false; - if (needle.body && message.body.match(needle.body) === null) return false; - if (needle.to && message.to[0].match(needle.to) === null) return false; - if (needle.from && message.from[0].match(needle.from) === null) return false; + if (needle.subject && message.subject[0].match(needle.subject) === null) { + reason.push('subject does not match'); + } - return true; + if (needle.body && message.body.match(needle.body) === null) { + reason.push('body does not match'); + } + + if (needle.to && message.to[0].match(needle.to) === null) { + reason.push('to does not match'); + } + + if (needle.from && message.from[0].match(needle.from) === null) { + reason.push('from does not match'); + } + + debug('searchMessage : %s %s %s %s (%j)', message.seqno, message.from[0], message.to[0], message.subject[0], reason); + + return reason.length === 0; } ImapProbe.prototype._scanBox = function (needle, callback) {