+2 votes

I'm writing an application that needs to map users' names to their email address. It does this by searching an email folder they all send to and finding emails from them - which has their email address and name in the from field. The problem is that some people have sent hundreds of emails to the folder so my VB code:

Dim Query As New SimpleImapQuery
Query.From = NameStr
LimiImapClient.SelectInbox()
Dim MatchingEmails As List(Of Long) = LimiImapClient.Search(Query)

can take a long time to complete while the client pulls down all the emails from the specified user. Is there a way to limit the number it returns? I only ever want one response per user.

by

1 Answer

0 votes

Yes it is possible. To limit IMAP search results just to one element, you should use Expression.UID(Range.Last()) IMAP search criterion and combine it with your IMAP query:

List<long> uids = imap.Search(
    Expression.And(query, Expression.UID(Range.Last())
    ));

VB.NET:

Dim uids As List(Of Long) = imap.Search( _
    Expression.And(Query, Expression.UID(Range.Last())))
by (301k points)
Thanks for the quick reply; I've tried this but I get an error "Last is not a member of Limilabs.Client.Imap.Range"
...