React Native
React Native
Refresh an Email Object's IMAP Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.RefetchMailFlags method, which updates the flags stored on an Email object to the current values on the server. The only argument is the Email object. This example re-reads the flags for a previously fetched message and then checks its Seen state.
Background: Flags are shared mailbox state, so between the time you fetch a message and the time you act on it, another client (a phone, a webmail tab) may have marked it read, flagged, or deleted.
RefetchMailFlags pulls just the flags — not the whole message — so a long-running job can cheaply re-check the live state before deciding what to do, avoiding acting on stale information.Chilkat React Native Downloads
import { Email, EmailBundle, Imap, MessageSet } from '@chilkat/react-native'
async function chilkatExample() {
// Demonstrates the Imap.RefetchMailFlags method, which updates the flags stored on an Email
// object to the current values on the server. The only argument is the Email object.
const imap = new Imap();
imap.ssl = true;
imap.port = 993;
try {
await imap.connectAsync('imap.example.com');
} catch {
console.log(imap.lastErrorText);
return;
}
try {
await imap.loginAsync('user@example.com', 'myPassword');
} catch {
console.log(imap.lastErrorText);
return;
}
try {
await imap.selectMailboxAsync('Inbox');
} catch {
console.log(imap.lastErrorText);
return;
}
const msgSet = new MessageSet();
try {
await imap.queryMbxAsync('ALL', true, msgSet);
} catch {
console.log(imap.lastErrorText);
return;
}
const bundle = new EmailBundle();
try {
await imap.fetchMsgSetAsync(true, msgSet, bundle);
} catch {
console.log(imap.lastErrorText);
return;
}
const email = new Email();
if (bundle.messageCount > 0) {
bundle.emailAt(0, email);
// Re-read the flags from the server, in case another client changed them since the fetch.
try {
await imap.refetchMailFlagsAsync(email);
} catch {
console.log(imap.lastErrorText);
return;
}
const seen = imap.getMailFlag(email, 'Seen');
console.log(`Current Seen state: ${seen}`);
}
try {
await imap.disconnectAsync();
} catch {
console.log(imap.lastErrorText);
return;
}
}