diff --git a/lib/msoffice.js b/lib/msoffice.js index ca61fde..46905fe 100644 --- a/lib/msoffice.js +++ b/lib/msoffice.js @@ -522,44 +522,70 @@ Outlook.Search = {}; Outlook.Search.filters = {}; +// Jet: escape for single-quoted literals Outlook.Search.filters._escape = function (s) { return (s + "").replace(/'/g, "''"); }; +// DASL: escape for single-quoted literals (same rule) +Outlook.Search.filters._escapeDASL = function (s) { + return (s + "").replace(/'/g, "''"); +}; + +// 1) Subject contains (Jet, wildcard = *) Outlook.Search.filters.subjectContains = function (keyword) { var k = Outlook.Search.filters._escape(keyword); return "([Subject] Like '*" + k + "*')"; }; +// 2) Sender contains (Jet, wildcard = *) Outlook.Search.filters.senderContains = function (keyword) { var k = Outlook.Search.filters._escape(keyword); return "([SenderEmailAddress] Like '*" + k + "*') OR ([SenderName] Like '*" + k + "*')"; }; +// 3) Sender email equals (Jet) Outlook.Search.filters.senderEmailEquals = function (email) { var e = Outlook.Search.filters._escape(email); return "([SenderEmailAddress] = '" + e + "')"; }; +// 4) Recipient contains (DASL; use @SQL= with % wildcard) Outlook.Search.filters.recipientContains = function (keyword) { - var k = Outlook.Search.filters._escape(keyword); - return "([To] Like '*" + k + "*') OR ([CC] Like '*" + k + "*') OR ([BCC] Like '*" + k + "*')"; + var k = Outlook.Search.filters._escapeDASL(keyword); + + // Note: do NOT wrap property names in [] in DASL. + // Use httpmail display fields for recipient display strings. + return '@SQL=' + + '"urn:schemas:httpmail:displayto" LIKE \'%' + k + '%\' OR ' + + '"urn:schemas:httpmail:displaycc" LIKE \'%' + k + '%\' OR ' + + '"urn:schemas:httpmail:displaybcc" LIKE \'%' + k + '%\''; }; -Outlook.Search.filters.senderOrToCcBccContains = function (keyword) { - var k = Outlook.Search.filters._escape(keyword); - return "(" + - "([SenderEmailAddress] Like '*" + k + "*') OR ([SenderName] Like '*" + k + "*')" + - " OR ([To] Like '*" + k + "*') OR ([CC] Like '*" + k + "*') OR ([BCC] Like '*" + k + "*')" + - ")"; +// 5) Sender OR To/CC/BCC contains +// IMPORTANT: cannot mix Jet and DASL in a single Restrict filter. +// Provide TWO filters: Jet (sender) + DASL (recipients), and let caller intersect/union in script. +Outlook.Search.filters.senderContains_Jet = function (keyword) { + return Outlook.Search.filters.senderContains(keyword); }; +Outlook.Search.filters.recipientContains_DASL = function (keyword) { + return Outlook.Search.filters.recipientContains(keyword); +}; + +// Optional helper: receivedSince in Jet (often OK), but keep separate to avoid mixing with DASL Outlook.Search.filters.receivedSince = function (dateObj) { - // Outlook filter date string is locale-dependent; use Date's default string. - // In WSH/JScript, Date string typically matches system locale and Outlook accepts it. return "([ReceivedTime] >= '" + dateObj + "')"; }; +// Optional helper: receivedSince in DASL (if you want to apply with other DASL filters) +Outlook.Search.filters.receivedSince_DASL = function (dateObj) { + // Use the same date string format you pass elsewhere; Outlook parses locale-dependent strings. + // This uses DAV:date-received. If your environment is picky, keep date restriction in Jet step. + var d = Outlook.Search.filters._escapeDASL(dateObj); + return '@SQL="DAV:date-received" >= \'' + d + '\''; +}; + Outlook.Search.match = {}; Outlook.Search.match._contains = function (hay, needle) {