MessageSet Chilkat2 Perl Reference Documentation

Chilkat2::MessageSet

Current Version: 11.7.0

Markdown version of this page for AI tools (v 11.7.0) · all AI docs

Chilkat.MessageSet

Represent and pass sets of IMAP message identifiers.

Chilkat.MessageSet represents a set of IMAP message identifiers used by Chilkat.Imap. It is a helper object for passing groups of messages to IMAP methods and for receiving groups of message IDs returned by IMAP search, fetch, copy, delete, or flag-related operations. A MessageSet may contain either UIDs or sequence numbers, and the HasUids setting identifies which form is being used.

IMAP message IDs

Store the identifiers used by IMAP operations, either as message UIDs or as sequence numbers.

Used by Chilkat.Imap

Pass message sets to IMAP methods that operate on multiple messages, or receive them from IMAP methods that return matching messages.

UID awareness

Use HasUids to indicate whether the contained identifiers are stable IMAP UIDs or mailbox-relative sequence numbers.

Add and remove IDs

Insert message identifiers, remove identifiers, check whether an ID is present, and build the exact message group needed for an IMAP operation.

Compact string formats

Load or emit compact IMAP-style message ranges such as comma-separated lists and range expressions.

Set operations

Subtract one message set from another when application logic needs to exclude already-processed or unwanted messages.

Common pattern: Use MessageSet only for IMAP message identifiers, not as a general-purpose collection. Obtain a message set from an IMAP search or build one manually, confirm whether it contains UIDs or sequence numbers, then pass it to the appropriate Chilkat.Imap method for fetching, copying, deleting, flagging, or otherwise processing the selected messages.

Object Creation

use Chilkat2;

my $messageSet = Chilkat2::MessageSet->new;
# or set properties (and RaiseError) at creation:
# my $messageSet = Chilkat2::MessageSet->new(VerboseLogging => 1, RaiseError => 1);
my $messageSet = Chilkat2::MessageSet->new(Property => $value, ...);

Creates the object. The optional pairs set writable properties (and RaiseError) in order, as if set one by one; an unknown or read-only name croaks. use Chilkat2; loads every class; the Chilkat2/MessageSet.pm file holds only this class's documentation (perldoc Chilkat2::MessageSet).

Perl frees the object when its last reference goes (undef $messageSet, or the variable going out of scope); there is nothing to close. Objects returned by methods are independent and freed the same way. The class may be subclassed (use parent -norequire, 'Chilkat2::MessageSet';): an object is a blessed hash reference whose hash is free for the subclass's own fields.

my $boolVal = $messageSet->RaiseError;
$messageSet->RaiseError($boolVal);

When false (the default), a method that fails returns false (or undef), and the reason is in LastErrorText. When true, it dies with a Chilkat2::Error instead, as DBI does with its RaiseError. Objects returned by a method inherit the value of the object that returned them.

Errors

A Chilkat2::Error stringifies to the failed call's full LastErrorText, and has the methods text, class ('Chilkat2::MessageSet'), method (the method name) and object. Methods that look something up and find nothing return undef without dying (each such method says so), methods that answer a question (HasMember, IsUnlocked, ...) return a plain boolean, and property reads and writes never fail for Chilkat reasons.

Misuse always croaks, with your file and line, whatever RaiseError is: a wrong number of arguments, a reference or undef where a string or number is expected, an object of the wrong class, an out-of-range integer, a string containing a NUL character, a wide character in a byte string, or a write to a read-only property.

Strings are Perl character strings in both directions (length, regexes and :encoding layers see characters); binary data (BinData) is a byte string. Unlocking: call Chilkat2::Global->new->UnlockBundle('...') once at startup.

Properties

Count
# $intVal is an integer (read-only)
my $intVal = $messageSet->Count;

Returns the number of unique message identifiers currently stored in the set. A newly created MessageSet has a count of 0.

The identifiers are maintained in ascending numeric order. They are interpreted as UIDs when HasUids is 1, or as sequence numbers when it is 0.

top
DebugLogFilePath
# $strVal is a string
my $strVal = $messageSet->DebugLogFilePath;
$messageSet->DebugLogFilePath($strVal);

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
HasUids
# $boolVal is a boolean
my $boolVal = $messageSet->HasUids;
$messageSet->HasUids($boolVal);

Indicates how the numeric identifiers in this message set are interpreted:

  • 1 — the values are IMAP UIDs. This is the default.
  • 0 — the values are mailbox-relative sequence numbers.

Changing this property only changes how the existing numeric values are interpreted. It does not convert, validate, reorder, or clear the identifiers.

An IMAP UID is stable only within its mailbox and while that mailbox's UIDVALIDITY remains unchanged. Sequence numbers are temporary and can change when messages are added or expunged.

Set this property consistently before passing a manually constructed message set to an Imap method. The string formats produced by ToCommaSeparatedStr and ToCompactString contain only the numeric values and do not include this setting.

More Information and Examples
top
LastErrorHtml
# $strVal is a string (read-only)
my $strVal = $messageSet->LastErrorHtml;

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
# $strVal is a string (read-only)
my $strVal = $messageSet->LastErrorText;

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
# $strVal is a string (read-only)
my $strVal = $messageSet->LastErrorXml;

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
# $boolVal is a boolean
my $boolVal = $messageSet->LastMethodSuccess;
$messageSet->LastMethodSuccess($boolVal);

Indicates the success or failure of the most recent method call: 1 means success, 0 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
VerboseLogging
# $boolVal is a boolean
my $boolVal = $messageSet->VerboseLogging;
$messageSet->VerboseLogging($boolVal);

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

top
Version
# $strVal is a string (read-only)
my $strVal = $messageSet->Version;

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

More Information and Examples
top

Methods

ContainsId
# $msgId is an integer
# $flag is true or false
my $flag = $messageSet->ContainsId($msgId);

Returns 1 if the raw numeric value in $msgId is present in the message set; otherwise, returns 0.

The comparison is numeric only. The HasUids setting does not participate in the comparison.

Never dies: false is an answer, not a failure.

top
FromCompactString
# $str is a string
# $success is true or false
my $success = $messageSet->FromCompactString($str);

Clears the identifiers currently stored in this object and loads the compact message-set representation in $str. The existing HasUids setting is preserved.

Important: The existing set is cleared before $str is parsed. If parsing fails, the message set remains empty.

An empty string succeeds and leaves the set empty. Valid identifiers are unsigned 32-bit decimal values from 1 through 4294967295. The value 0 is not accepted. Values too large for an unsigned 32-bit integer cause the method to fail.

The syntax uses commas to separate values or ranges, and a colon to specify an inclusive ascending range. A single range may contain at most 500,001 identifiers; equivalently, the ending value minus the starting value cannot exceed 500000.

Version note: The error-handling behavior described here was added in Chilkat version 11.6.0.
Input Result
1,2,3,4,5Loads 1,2,3,4,5.
1:5Loads the inclusive range 1 through 5.
1:5,8:10Loads 1,2,3,4,5,8,9,10.
1,1,2,2,3Loads the unique values 1,2,3.
1:5,3:7Loads the unique values 1 through 7.
1,,3Empty comma-separated elements are ignored; loads 1,3.
1,2,abc,4Unrecognized elements are ignored; loads 1,2,4.
+1A leading plus sign is accepted; loads 1.

Whitespace is accepted around values, commas, and colons. This includes spaces, tabs, carriage returns, and line feeds. Empty comma-separated elements and unrecognized non-numeric elements are intentionally ignored. If $str is nonempty and no valid identifier is loaded, the method returns 0.

Descending ranges, ranges containing 0, wildcard ranges such as 1:*, malformed range syntax, oversized ranges, and numeric overflow cause the method to return 0.

On success, duplicate identifiers are removed and the resulting identifiers are stored in ascending numeric order. The serialized form contains only the numbers and does not indicate whether they are UIDs or sequence numbers.

Use ToCompactString to generate the canonical compact representation.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
GetId
# $index is an integer
# $n is an integer
my $n = $messageSet->GetId($index);

Returns the message identifier at the zero-based index specified by $index. Identifiers are returned in ascending numeric order.

If $index is negative or is greater than or equal to Count, this method returns 0xFFFFFFFF.

Important: The numeric value 0xFFFFFFFF can also be stored in the set. Check $index against Count before calling this method when that value could be present.
top
InsertId
# $id is an integer
$messageSet->InsertId($id);

Adds $id to the message set and maintains the identifiers in ascending numeric order.

  • If $id is already present, no duplicate is added.
  • If $id is 0, the set is unchanged.
  • The value 0xFFFFFFFF is accepted.

The HasUids setting determines whether the stored values are interpreted as UIDs or sequence numbers.

Returns the object, so calls can be chained.

top
RemoveId
# $id is an integer
$messageSet->RemoveId($id);

Removes the identifier whose raw numeric value equals $id. If the value is not present, the set is unchanged.

The comparison is numeric only and does not depend on HasUids. The remaining identifiers stay in ascending numeric order.

Returns the object, so calls can be chained.

top
Subtract
# $msgSet is a Chilkat2::MessageSet
$messageSet->Subtract($msgSet);
Introduced in version 11.3.0

Removes from this message set every identifier whose raw numeric value is present in $msgSet. Values not present in this set are ignored.

The comparison is numeric only; the HasUids values of the two objects are not compared. This object's HasUids value is preserved, and the remaining identifiers stay in ascending numeric order.

Passing the same object as $msgSet clears the set. Passing an empty set leaves this set unchanged.

For meaningful IMAP results, both objects should represent identifiers of the same type and from the same mailbox.

Returns the object, so calls can be chained.

More Information and Examples
top
ToCommaSeparatedStr
# $str is a string or undef
my $str = $messageSet->ToCommaSeparatedStr();

Returns the unique identifiers as a comma-separated string in ascending numeric order. An empty set returns an empty string.

For example, a set containing the identifiers 1 through 5 returns 1,2,3,4,5.

The returned string contains only the numeric values; it does not include the HasUids setting.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
ToCompactString
# $str is a string or undef
my $str = $messageSet->ToCompactString();

Returns the unique identifiers in ascending numeric order using compact IMAP message-set syntax. Consecutive identifiers are represented as an inclusive range. An empty set returns an empty string.

Comma-separated form Compact form
1,2,3,4,51:5
1,2,3,4,5,8,9,101:5,8:10
1,3,4,5,8,9,101,3:5,8:10

The returned string is canonical for the current set: identifiers are unique, sorted, and consecutive runs are compacted. It contains only the numeric values and does not include the HasUids setting.

Use FromCompactString to load this format.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top