MessageSet Lua Reference Documentation
chilkat.MessageSet
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Object Creation
local chilkat = require("chilkat")
local message_set = chilkat.MessageSet.new()Creates the object (chilkat.MessageSet() does the same). Lua's garbage collector frees it when it is no longer referenced; message_set:dispose() frees it at once, and in Lua 5.4 and later local message_set <close> = chilkat.MessageSet.new() frees it when the block ends. Calling a method of a disposed object raises an error.
Errors
A method that fails returns nil followed by the error text, as io.open does: local body, err = message_set:method(...), where err is the object's last_error_text. Wrap the call in assert() to raise an error with that text instead. Methods that answer a question return true or false, numbers are returned as they are (check last_method_success where the description says a value means failure), and property reads and writes never fail for Chilkat reasons.
Misuse raises a Lua error: a wrong argument type or a missing argument (bad argument #1 to ...), an unknown property name, a write to a read-only property, an out-of-range integer, or an object of the wrong class.
Names are Chilkat's in snake_case: QuickGetStr is quick_get_str, LastErrorText is last_error_text. Properties are fields (message_set.verbose_logging = true) and methods use the colon (message_set:method(...)). Strings are UTF-8; binary data is a Lua string of bytes. Indexes are 0-based, as in every Chilkat API. Unlocking: call chilkat.unlock_bundle("...") once at startup.
Properties
Count
local intVal = message_set.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 , or as sequence numbers when it is true.false
DebugLogFilePath
local strVal = message_set.debug_log_file_path
message_set.debug_log_file_path = 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.
HasUids
local boolVal = message_set.has_uids
message_set.has_uids = boolVal
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 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.
LastErrorHtml
local strVal = message_set.last_error_html
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.
topLastErrorText
local strVal = message_set.last_error_text
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.
LastErrorXml
local strVal = message_set.last_error_xml
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.
topLastMethodSuccess
local boolVal = message_set.last_method_success
message_set.last_method_success = boolVal
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.
VerboseLogging
local boolVal = message_set.verbose_logging
message_set.verbose_logging = boolVal
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.
Version
local strVal = message_set.version
Methods
ContainsId
-- flag is true or false
local flag = message_set:contains_id(msg_id)
Returns if the raw numeric value in truemsg_id is present in the message set; otherwise, returns .false
The comparison is numeric only. The HasUids setting does not participate in the comparison.
Returns true or false: an answer, not a success flag.
FromCompactString
-- ok is true, or nil and err on failure
local ok, err = message_set:from_compact_string(str)
Clears the identifiers currently stored in this object and loads the compact message-set representation in str. The existing HasUids setting is preserved.
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.
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 .false
Descending ranges, ranges containing 0, wildcard ranges such as 1:*, malformed range syntax, oversized ranges, and numeric overflow cause the method to return .false
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, nil, err on failure. The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
GetId
-- n is an integer
local n = message_set:get_id(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.
0xFFFFFFFF can also be stored in the set. Check index against Count before calling this method when that value could be present.InsertId
message_set:insert_id(id)
Adds id to 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 HasUids setting determines whether the stored values are interpreted as UIDs or sequence numbers.
RemoveId
message_set:remove_id(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.
Subtract
message_set:subtract(msg_set)
Removes from this message set every identifier whose raw numeric value is present in msg_set. 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 msg_set 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.
ToCommaSeparatedStr
local str, err = message_set:to_comma_separated_str()
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 the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.
ToCompactString
local str, err = message_set:to_compact_string()
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.
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 the string, or nil, err on failure (or when nothing is found). The second return value, err, is the object's last_error_text; wrap the call in assert() to raise an error instead.