Reputation: 20105
RFC 3501 states in section 6.1.2. that you should use the NOOP
command for polling.
Though in TIdIMAP4
there's only the KeepAlive
method using it, which is implemented as a procedure, i.e. doesn't return anything.
So how to check for status updates like e.g. new messages or read status changes? I.e. how can I do manual polling with TIdIMAP4
? Which methods and properties are involved in doing that? And how to get the (U)IDs these messages?
Or is it even possible to use the IDLE
command specified in RFC 2177 to avoid polling and to get updates automatically?
Upvotes: 2
Views: 1030
Reputation: 596352
IMAP is technically an asynchronous protocol, but TIdIMAP4
is currently implemented as a synchronous client. As such, unexpected/out-of-order data is either discarded, treated as untagged data, or treated as error data, depending on timing and context. Untagged/extra data is accessible from the TIdIMAP4.LastCmdResult
property, which you can type-cast to TIdReplyIMAP4
to access its Extra
sub-property.
IDLE
is not currently supported in TIdIMAP4
. There are tickets in Indy's issue trackers (see here and here) to add IDLE
support in a future release, maybe in Indy 11. Until then, you will have to poll the mailbox envelopes periodically, keeping track of messages you have already seen so you can detect new messages.
Upvotes: 3
Reputation: 9685
Yes, you can use IDLE
to avoid NOOP
and in general it's a good idea.
However, that won't give you any results. In a way, IMAP commands don't have results. They tell the server what you want, and the server tells you things. The server is free to tell you things for other reasons as well, including the goodness of its heart.
You might say that NOOP
means "hi server, now is a good time to tell me things, I'm listening" and IDLE
means "hi server, I'm listening all the time, so just tell me whatever you want whenever you want". Both also mean "and btw, restart your inactivity timeout if you have one".
The server will send you EXISTS
, FETCH
and other responses, which I expect TIdIMAP4 forwards to you in some way. (Yes, they're called responses even though they're not in response to any command of yours. They may be sent in response to someone else having sent you mail, for instance. Stupid naming.)
Upvotes: 2