EmailBundle React Native Reference Documentation

EmailBundle

Current Version: 11.6.1

EmailBundle

Hold, search, sort, remove, save, and reload groups of email messages.

EmailBundle is a container for multiple Email objects. It is commonly returned by mail-related operations and can also be built manually by adding individual email messages. The class provides a simple way to work with groups of messages: retrieve emails by index, search for a matching email, sort by common email fields, remove messages, clear the bundle, and serialize or reload the collection as XML.

Email collection

Store multiple Email objects together after receiving, loading, filtering, or manually building a message set.

Retrieve messages

Use the message count and indexed access methods to retrieve individual emails for inspection, processing, saving, or sending.

Search within the bundle

Locate a specific email in the collection when application logic needs to find a matching message.

Sort messages

Sort the bundle by date, sender, recipient, or subject to organize messages before processing or display.

Remove or clear emails

Remove individual messages by object or index, or clear the entire bundle when the collection is no longer needed.

Save and reload

Serialize the bundle to XML and reload it later, or load task results that return an email bundle.

Common pattern: Receive or build a bundle of Email objects, loop from 0 to MessageCount - 1, retrieve each message with EmailAt, and then inspect, save, sort, remove, or process each email as needed. Use EmailBundle for the group and Email for the individual message contents.

Object Creation

// npm install @chilkat/react-native react-native-nitro-modules
// (React Native 0.76+ with the New Architecture; then `pod install` for iOS.  The Chilkat
//  native library is downloaded and verified during the native build -- see the package README.)

import { Chilkat, EmailBundle } from '@chilkat/react-native'

// Once per app start, before any other Chilkat call:
Chilkat.unlockBundle('Anything for 30-day trial')   // shorthand for new Global().unlockBundle(..)

const emailBundle = new EmailBundle()
// ... the native object is released when `emailBundle` is garbage collected, or now with emailBundle.dispose()
new EmailBundle()

Creates the underlying native Chilkat object. EmailBundle is a Nitro Module HybridObject: use it from the JavaScript thread only (it cannot be passed to a Worklet or another runtime). Every member is synchronous and blocks the JavaScript thread until Chilkat returns; a method that can take a while also exists as a ...Async twin returning a Promise, which runs the same call on a native worker thread so the UI keeps rendering. While such a call is pending, every other call on this object throws, except abort() and assigning onPercentDone / onProgressInfo.

dispose(): void

Releases the native object immediately instead of waiting for garbage collection (useful for a large BinData or an open socket). Calling it more than once is harmless; any other use of the object afterwards throws. An object with a pending ...Async call cannot be disposed until the promise settles.

Errors

A method that can fail throws a plain Error: a method whose only outcome is success or failure returns void and throws on failure; a method producing a string or an object returns it and throws where Chilkat would have returned null. The error's message is "Class.method(...): reason", where the reason is the last informative line of the object's lastErrorText, which holds the full Chilkat log of the failed call. A ...Async twin rejects its promise with the same Error instead of throwing. Properties never throw, and methods that answer a question (has..., is..., ...) return a plain boolean.

try {
  emailBundle.someMethod(...)
} catch (e) {
  console.log((e as Error).message)   // EmailBundle.someMethod(...): <reason>
  console.log(emailBundle.lastErrorText)   // the full Chilkat log of the failed call
}

// The same call without blocking the JavaScript thread:
try {
  await emailBundle.someMethodAsync(...)
} catch (e) {
  console.log((e as Error).message)   // EmailBundle.someMethodAsync: <reason>
}

Properties

DebugLogFilePath
// read/write
debugLogFilePath: string

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
LastErrorHtml
// read-only
readonly lastErrorHtml: string

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
// read-only
readonly lastErrorText: string

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
// read-only
readonly lastErrorXml: string

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
// read/write
lastMethodSuccess: boolean

Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
MessageCount
// read-only
readonly messageCount: number

Returns the number of Email objects currently contained in the bundle.

Valid zero-based indexes range from 0 through MessageCount - 1.

top
VerboseLogging
// read/write
verboseLogging: boolean

If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
// read-only
readonly version: string

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

AddEmail
addEmail(email: Email): void

Adds an independent copy of the Email object in email to the end of this in-memory bundle.

The bundle does not retain a reference to email and does not take ownership of the supplied object. Changes made to email after this method returns do not affect the copy stored in the bundle, and changes to the stored copy do not affect email.

The same Email object may be added more than once. Each call adds another independent copy and increases the MessageCount property by one.

Returns normally on success; throws an Error on failure.

top
Clear
clear(): void
Introduced in version 11.1.0

Removes and discards all emails from this in-memory bundle.

After this method returns, MessageCount is 0. No messages are deleted from any mail server.

top
EmailAt
emailAt(index: number, email: Email): void
Introduced in version 11.0.0

Copies the email at the zero-based index in index into the Email object in email.

Valid indexes range from 0 through MessageCount - 1. The first email is at index 0.

email receives an independent copy. Changes made to email do not modify the email stored in the bundle.

Note: This is an in-memory operation and does not communicate with a mail server.

Returns normally on success; throws an Error on failure.

top
FindEmail
findEmail(json: JsonObject, email: Email): void
Introduced in version 11.0.0

Finds the first email in the bundle whose MIME header field matches the search criteria specified by the JsonObject in json.

At this time, a search may specify only one MIME header field. Use the following JSON format:

{
  "header": {
    "name": "Subject",
    "value": "Dinner on Wednesday?",
    "caseInsensitive": true
  }
}

header.name specifies the MIME header field name, and header.value specifies the complete field value to match. The field value must match exactly; this is not a substring, wildcard, or regular-expression search. Set header.caseInsensitive to true for a case-insensitive comparison or false for a case-sensitive comparison.

When a match is found, email receives the first matching email.

Returns normally on success; throws an Error on failure.

top
GetXml
getXml(): string

Serializes the entire email bundle to Chilkat XML and returns the XML document as a string.

The XML contains the bundle and its individual Email objects. It can be loaded into another EmailBundle by calling LoadXmlString.

This is Chilkat's XML representation of an email bundle; it is not an RFC 822/MIME message.

Throws an Error on failure (where the description says null is returned, the method throws instead).

top
LoadXml
loadXml(path: string): void

Loads an email bundle from the local filesystem path specified by path. The path may be absolute or relative; a filename alone refers to a file in the current working directory.

The file should contain Chilkat email-bundle XML previously produced by SaveXml or GetXml.

The emails loaded from path are appended to the emails already in the bundle. Existing emails are not removed or replaced.

Returns normally on success; throws an Error on failure.

top
LoadXmlString
loadXmlString(xmlStr: string): void

Loads an email bundle from the Chilkat XML string in xmlStr.

The XML is typically obtained from GetXml or read from a file created by SaveXml.

The emails loaded from xmlStr are appended to the emails already in the bundle. Existing emails are not removed or replaced.

Returns normally on success; throws an Error on failure.

top
RemoveEmail
removeEmail(email: Email): void

Removes the first email in this in-memory bundle that matches email.

Chilkat first searches for an email having the same UIDL as email. If no email with a matching UIDL is found, it searches for the first email having the same Message-ID header field value. Only the first matching email is removed.

email may be an independent copy obtained from EmailAt.

Note: This method changes only the local bundle. It does not delete a message from a POP3 or IMAP server.

Returns normally on success; throws an Error on failure.

top
RemoveEmailByIndex
removeEmailByIndex(index: number): void

Removes the email at the zero-based index in index.

Valid indexes range from 0 through MessageCount - 1.

Note: This method changes only the local bundle. It does not delete a message from a mail server.

Returns normally on success; throws an Error on failure.

top
SaveXml
saveXml(path: string): void

Serializes the bundle and each contained Email to Chilkat XML, then writes the XML document to the local filesystem path specified by path. The path may be absolute or relative; a filename alone writes to the current working directory.

Reload the saved bundle by calling LoadXml. Use GetXml when the XML is needed in memory rather than in a file.

The saved file is a Chilkat email-bundle serialization, not an RFC 822/MIME message file.

Returns normally on success; throws an Error on failure.

top
SortByDate
sortByDate(ascending: boolean): void

Sorts the emails in this bundle by each Email object's EmailDate property.

Set ascending to true to sort in ascending order, from oldest to newest. Set ascending to false to sort in descending order, from newest to oldest.

The operation changes the order of the emails in the in-memory collection.

top
SortByRecipient
sortByRecipient(ascending: boolean): void

Sorts the emails in this bundle by the full value of each email's To header field.

The comparisons are case-sensitive. Set ascending to true for ascending order or false for descending order. The operation changes the order of the emails in the in-memory collection.

top
SortBySender
sortBySender(ascending: boolean): void

Sorts the emails in this bundle by the full content of each email's From header field.

Set ascending to true for ascending order or false for descending order. The operation changes the order of the emails in the in-memory collection.

top
SortBySubject
sortBySubject(ascending: boolean): void

Sorts the emails in this bundle by subject.

Set ascending to true for ascending order or false for descending order. The operation changes the order of the emails in the in-memory collection.

top