IP*Works! SearchMailbox for IMAPS returns all available emails, even unmatching

240 Views Asked by At

I am using IP*Works! V9. I try to restrict the returned emails to only the one matching a restriction using SearchMailbox. My code looks like this:

lIMap.Mailbox := 'INBOX';
lIMap.SelectMailbox;
lIMap.CheckMailbox;
lIMap.Config('FETCHAFTERSEARCH=True');
lIMap.SearchMailbox('SUBJECT Diessenhofen UNSEEN');
if (lIMap.MessageCount > 0) then
begin
   ...
end;

MessageCount always reflects the total number of emails instead of one (there is one match in my inbox).

The IMAP server is Kereo

2

There are 2 best solutions below

0
On BEST ANSWER

Thanks to the answer of @arnt, I figured out a solution that works for me.

Yes, for every Message that corresponds to the search criteria, the event OnMessageInfo is fired.

Since I need to go through all messages in a loop, I ended up doing this:

procedure TReadIMapObjectsFavFktProperty.MessageInfo(Sender: TObject;
  const MessageId, Subject, MessageDate, From, Flags: String;
  Size:Int64);
begin
  if (MessageList.IndexOf(MessageId) < 0) then
  begin
    MessageList.Add(MessageId);
  end;
end;

where MessageList is a TStringList with delimiter ',';

I can then get all messages using either

lIMap.MessageSet := MessageList.Text;

again firing the same event or loop through them using the size of the MessageList like this:

for aa := 0 to MessageList.Count - 1 do
begin
  lIMap.MessageSet := MessageList.Strings[aa];
  lIMap.FetchMessageInfo;
  ...
end;
0
On

The documentation says it doesn't work like that. SearchMailbox doesn't restrict what's available to you, instead it calls a user-supplied function and fires an even once for each message in the search result.