Class MessageSet
- All Implemented Interfaces:
AutoCloseable
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.
For an extended overview, see MessageSet Class Overview.
</section>
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsId(long msgId)Returnsif the raw numeric value intruemsgIdis present in the message set; otherwise, returns.falsevoidfromCompactString(String str)Clears the identifiers currently stored in this object and loads the compact message-set representation instr.intgetCount()Returns the number of unique message identifiers currently stored in the set.booleanIndicates how the numeric identifiers in this message set are interpreted:— the values are IMAP UIDs.truelonggetId(int index)Returns the message identifier at the zero-based index specified byindex.voidinsertId(long id)Addsidto the message set and maintains the identifiers in ascending numeric order.voidremoveId(long id)Removes the identifier whose raw numeric value equalsid.voidsetHasUids(boolean value)Sets theHasUidsproperty; seegetHasUids().voidsubtract(MessageSet msgSet)Removes from this message set every identifier whose raw numeric value is present inmsgSet.Returns the unique identifiers as a comma-separated string in ascending numeric order.Returns the unique identifiers in ascending numeric order using compact IMAP message-set syntax.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
MessageSet
public MessageSet()Creates a newMessageSetobject.
-
-
Method Details
-
getCount
public int getCount()Returns the number of unique message identifiers currently stored in the set. A newly createdMessageSethas a count of0.The identifiers are maintained in ascending numeric order. They are interpreted as UIDs when
isgetHasUids(), or as sequence numbers when it istrue.false- Returns:
- the value of the
Countproperty (read-only)
-
getHasUids
public boolean getHasUids()Indicates how the numeric identifiers in this message set are interpreted:— the values are IMAP UIDs. This is the default.true— the values are mailbox-relative sequence numbers.false
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
UIDVALIDITYremains 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
Imapmethod. The string formats produced byandtoCommaSeparatedStr()contain only the numeric values and do not include this setting.toCompactString()- Returns:
- the value of the
HasUidsproperty
-
setHasUids
public void setHasUids(boolean value)Sets theHasUidsproperty; seegetHasUids().- Parameters:
value- the new value
-
containsId
public boolean containsId(long msgId)Returnsif the raw numeric value intruemsgIdis present in the message set; otherwise, returns.falseThe comparison is numeric only. The
setting does not participate in the comparison.getHasUids()- Parameters:
msgId- themsgIdargument (0 .. 4294967295)- Returns:
- the result; this method never throws
ChilkatException
-
fromCompactString
Clears the identifiers currently stored in this object and loads the compact message-set representation instr. The existingsetting is preserved.getHasUids()Important: The existing set is cleared before
stris 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
1through4294967295. The value0is 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,5Loads1,2,3,4,5.1:5Loads the inclusive range1through5.1:5,8:10Loads1,2,3,4,5,8,9,10.1,1,2,2,3Loads the unique values1,2,3.1:5,3:7Loads the unique values1through7.1,,3Empty comma-separated elements are ignored; loads1,3.1,2,abc,4Unrecognized elements are ignored; loads1,2,4.+1A leading plus sign is accepted; loads1.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
stris nonempty and no valid identifier is loaded, the method returns.falseDescending ranges, ranges containing
0, wildcard ranges such as1:*, malformed range syntax, oversized ranges, and numeric overflow cause the method to return.falseOn 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
to generate the canonical compact representation.toCompactString()- Parameters:
str- thestrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getId
public long getId(int index)Returns the message identifier at the zero-based index specified byindex. Identifiers are returned in ascending numeric order.If
indexis negative or is greater than or equal to, this method returnsgetCount()0xFFFFFFFF.Important: The numeric value
0xFFFFFFFFcan also be stored in the set. CheckindexagainstCountbefore calling this method when that value could be present.- Parameters:
index- theindexargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-
insertId
public void insertId(long id)Addsidto the message set and maintains the identifiers in ascending numeric order.- If
idis already present, no duplicate is added. - If
idis0, the set is unchanged. - The value
0xFFFFFFFFis accepted.
The
setting determines whether the stored values are interpreted as UIDs or sequence numbers.getHasUids()- Parameters:
id- theidargument (0 .. 4294967295)
- If
-
removeId
public void removeId(long id)Removes the identifier whose raw numeric value equalsid. If the value is not present, the set is unchanged.The comparison is numeric only and does not depend on
. The remaining identifiers stay in ascending numeric order.getHasUids()- Parameters:
id- theidargument (0 .. 4294967295)
-
subtract
Removes from this message set every identifier whose raw numeric value is present inmsgSet. Values not present in this set are ignored.The comparison is numeric only; the
values of the two objects are not compared. This object'sgetHasUids()HasUidsvalue is preserved, and the remaining identifiers stay in ascending numeric order.Passing the same object as
msgSetclears 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.
- Parameters:
msgSet- themsgSetargument (notnull)
-
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
1through5returns1,2,3,4,5.The returned string contains only the numeric values; it does not include the
setting.getHasUids()- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
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:51,2,3,4,5,8,9,101:5,8:101,3,4,5,8,9,101,3:5,8:10The 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
setting.getHasUids()Use
to load this format.fromCompactString(String)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-