MBOX-Line: From mrc+imap at panda.com  Thu Apr 14 19:04:28 2011
To: imap-protocol@u.washington.edu
From: Mark Crispin <mrc+imap@panda.com>
Date: Fri Jun  8 12:34:45 2018
Subject: [Imap-protocol] cancel or limit results from imap search
In-Reply-To: <BANLkTi=JPaPQnuNtFWrwT+GUuuX0gC-wfg@mail.gmail.com>
References: <BANLkTi=JPaPQnuNtFWrwT+GUuuX0gC-wfg@mail.gmail.com>
Message-ID: <alpine.OSX.2.00.1104141840530.797@hsinghsing.panda.com>

On Thu, 14 Apr 2011, Brendan Miller wrote:
> Is there a way in the imap protocol to limit the number of results
> from a search command?

You can compose your search criteria to limit the range of messages that
are searched by either message sequence number or UID, and by doing so put
a cap on the number of messages returned.

There is an extension that returns "first n results"; but that extension
is not widely implemented.

> Would the only way to do this be to disconnect
> the tcp stream after having received the number of results you want?

Since search results come back in a single response, it is pointless to do
that.

> As a follow up question, in the c-client, is there a means of safely
> disconnecting a mailstream in the mm_searched callback? The
> documentation seemed to indicate that calling back into the c-client,
> say to do a mail_close, is not safe within mm_* callbacks.

The simple answer is "no".

IMAP is not HTTP.  IMAP is a stateful protocol.  Disconnecting is
antihetical to state architectures.

Please use IMAP properly.  The market is saturated with poorly designed
and poor performing IMAP client implementations.  Don't add to them.

If you enjoy banging your head against a wall repeatedly in frustration
as your application never works work a damn, then ignore my advice.

-- Mark --

http://panda.com/mrc
Democracy is two wolves and a sheep deciding what to eat for lunch.
Liberty is a well-armed sheep contesting the vote.

