Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching two string at a time in the Object of emails
#2
(01-07-2022, 06:22 PM)luigisic Wrote: Can i search both strings at a time?

When you specify multiple criteria to the IMAP SEARCH command, it returns the intersection (AND) of all matching criteria. Per RFC 3501 Section 6.4.4:

Quote:When multiple keys are specified, the result is the intersection (AND function) of all the messages that match those keys. For example, the criteria DELETED FROM "SMITH" SINCE 1-Feb-1994 refers to all deleted messages from Smith that were placed in the mailbox since February 1, 1994. A search key can also be a parenthesized list of one or more search keys (e.g., for use with the OR and NOT keys).

So, in your example, you are searching for emails that:
  • are marked as Unseen
  • AND whose subject contains 'ACC: '
  • AND whose subject contains 'CON: '

Which I suspect is probably not what you want. You probably want something more like this instead:
  • are marked as Unseen
  • AND whose subject contains EITHER 'ACC: ' OR 'CON: '

The SEARCH command has an OR <search-key1> <search-key2> search-key for that very purpose, so try this:

Code:
SetLength(SearchInfoArray, 4);
SearchInfo.Date := 0;
SearchInfo.Size := 0;
SearchInfo.Text := '';

SearchInfo.SearchKey := skUnseen;
SearchInfoArray[0] := SearchInfo;

SearchInfo.SearchKey := skOr;
SearchInfoArray[1] := SearchInfo;

SearchInfo.SearchKey := skSubject;
SearchInfo.Text := 'ACC: ';
SearchInfoArray[2] := SearchInfo;

SearchInfo.SearchKey := skSubject;
SearchInfo.Text := 'CON: ';
SearchInfoArray[3] := SearchInfo;

if IMAP.SearchMailBox(SearchInfoArray) then

Reply


Messages In This Thread
RE: Searching two string at a time in the Object of emails - by rlebeau - 01-07-2022, 07:11 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)