andyedinborough / aenetmail

C# POP/IMAP Mail Client
370 stars 153 forks source link

ImapClient.Search does not return new messages #139

Open benfoster opened 11 years ago

benfoster commented 11 years ago

I'm keeping our ImapClient alive and polling periodically for new messages with the following code:

    public IEnumerable<Message> GetMessages()
    {
        foreach (var msgId in client.Search(SearchCondition.Unseen()))
        {
            var msg = client.GetMessage(msgId, headersonly: false, setseen: true);

            foreach (var attachment in msg.Attachments)
            {
                yield return new Message
                {
                    ContentType = attachment.ContentType,
                    Filename = attachment.Filename,
                    Data = attachment.GetData()
                };
            }
        }
    }

I'm finding that any new emails are not returned. Do I need disconnect/reconnect between polling in order to pick new mail/clear the queue?