Dart
Dart
End IMAP IDLE Mode
See more IMAP Examples
Demonstrates the Chilkat Imap.IdleDone method, which ends IDLE mode by sending the protocol's DONE continuation. It takes no arguments. The authenticated connection remains open and usable afterward.
Background: While IDLE is active the connection is dedicated to receiving push notifications, so any command that needs to talk to the server — fetching a message, setting a flag — must wait until IDLE ends.
IdleDone cleanly exits IDLE without dropping the login, so the same connection can immediately be reused. Calling it when IDLE is not active fails.Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// Demonstrates the Imap.IdleDone method, which ends IMAP IDLE mode by sending the DONE
// continuation. It takes no arguments. The authenticated connection remains open and usable.
final imap = CkImap();
imap.ssl = true;
imap.port = 993;
try {
imap.connect('imap.example.com');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
imap.login('user@example.com', 'myPassword');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
imap.selectMailbox('Inbox');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
imap.idleStart();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Check once for any updates that arrived.
final timeoutMs = 5000;
final String updates;
try {
updates = imap.idleCheck(timeoutMs);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print(updates);
// End IDLE so that ordinary IMAP commands can be sent again on the same connection.
try {
imap.idleDone();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('IDLE mode ended.');
try {
imap.disconnect();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
}