Refactor Outlook search filters for Jet and DASL

Updated search methods to use appropriate Jet or DASL filters for sender and recipient queries, improving reliability and compatibility. Sender email equality now uses DASL display-from matching, and legacy filter names are preserved for compatibility.
This commit is contained in:
Namhyeon, Go 2026-01-18 14:56:50 +09:00
parent 8f02a5f07c
commit 0cd8d5ec96

View File

@ -283,13 +283,13 @@ function Outlook() {
};
this.find = function (filter) {
console.log(filter);
var item = this.items.Find(filter);
if (!item) return null;
return new Outlook.MailItem(item);
};
this.restrict = function (filter) {
// Accept both Jet filter and DASL filter (@SQL=...)
console.log(filter);
var restricted = this.items.Restrict(filter);
return new Outlook.Items(restricted);
@ -305,7 +305,8 @@ function Outlook() {
// -----------------------------
this.searchBySenderContains = function (keyword) {
return this.restrict(Outlook.Search.filters.senderContains(keyword));
// Jet filter: use [From] / [SenderName] (NOT SenderEmailAddress)
return this.restrict(Outlook.Search.filters.senderContains_Jet(keyword));
};
this.searchByRecipientContains = function (keyword) {
@ -314,10 +315,8 @@ function Outlook() {
};
this.searchBySenderOrRecipientContains = function (keyword) {
// IMPORTANT: cannot mix Jet and DASL in a single Restrict filter
// We run two Restrict calls and then merge the candidates in JS.
var bySender = this.restrict(Outlook.Search.filters.senderContains_Jet(keyword));
// Use DASL for sender and recipients to avoid Jet field incompatibilities
var bySender = this.restrict(Outlook.Search.filters.senderContains_DASL(keyword));
var byRecipients = this.restrict(Outlook.Search.filters.recipientContains_DASL(keyword));
var merged = new Outlook.ItemsMerged(bySender, byRecipients);
@ -328,6 +327,7 @@ function Outlook() {
};
this.searchBySenderEmailEquals = function (email) {
// SenderEmailAddress equality is unreliable in Jet; use DASL from-display match
return this.restrict(Outlook.Search.filters.senderEmailEquals(email));
};
@ -576,23 +576,26 @@ Outlook.Search.filters._escapeDASL = function (s) {
return (s + "").replace(/'/g, "''");
};
// Jet
Outlook.Search.filters.subjectContains = function (keyword) {
var k = Outlook.Search.filters._escape(keyword);
return "([Subject] Like '*" + k + "*')";
};
// Jet (use [From]/[SenderName], NOT SenderEmailAddress)
Outlook.Search.filters.senderContains = function (keyword) {
var k = Outlook.Search.filters._escape(keyword);
return "([SenderEmailAddress] Like '*" + k + "*') OR ([SenderName] Like '*" + k + "*')";
return "([From] Like '*" + k + "*') OR ([SenderName] Like '*" + k + "*')";
};
Outlook.Search.filters.senderEmailEquals = function (email) {
var e = Outlook.Search.filters._escape(email);
return "([SenderEmailAddress] = '" + e + "')";
// DASL sender (display-from)
Outlook.Search.filters.senderContains_DASL = function (keyword) {
var k = Outlook.Search.filters._escapeDASL(keyword);
return '@SQL="urn:schemas:httpmail:from" LIKE \'%' + k + '%\'';
};
// DASL recipient (display-to/cc/bcc)
Outlook.Search.filters.recipientContains = function (keyword) {
// Legacy name kept for compatibility: this returns DASL now
var k = Outlook.Search.filters._escapeDASL(keyword);
return '@SQL=' +
'"urn:schemas:httpmail:displayto" LIKE \'%' + k + '%\' OR ' +
@ -600,6 +603,7 @@ Outlook.Search.filters.recipientContains = function (keyword) {
'"urn:schemas:httpmail:displaybcc" LIKE \'%' + k + '%\'';
};
// Keep compatibility names
Outlook.Search.filters.senderContains_Jet = function (keyword) {
return Outlook.Search.filters.senderContains(keyword);
};
@ -608,6 +612,12 @@ Outlook.Search.filters.recipientContains_DASL = function (keyword) {
return Outlook.Search.filters.recipientContains(keyword);
};
// DASL senderEmailEquals (best-effort; display-based)
Outlook.Search.filters.senderEmailEquals = function (email) {
var e = Outlook.Search.filters._escapeDASL(email);
return '@SQL="urn:schemas:httpmail:from" LIKE \'%' + e + '%\'';
};
Outlook.Search.filters.receivedSince = function (dateObj) {
return "([ReceivedTime] >= '" + dateObj + "')";
};