React Native
React Native
Test for an IMAP Server Capability
See more IMAP Examples
Demonstrates the Chilkat Imap.HasCapability method, which tests whether a named capability appears in a raw capability response. The second argument is typically the string returned by the Capability method. This example checks whether the server supports the IDLE extension.
Background: Rather than scanning the raw
CAPABILITY text yourself, HasCapability parses it for a specific token. This is the right guard before using any optional feature — for example, only entering an IDLE wait loop, or using the MOVE command, when the server actually advertises it. Fetch the capability string once and test it as many times as needed.Chilkat React Native Downloads
import { Imap } from '@chilkat/react-native'
async function chilkatExample() {
// Demonstrates the Imap.HasCapability method, which tests whether a named capability appears
// in a raw capability response. The 2nd argument is typically the string returned by the
// Capability method.
const imap = new Imap();
imap.ssl = true;
imap.port = 993;
try {
await imap.connectAsync('imap.example.com');
} catch {
console.log(imap.lastErrorText);
return;
}
// Get the raw capability response.
let capabilities: string;
try {
capabilities = await imap.capabilityAsync();
} catch {
console.log(imap.lastErrorText);
return;
}
// Test whether the server supports the IDLE extension.
const hasIdle = imap.hasCapability('IDLE', capabilities);
if (hasIdle) {
console.log('The server supports IDLE.');
} else {
console.log('The server does not support IDLE.');
}
try {
await imap.disconnectAsync();
} catch {
console.log(imap.lastErrorText);
return;
}
}