Search code examples
delphiimapdelphi-xe2

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


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


Solution

  • 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;