### Chat Cache Example Source: https://docs.rs/imessage-database/latest/imessage_database/tables/chat/struct.Chat.html Example demonstrating how to cache chat data from the database using the 'cache' function. Requires establishing a database connection first. ```rust use imessage_database::util::dirs::default_db_path; use imessage_database::tables::table::{Cacheable, get_connection}; use imessage_database::tables::chat::Chat; let db_path = default_db_path(); let conn = get_connection(&db_path).unwrap(); let chatrooms = Chat::cache(&conn); ``` -------------------------------- ### Set Start Date for QueryContext Source: https://docs.rs/imessage-database/latest/imessage_database/util/query_context/struct.QueryContext.html Populates the QueryContext with a start date filter. The date is provided as a string and parsed into a suitable format. ```rust use imessage_database::util::query_context::QueryContext; let mut context = QueryContext::default(); context.set_start("2023-01-01"); ``` -------------------------------- ### fn get Source: https://docs.rs/imessage-database/latest/imessage_database/tables/table/trait.Table.html Prepare SELECT * statement for retrieving all columns from a table. ```APIDOC ## fn get(db: &Connection) -> Result, TableError> ### Description Prepare SELECT * statement for retrieving all columns from a table. ### Parameters #### Path Parameters - **db** (&Connection) - Required - The database connection. ``` -------------------------------- ### Create Message from GUID Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/struct.Message.html Creates a Message instance from its unique GUID. Useful for debugging or retrieving specific messages. Requires a database connection. ```rust use imessage_database:: tables:: messages::Message, table::get_connection, util::dirs::default_db_path; let db_path = default_db_path(); let conn = get_connection(&db_path).unwrap(); if let Ok(mut message) = Message::from_guid("example-guid", &conn) { if let Ok(body) = message.parse_body(&conn) { message.apply_body(body); } println!("{:#?}", message) } ``` -------------------------------- ### from_guid Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/struct.Message.html Creates a `Message` instance from a given GUID, primarily for debugging purposes. ```APIDOC ## pub fn from_guid(guid: &str, db: &Connection) -> Result ### Description Create a message from a given GUID; useful for debugging. ### Parameters - **guid** (*str) - Required - The GUID of the message to retrieve. - **db** (*Connection) - Required - A database connection object. ### Returns - **Result** - A `Result` containing the `Message` if found, or a `TableError` otherwise. ### Example ```rust use imessage_database::tables::messages::Message; use imessage_database::util::dirs::default_db_path; use imessage_database::tables::table::get_connection; let db_path = default_db_path(); let conn = get_connection(&db_path).unwrap(); if let Ok(mut message) = Message::from_guid("example-guid", &conn) { if let Ok(body) = message.parse_body(&conn) { message.apply_body(body); } println!("{:#?}", message) } ``` ``` -------------------------------- ### Format File Size Source: https://docs.rs/imessage-database/latest/imessage_database/util/size/fn.format_file_size.html Converts a u64 byte count into a human-readable string. Example shows formatting 5,612,000 bytes. ```rust use imessage_database::util::size::format_file_size; let size: String = format_file_size(5612000); println!("{size}"); // 5.35 MB ``` -------------------------------- ### Stream Table Rows Example Source: https://docs.rs/imessage-database/latest/imessage_database/tables/table/trait.Table.html Demonstrates how to stream rows from a table using a callback function for memory-efficient processing of large tables. Requires a database connection and imports from the imessage_database crate. ```rust use imessage_database:: error::table::TableError, tables:: table::{get_connection, Table}, handle::Handle, util::dirs::default_db_path }; // Get a connection to the database let db_path = default_db_path(); let db = get_connection(&db_path).unwrap(); // Stream the Handle table, processing each row with a callback Handle::stream(&db, |handle_result| { match handle_result { Ok(handle) => println!("Handle: {}", handle.id), Err(e) => eprintln!("Error: {:?}", e), } Ok::<(), TableError>(()) }).unwrap(); ``` -------------------------------- ### fn get_blob Source: https://docs.rs/imessage-database/latest/imessage_database/tables/table/trait.Table.html Get a BLOB from the table. ```APIDOC ## fn get_blob<'a>(&self, db: &'a Connection, table: &str, column: &str, rowid: i64) -> Option> ### Description Get a BLOB from the table. ### Parameters #### Path Parameters - **db** (&'a Connection) - Required - The database connection. - **table** (&str) - Required - The name of the table. - **column** (&str) - Required - The name of the column containing the BLOB. - **rowid** (i64) - Required - The row ID to retrieve the BLOB from. ``` -------------------------------- ### Group and Action Methods Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/struct.Message.html Methods for retrieving information about group actions and associated message GUIDs. ```APIDOC ## group_action ### Description Retrieves the group action associated with the current message. ### Method `group_action(&self) -> Option>` ### Returns An `Option` if a group action is present, `None` otherwise. ``` ```APIDOC ## clean_associated_guid ### Description Cleans and parses the associated message GUID, typically used for tapbacks and replies. Returns the component index and message GUID if present. ### Method `clean_associated_guid(&self) -> Option<(usize, &str)>` ### Returns An `Option` containing a tuple of `(usize, &str)` representing the component index and message GUID, or `None` if not applicable. ``` -------------------------------- ### get Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/struct.Message.html Converts data from the messages table into native Rust data structures, using fallback queries for compatibility with older database schemas. ```APIDOC ## fn get(db: &Connection) -> Result, TableError> ### Description Convert data from the messages table to native Rust data structures, falling back to more compatible queries to ensure compatibility with older database schemas. ### Parameters - **db** (*Connection) - Required - A database connection object. ### Returns - **Result, TableError>** - A `Result` containing the `CachedStatement` or a `TableError`. ``` -------------------------------- ### Get Attachment MIME Type Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Returns the media type of an attachment. ```rust pub fn mime_type(&self) -> MediaType<'_> ``` -------------------------------- ### Get Attachment Path Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Retrieves the file system path for an attachment, if it exists. ```rust pub fn path(&self) -> Option<&Path> ``` -------------------------------- ### Get Home Directory (macOS) Source: https://docs.rs/imessage-database/latest/imessage_database/util/dirs/fn.home.html Call the `home` function to obtain the user's home directory path. This function is intended for macOS. ```rust use imessage_database::util::dirs::home; let path = home(); println!("{path}"); ``` -------------------------------- ### TextAttributes Constructor Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/models/struct.TextAttributes.html Creates a new `TextAttributes` with the specified start index, end index, and text effects. ```APIDOC ### impl TextAttributes #### pub fn new(start: usize, end: usize, effects: Vec) -> Self Creates a new `TextAttributes` with the specified start index, end index, and text effects. ``` -------------------------------- ### Get iMessage Database Connection Source: https://docs.rs/imessage-database/latest/imessage_database/tables/table/fn.get_connection.html Use this function to establish a connection to the default iMessage SQLite database. Ensure the `imessage_database` crate is imported. ```rust use imessage_database:: util::dirs::default_db_path, tables::table::get_connection }; let db_path = default_db_path(); let connection = get_connection(&db_path); ``` -------------------------------- ### Sample parsed message body Source: https://docs.rs/imessage-database/latest/imessage_database/util/streamtyped/fn.parse.html This example shows the expected output structure when parsing an iMessage with attachments and text effects. It represents the message body as a vector of `BubbleComponent`s. ```rust use imessage_database::message_types::text_effects::TextEffect; use imessage_database::tables::messages::{models::{TextAttributes, BubbleComponent, AttachmentMeta}}; let result = vec![ BubbleComponent::Attachment(AttachmentMeta::default()), BubbleComponent::Text(vec![TextAttributes::new(3, 24, vec![TextEffect::Default])]), ]; ``` -------------------------------- ### Example NSKeyedArchiver XML Structure Source: https://docs.rs/imessage-database/latest/imessage_database/util/plist/fn.parse_ns_keyed_archiver.html Illustrates a simplified XML structure that might be encountered before parsing. The `CF$UID` indicates a reference to another object within the plist. ```xml link CF$UID 2 https://chrissardegna.com ``` -------------------------------- ### Iterate Over Message Data Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/index.html Use `Message::stream()` to iterate over message rows. This example shows how to connect to the database and process each message, handling potential errors. ```rust use imessage_database:: error::table::TableError, tables:: messages::Message, table::{get_connection, Table}, }, util::dirs::default_db_path, }; // Your custom error type #[derive(Debug)] struct ProgramError(TableError); impl From for ProgramError { fn from(err: TableError) -> Self { Self(err) } } // Get the default database path and connect to it let db_path = default_db_path(); let conn = get_connection(&db_path).unwrap(); Message::stream(&conn, |message_result| { match message_result { Ok(message) => println!("Message: {:#?}", message), Err(e) => eprintln!("Error: {:?}", e), } Ok::<(), ProgramError>(()) }).unwrap(); ``` -------------------------------- ### Get Chat Properties Source: https://docs.rs/imessage-database/latest/imessage_database/tables/chat/struct.Chat.html Fetches the 'Properties' associated with a chat from the database. This operation is database-intensive and should be used judiciously. ```rust pub fn properties(&self, db: &Connection) -> Option ``` -------------------------------- ### Get Human-Readable File Size Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Formats the attachment's total bytes into a human-readable string using `format_file_size`. ```rust pub fn file_size(&self) -> String ``` -------------------------------- ### Execute Custom Message Query with Emoji Filter Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/index.html This Rust example demonstrates how to execute a custom SQL query to retrieve messages that have an associated emoji. It prepares the statement, queries the database, and then processes the results, extracting and printing message details. ```rust use imessage_database:: tables:: messages::Message, table::{get_connection, Table}, }, util::dirs::default_db_path }; let db_path = default_db_path(); let db = get_connection(&db_path).unwrap(); let mut statement = db.prepare(" SELECT *, c.chat_id, (SELECT COUNT(*) FROM message_attachment_join a WHERE m.ROWID = a.message_id) as num_attachments, d.chat_id as deleted_from, (SELECT COUNT(*) FROM message m2 WHERE m2.thread_originator_guid = m.guid) as num_replies FROM message as m LEFT JOIN chat_message_join as c ON m.ROWID = c.message_id LEFT JOIN chat_recoverable_message_join as d ON m.ROWID = d.message_id WHERE m.associated_message_emoji IS NOT NULL ORDER BY m.date; ").unwrap(); let messages = statement.query_map([], |row| Ok(Message::from_row(row))).unwrap(); messages.for_each(|msg| println!( "{:#?}", Message::extract(msg))); ``` -------------------------------- ### Get Sticker Source Application Name from Attachment Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Parses a sticker's application name from ATTRIBUTION_INFO plist data. This operation is database-intensive. ```rust pub fn get_sticker_source_application_name( &self, db: &Connection, ) -> Option ``` -------------------------------- ### Get Database Size Source: https://docs.rs/imessage-database/latest/imessage_database/tables/table/fn.get_db_size.html Use this function to retrieve the size of the iMessage database file in bytes. Ensure the necessary imports are included. ```rust use imessage_database:: util::dirs::default_db_path, tables::table::get_db_size }; let db_path = default_db_path(); let database_size_in_bytes = get_db_size(&db_path); ``` -------------------------------- ### Create TextAttributes Instance Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/models/struct.TextAttributes.html Instantiates a TextAttributes struct with specified start and end indices and a list of text effects. This is useful for programmatically defining text styling. ```rust use imessage_database::message_types::text_effects::TextEffect; use imessage_database::tables::messages::models::{TextAttributes, BubbleComponent}; let result = vec![BubbleComponent::Text(vec![TextAttributes::new(0, 11, vec![TextEffect::Default]), // `What's up, ` TextAttributes::new(11, 22, vec![TextEffect::Mention("+5558675309".to_string())]), // ` Christopher` TextAttributes::new(22, 23, vec![TextEffect::Default]) // `?` ])]; ``` -------------------------------- ### parse_balloon_bundle_id Source: https://docs.rs/imessage-database/latest/imessage_database/util/bundle_id/fn.parse_balloon_bundle_id.html Parses an App's Bundle ID out of a Balloon's Bundle ID. For example, a Bundle ID like `com.apple.messages.MSMessageExtensionBalloonPlugin:0000000000:com.apple.SafetyMonitorApp.SafetyMonitorMessages` should get parsed into `com.apple.SafetyMonitorApp.SafetyMonitorMessages`. ```APIDOC ## Function parse_balloon_bundle_id ### Signature ```rust pub fn parse_balloon_bundle_id(bundle_id: Option<&str>) -> Option<&str> ``` ### Description Parse an App’s Bundle ID out of a Balloon’s Bundle ID. For example, a Bundle ID like `com.apple.messages.MSMessageExtensionBalloonPlugin:0000000000:com.apple.SafetyMonitorApp.SafetyMonitorMessages` should get parsed into `com.apple.SafetyMonitorApp.SafetyMonitorMessages`. ### Example ```rust use imessage_database::util::bundle_id::parse_balloon_bundle_id; let bundle_id = "com.apple.messages.MSMessageExtensionBalloonPlugin:0000000000:com.apple.SafetyMonitorApp.SafetyMonitorMessages"; let parsed = parse_balloon_bundle_id(Some(bundle_id)); // Some("com.apple.SafetyMonitorApp.SafetyMonitorMessages") ``` ``` -------------------------------- ### String::from Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Demonstrates converting different types into a String. ```APIDOC ## String::from ### Description Converts various types into an owned `String`. ### Methods #### `fn from(s: &String) -> String` Converts a `&String` into a `String` by cloning. #### `fn from(s: &mut str) -> String` Converts a mutable string slice `&mut str` into a `String` by allocating on the heap. #### `fn from(s: &str) -> String` Converts a string slice `&str` into a `String` by allocating on the heap. #### `fn from(s: Box) -> String` Converts a boxed string slice `Box` into a `String`. The `str` slice is owned. ##### Example ```rust let s1: String = String::from("hello world"); let s2: Box = s1.into_boxed_str(); let s3: String = String::from(s2); assert_eq!("hello world", s3) ``` #### `fn from(s: Cow<'a, str>) -> String` Converts a `Cow<'a, str>` into an owned `String`. If the `Cow` is borrowed, it will be cloned. ##### Example ```rust // If the string is not owned... let cow: Cow<'_, str> = Cow::Borrowed("eggplant"); // It will allocate on the heap and copy the string. let owned: String = String::from(cow); assert_eq!(&owned[..], "eggplant"); ``` #### `fn from(key: Key) -> String` Converts from a `Key` type to a `String`. #### `fn from(short: Short) -> String` Converts from a `Short` type to a `String`. #### `fn from(c: char) -> String` Allocates an owned `String` from a single character. ##### Example ```rust let c: char = 'a'; let s: String = String::from(c); assert_eq!("a", &s[..]); ``` ``` -------------------------------- ### Get String as a byte slice Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Use `as_bytes` to get a byte slice representation of the String's contents. The inverse operation is `from_utf8`. ```rust let s = String::from("hello"); assert_eq!(&[104, 101, 108, 108, 111], s.as_bytes()); ``` -------------------------------- ### Determine Platform from Path Source: https://docs.rs/imessage-database/latest/imessage_database/util/platform/enum.Platform.html Attempts to identify the platform based on the provided database path. Defaults to macOS if determination fails. ```rust pub fn determine(db_path: &Path) -> Result ``` -------------------------------- ### Prepare Chat Select Statement Source: https://docs.rs/imessage-database/latest/imessage_database/tables/chat/struct.Chat.html Prepares a SQL statement for selecting all columns from the chat table. ```rust fn get(db: &Connection) -> Result, TableError> ``` -------------------------------- ### Get Sticker Source Application Name Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Parses a sticker's application name stored in the `ATTRIBUTION_INFO` plist data. This operation is database-intensive and should be used sparingly. ```APIDOC ## pub fn get_sticker_source_application_name ### Description Parse a sticker’s application name stored in `ATTRIBUTION_INFO` `plist` data. Calling this hits the database, so it is expensive and should only get invoked when needed. ### Parameters - `db` (*Connection) - A connection to the database. ### Returns - `Option` - An optional application name string if found, otherwise None. ``` -------------------------------- ### Get String Capacity Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Returns the current capacity of the String in bytes. ```rust let s = String::from("hello"); let capacity = s.capacity(); // The capacity is at least the length of the string, but may be larger. ``` -------------------------------- ### Create Platform from CLI Input Source: https://docs.rs/imessage-database/latest/imessage_database/util/platform/enum.Platform.html Converts a string input from the command line into a Platform variant. Returns None if the input does not match any known platform. ```rust pub fn from_cli(platform: &str) -> Option ``` -------------------------------- ### FromIterator Implementations for String Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Demonstrates how to create a String from various iterator types. ```APIDOC ## FromIterator> for String ### Description Creates a String from an iterator of `Box`. ### Method `from_iter(iter: I) -> String` ### Type Parameters - `A`: Allocator - `I`: IntoIterator> ### Availability Available on **non-`no_global_oom_handling`** only. ``` ```APIDOC ## FromIterator for String ### Description Creates a String from an iterator of `AsciiChar`. ### Method `from_iter(iter: T) -> String` ### Type Parameters - `T`: IntoIterator ### Availability Available on **non-`no_global_oom_handling`** only. ``` ```APIDOC ## FromIterator> for String ### Description Creates a String from an iterator of `Cow<'a, str>`. ### Method `from_iter(iter: I) -> String` ### Type Parameters - `'a`: Lifetime parameter - `I`: IntoIterator> ### Availability Available on **non-`no_global_oom_handling`** only. ``` ```APIDOC ## FromIterator for String ### Description Creates a String from an iterator of `String`. ### Method `from_iter(iter: I) -> String` ### Type Parameters - `I`: IntoIterator ### Availability Available on **non-`no_global_oom_handling`** only. ``` ```APIDOC ## FromIterator for String ### Description Creates a String from an iterator of `char`. ### Method `from_iter(iter: I) -> String` ### Type Parameters - `I`: IntoIterator ### Availability Available on **non-`no_global_oom_handling`** only. ``` -------------------------------- ### default_db_path Source: https://docs.rs/imessage-database/latest/imessage_database/util/dirs/fn.default_db_path.html Get the default path the macOS iMessage database is located at (macOS only). ```APIDOC ## default_db_path ### Description Get the default path the macOS iMessage database is located at (macOS only) ### Signature ```rust pub fn default_db_path() -> PathBuf ``` ### Example ```rust use imessage_database::util::dirs::default_db_path; let path = default_db_path(); println!("{path:?}"); ``` ``` -------------------------------- ### Implement Equivalent for Q Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/handwriting/models/struct.Point.html Checks if a value is equivalent to a given key. ```rust fn equivalent(&self, key: &K) -> bool ``` ```rust fn equivalent(&self, key: &K) -> bool ``` -------------------------------- ### from_cli Source: https://docs.rs/imessage-database/latest/imessage_database/util/platform/enum.Platform.html Converts a string input from the command line into a Platform variant if it matches. ```APIDOC ## Function: from_cli ### Description Given user’s input, return a variant if the input matches one. ### Signature `pub fn from_cli(platform: &str) -> Option` ### Parameters * `platform` (&str): The string input representing the platform. ``` -------------------------------- ### home() Source: https://docs.rs/imessage-database/latest/imessage_database/util/dirs/fn.home.html Retrieves the user's home directory. This function is macOS specific. ```APIDOC ## home() ### Description Get the user’s home directory (macOS only) ### Signature ```rust pub fn home() -> String ``` ### Example ```rust use imessage_database::util::dirs::home; let path = home(); println!("{path}"); ``` ``` -------------------------------- ### Get Attachment Filename Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Provides a suitable filename for an attachment, prioritizing `transfer_name` over `filename`. ```rust pub fn filename(&self) -> Option<&str> ``` -------------------------------- ### Get String Slice Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Extracts a string slice (&str) representing the entire content of the String. ```rust let s = String::from("foo"); assert_eq!("foo", s.as_str()); ``` -------------------------------- ### Debug and Display Formatting Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html This section details the implementation of the `Debug` and `Display` traits for `String`, allowing for formatted output. ```APIDOC ## `Debug` for `String` ### `fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>` Formats the value using the given formatter. ## `Display` for `String` ### `fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>` Formats the value using the given formatter. ``` -------------------------------- ### Get BLOB from Attachment Table Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Retrieves a BLOB from a specified table and column for a given rowid. ```rust fn get_blob<'a>( &self, db: &'a Connection, table: &str, column: &str, rowid: i64, ) -> Option> ``` -------------------------------- ### String Reservation with Existing Capacity Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Demonstrates that calling `reserve` might not increase capacity if sufficient space is already allocated. This is useful for understanding how `reserve` behaves when the string already has ample room. ```rust let mut s = String::with_capacity(10); s.push('a'); s.push('b'); // s now has a length of 2 and a capacity of at least 10 let capacity = s.capacity(); assert_eq!(2, s.len()); assert!(capacity >= 10); // Since we already have at least an extra 8 capacity, calling this... s.reserve(8); // ... doesn't actually increase. assert_eq!(capacity, s.capacity()); ``` -------------------------------- ### Parse and Apply Message Body Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/struct.ParsedBody.html Demonstrates how to parse a message body using `Message::parse_body()` and then apply the parsed body back to the message using `Message::apply_body()`. ```rust if let Ok(body) = message.parse_body(&conn) { message.apply_body(body); } ``` -------------------------------- ### Get Total Attachment Bytes Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Calculates the sum of all attachment bytes referenced in the attachment table. ```rust pub fn get_total_attachment_bytes( db: &Connection, context: &QueryContext, ) -> Result ``` -------------------------------- ### Get Attachment Filename Extension Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Extracts the file extension from an attachment's filename, if available. ```rust pub fn extension(&self) -> Option<&str> ``` -------------------------------- ### Implement Default for Placemark Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/placemark/struct.Placemark.html Provides a default value for the Placemark struct. This is useful for initializing a Placemark without specifying all fields. ```rust impl<'a> Default for Placemark<'a> Source§ #### fn default() -> Placemark<'a> Returns the “default value” for a type. Read more ``` -------------------------------- ### Get Attachments from Message Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Retrieves all attachments associated with a specific message, maintaining their original order. ```rust pub fn from_message( db: &Connection, msg: &Message, ) -> Result, TableError> ``` -------------------------------- ### Default Platform Source: https://docs.rs/imessage-database/latest/imessage_database/util/platform/enum.Platform.html Specifies the default platform, which is macOS. ```APIDOC ## Trait Implementation: Default for Platform ### Description The default Platform is `Platform::macOS`. ### Method `fn default() -> Self` ``` -------------------------------- ### String Conversion and Manipulation Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html This section covers methods for converting a String to a reference, borrowing, cloning, and extending the String with various character and string types. ```APIDOC ## `AsRef` for `String` ### `fn as_ref(&self) -> &str` Converts this type into a shared reference of the (usually inferred) input type. ## `Borrow` for `String` ### `fn borrow(&self) -> &str` Immutably borrows from an owned value. ## `BorrowMut` for `String` ### `fn borrow_mut(&mut self) -> &mut str` Mutably borrows from an owned value. ## `Clone` for `String` ### `fn clone_from(&mut self, source: &String)` Clones the contents of `source` into `self`. This method is preferred over simply assigning `source.clone()` to `self`, as it avoids reallocation if possible. ### `fn clone(&self) -> String` Returns a duplicate of the value. ## `Default` for `String` ### `fn default() -> String` Creates an empty `String`. ## `Deref` for `String` ### `type Target = str` The resulting type after dereferencing. ### `fn deref(&self) -> &str` Dereferences the value. ## `DerefMut` for `String` ### `fn deref_mut(&mut self) -> &mut str` Mutably dereferences the value. ## `Extend<&'a AsciiChar>` for `String` ### `fn extend(&mut self, iter: I)` where I: IntoIterator, Extends a collection with the contents of an iterator. ### `fn extend_one(&mut self, c: &'a AsciiChar)` Extends a collection with exactly one element. ### `fn extend_reserve(&mut self, additional: usize)` Reserves capacity in a collection for the given number of additional elements. ## `Extend<&'a char>` for `String` ### `fn extend(&mut self, iter: I)` where I: IntoIterator, Extends a collection with the contents of an iterator. ### `fn extend_one(&mut self, _: &'a char)` Extends a collection with exactly one element. ### `fn extend_reserve(&mut self, additional: usize)` Reserves capacity in a collection for the given number of additional elements. ## `Extend<&'a str>` for `String` ### `fn extend(&mut self, iter: I)` where I: IntoIterator, Extends a collection with the contents of an iterator. ### `fn extend_one(&mut self, s: &'a str)` Extends a collection with exactly one element. ### `fn extend_reserve(&mut self, additional: usize)` Reserves capacity in a collection for the given number of additional elements. ## `Extend>` for `String` ### `fn extend(&mut self, iter: I)` where I: IntoIterator>, Extends a collection with the contents of an iterator. ### `fn extend_one(&mut self, item: A)` Extends a collection with exactly one element. ### `fn extend_reserve(&mut self, additional: usize)` Reserves capacity in a collection for the given number of additional elements. ## `Extend` for `String` ### `fn extend(&mut self, iter: I)` where I: IntoIterator, Extends a collection with the contents of an iterator. ### `fn extend_one(&mut self, c: AsciiChar)` Extends a collection with exactly one element. ``` -------------------------------- ### Get Chat Service Source: https://docs.rs/imessage-database/latest/imessage_database/tables/chat/struct.Chat.html Retrieves the service associated with the chat (e.g., iMessage, SMS, IRC). ```rust pub fn service(&self) -> Service<'_> ``` -------------------------------- ### CloneToUninit Trait Implementation (Nightly) Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/models/struct.AttachmentMeta.html Nightly-only experimental API for performing copy-assignment to uninitialized memory. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Get Chat Display Name Source: https://docs.rs/imessage-database/latest/imessage_database/tables/chat/struct.Chat.html Retrieves the current display name for the chat, if one has been set. ```rust pub fn display_name(&self) -> Option<&str> ``` -------------------------------- ### get_url Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/url/struct.URLMessage.html Gets the redirected URL from a URL message, falling back to the original URL if necessary. ```APIDOC ## Method get_url ### Description Get the redirected URL from a URL message, falling back to the original URL, if it exists. ### Signature `pub fn get_url(&self) -> Option<&str>` ### Returns - `Option<&str>`: The redirected URL or the original URL if the redirected URL is not available. ``` -------------------------------- ### Index Implementations for String Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Allows indexing into a String. ```APIDOC ## Index for String ### Description Allows indexing into a String. ### Method `index(&self, index: I) -> &>::Output` ### Type Parameters - `I`: SliceIndex ### Type Alias `Output = >::Output` ``` ```APIDOC ## IndexMut for String ### Description Allows mutable indexing into a String. ### Method `index_mut(&mut self, index: I) -> &mut >::Output` ### Type Parameters - `I`: SliceIndex ``` -------------------------------- ### Get URLMessage Override Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/url/struct.URLMessage.html Retrieves the subtype of a URL message from a payload. This function is part of the URLMessage implementation. ```rust pub fn get_url_message_override( payload: &'a Value, ) -> Result, PlistParseError> ``` -------------------------------- ### Iterate Over iMessage Database Messages Source: https://docs.rs/imessage-database/latest/imessage_database/index.html Demonstrates how to establish a read-only connection to an iMessage database and stream messages. It includes parsing message bodies and applying them, with error handling for both the stream and individual messages. ```rust use imessage_database:: error::table::TableError, tables:: messages::Message, table::{get_connection, Table}, util::dirs::default_db_path, }; fn iter_messages() -> Result<(), TableError> { // Create a read-only connection to an iMessage database let db = get_connection(&default_db_path()).unwrap(); // Iterate over a stream of messages Message::stream(&db, |message_result| { match message_result { Ok(mut message) => { // Deserialize the message body if let Ok(body) = message.parse_body(&db) { message.apply_body(body); } // Emit debug info for each message println!("Message: {:#?}", message) }, Err(e) => eprintln!("Error: {:?}", e), }; // You can substitute your own closure error type Ok::<(), TableError>(()) })?; Ok(()) } ``` -------------------------------- ### Get Collaboration URL Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/collaboration/struct.CollaborationMessage.html Retrieves the collaboration URL, with a fallback to the original URL if the collaboration URL is not present. ```rust pub fn get_url(&self) -> Option<&str> ``` -------------------------------- ### String Exact Reservation with Existing Capacity Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Illustrates that `reserve_exact` may not change capacity if the current allocation already meets or exceeds the requested minimum. This highlights the behavior of exact reservation when sufficient capacity exists. ```rust let mut s = String::with_capacity(10); s.push('a'); s.push('b'); // s now has a length of 2 and a capacity of at least 10 let capacity = s.capacity(); assert_eq!(2, s.len()); assert!(capacity >= 10); // Since we already have at least an extra 8 capacity, calling this... s.reserve_exact(8); // ... doesn't actually increase. assert_eq!(capacity, s.capacity()); ``` -------------------------------- ### Get Number of Missing Files Source: https://docs.rs/imessage-database/latest/imessage_database/tables/diagnostic/struct.AttachmentDiagnostic.html Returns the count of attachments where a path was specified but the file could not be found on disk. ```rust pub fn no_file_located(&self) -> usize ``` -------------------------------- ### Error::provide (Nightly Experimental) Source: https://docs.rs/imessage-database/latest/imessage_database/error/attachment/enum.AttachmentError.html Nightly-only experimental API for providing type-based access to error context, intended for error reporting tools. ```rust fn provide<'a>(&'a self, request: &mut Request<'a>) ``` -------------------------------- ### Get Number of Editable/Unsent Parts Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/edited/struct.EditedMessage.html Returns the total count of message parts that could potentially be edited or unsent. ```rust pub fn items(&self) -> usize ``` -------------------------------- ### Error::cause (Deprecated) Source: https://docs.rs/imessage-database/latest/imessage_database/error/attachment/enum.AttachmentError.html Deprecated method for getting the cause of the error. Use `Error::source` which supports downcasting. ```rust fn cause(&self) -> Option<&dyn Error> ``` -------------------------------- ### Get Mutable String Slice Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Converts a String into a mutable string slice (&mut str), allowing in-place modifications. ```rust let mut s = String::from("foobar"); let s_mut_str = s.as_mut_str(); s_mut_str.make_ascii_uppercase(); assert_eq!("FOOBAR", s_mut_str); ``` -------------------------------- ### Get Message Count Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/struct.Message.html Retrieves the total number of messages stored in the database. Requires a database connection and query context. ```rust use imessage_database::util::dirs::default_db_path; use imessage_database::tables::table::get_connection; use imessage_database::tables::messages::Message; use imessage_database::util::query_context::QueryContext; let db_path = default_db_path(); let conn = get_connection(&db_path).unwrap(); let context = QueryContext::default(); Message::get_count(&conn, &context); ``` -------------------------------- ### Get Value from Dictionary Source: https://docs.rs/imessage-database/latest/imessage_database/util/plist/fn.get_value_from_dict.html Extracts a value from a dictionary-like structure using a specified key. Returns None if the key is not found. ```rust pub fn get_value_from_dict<'a>( payload: &'a Value, key: &'a str, ) -> Option<&'a Value> ``` -------------------------------- ### Get Default iMessage DB Path Source: https://docs.rs/imessage-database/latest/imessage_database/util/dirs/fn.default_db_path.html Retrieves the default path to the macOS iMessage database. This function is specific to macOS. ```rust use imessage_database::util::dirs::default_db_path; let path = default_db_path(); println!("{path:?}"); ``` -------------------------------- ### String Write Implementations Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Provides methods for writing string slices and characters into a String, useful for building strings incrementally. ```APIDOC ### impl Write for String Available on **non-`no_global_oom_handling`** only. #### fn write_str(&mut self, s: &str) -> Result<(), Error> Writes a string slice into this writer, returning whether the write succeeded. Read more #### fn write_char(&mut self, c: char) -> Result<(), Error> Writes a `char` into this writer, returning whether the write succeeded. Read more #### fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error> Glue for usage of the `write!` macro with implementors of this trait. Read more ``` -------------------------------- ### Error::description (Deprecated) Source: https://docs.rs/imessage-database/latest/imessage_database/error/attachment/enum.AttachmentError.html Deprecated method for getting a string description of the error. Use the Display implementation or `to_string()` instead. ```rust fn description(&self) -> &str ``` -------------------------------- ### Implement Debug for Placemark Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/placemark/struct.Placemark.html Provides a way to format the Placemark struct for debugging purposes. This allows the struct to be printed in a human-readable format during development. ```rust impl<'a> Debug for Placemark<'a> Source§ #### fn fmt(&self, f: &mut Formatter<'_>) -> Result Formats the value using the given formatter. Read more ``` -------------------------------- ### Convert Key to String Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Converts a Key type into a String. ```rust fn from(key: Key) -> String ``` -------------------------------- ### Get Sticker Source from Attachment Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Parses a sticker's source from the Bundle ID in STICKER_USER_INFO plist data. This operation is database-intensive. ```rust pub fn get_sticker_source(&self, db: &Connection) -> Option ``` -------------------------------- ### Create an empty String Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Use String::new() to create a new, empty String. This method does not allocate an initial buffer, which can be efficient but may lead to reallocations later. ```rust let s = String::new(); ``` -------------------------------- ### PartialEq Implementations for String Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Provides equality comparisons for String with various types. ```APIDOC ## PartialEq<&str> for String ### Description Tests for equality between String and &str. ### Methods - `eq(&self, other: &&str) -> bool` - `ne(&self, other: &&str) -> bool` ``` ```APIDOC ## PartialEq for String ### Description Tests for equality between String and ByteStr. ### Methods - `eq(&self, other: &ByteStr) -> bool` - `ne(&self, other: &Rhs) -> bool` ``` ```APIDOC ## PartialEq for String ### Description Tests for equality between String and ByteString. ### Methods - `eq(&self, other: &ByteString) -> bool` - `ne(&self, other: &Rhs) -> bool` ``` ```APIDOC ## PartialEq> for String ### Description Tests for equality between String and Cow<'_, str>. ### Methods - `eq(&self, other: &Cow<'_, str>) -> bool` - `ne(&self, other: &Cow<'_, str>) -> bool` ``` -------------------------------- ### Get Sticker Effect Source: https://docs.rs/imessage-database/latest/imessage_database/tables/attachment/struct.Attachment.html Determines the StickerEffect for a sticker attachment. Requires the platform, database path, and an optional custom attachment root. ```rust pub fn get_sticker_effect( &self, platform: &Platform, db_path: &Path, custom_attachment_root: Option<&str>, ) -> Result, AttachmentError> ``` -------------------------------- ### Implement StructuralPartialEq for Placemark Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/placemark/struct.Placemark.html Enables structural equality comparisons for the Placemark struct. This is often used in testing and serialization contexts. ```rust impl<'a> StructuralPartialEq for Placemark<'a> ``` -------------------------------- ### AttachmentMeta Struct Definition Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/models/struct.AttachmentMeta.html Defines the structure for attachment metadata, including optional fields for GUID, transcription, height, width, and name. ```rust pub struct AttachmentMeta { pub guid: Option, pub transcription: Option, pub height: Option, pub width: Option, pub name: Option, } ``` -------------------------------- ### Implement PartialEq for Point Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/handwriting/models/struct.Point.html Enables comparison of two Point instances for equality. ```rust fn eq(&self, other: &Point) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### QueryContext Struct Definition Source: https://docs.rs/imessage-database/latest/imessage_database/util/query_context/struct.QueryContext.html Defines the structure for query filtering, including optional start and end dates, and sets of handle and chat IDs. ```rust pub struct QueryContext { pub start: Option, pub end: Option, pub selected_handle_ids: Option>, pub selected_chat_ids: Option>, } ``` -------------------------------- ### Message Status Checks Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/struct.Message.html Methods to check the status of a message, such as whether the sender started or stopped sharing their location, or if the message has been deleted or translated. ```APIDOC ## started_sharing_location ### Description Checks if the message indicates that the sender started sharing their location. ### Method `started_sharing_location(&self) -> bool` ### Returns `true` if the sender started sharing their location, `false` otherwise. ``` ```APIDOC ## stopped_sharing_location ### Description Checks if the message indicates that the sender stopped sharing their location. ### Method `stopped_sharing_location(&self) -> bool` ### Returns `true` if the sender stopped sharing their location, `false` otherwise. ``` ```APIDOC ## is_deleted ### Description Checks if the message was deleted and is recoverable. Deleted messages are moved to a separate collection for up to 30 days. ### Method `is_deleted(&self) -> bool` ### Returns `true` if the message is deleted and recoverable, `false` otherwise. ``` ```APIDOC ## has_translation ### Description Checks if the message has been translated. This method only works on iOS 16+ databases. ### Method `has_translation(&self, db: &Connection) -> bool` ### Parameters * `db` (&Connection) - A reference to the database connection. ### Returns `true` if the message was translated, `false` otherwise. ``` -------------------------------- ### as_unsigned_integer Source: https://docs.rs/imessage-database/latest/imessage_database/util/typedstream/fn.as_unsigned_integer.html Converts a `Property` to an `Option` if it is an unsigned integer or similar structure. ```APIDOC ## Function as_unsigned_integer ### Signature ```rust pub fn as_unsigned_integer<'a>(property: &'a Property<'a, 'a>) -> Option ``` ### Description Converts a `Property` to an `Option` if it is an unsigned integer or similar structure. ``` -------------------------------- ### Try Reserving Exact String Capacity Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Tries to reserve the minimum capacity for at least `additional` bytes more than the current length, returning a `Result`. Unlike `try_reserve`, this will not deliberately over-allocate. After calling `try_reserve_exact`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Note that the allocator may give the collection more space than it requests. ```rust use std::collections::TryReserveError; fn process_data(data: &str) -> Result { let mut output = String::new(); // Pre-reserve the memory, exiting if we can't output.try_reserve_exact(data.len())?; // Now we know this can't OOM in the middle of our complex work output.push_str(data); Ok(output) } ``` -------------------------------- ### Get Raw Payload Data Source: https://docs.rs/imessage-database/latest/imessage_database/tables/messages/message/struct.Message.html Retrieves the raw data from the MESSAGE_PAYLOAD BLOB column. This is a database-intensive operation. This data is specifically used for HandwrittenMessages. ```rust pub fn raw_payload_data(&self, db: &Connection) -> Option> ``` -------------------------------- ### try_reserve_exact Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html Tries to reserve the minimum capacity for at least `additional` bytes more than the current length. Unlike `try_reserve`, this will not deliberately over-allocate to speculatively avoid frequent allocations. ```APIDOC ## pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError> ### Description Tries to reserve the minimum capacity for at least `additional` bytes more than the current length. Unlike `try_reserve`, this will not deliberately over-allocate to speculatively avoid frequent allocations. After calling `try_reserve_exact`, capacity will be greater than or equal to `self.len() + additional` if it returns `Ok(())`. Does nothing if the capacity is already sufficient. Note that the allocator may give the collection more space than it requests. Therefore, capacity can not be relied upon to be precisely minimal. Prefer `try_reserve` if future insertions are expected. ### Errors If the capacity overflows, or the allocator reports a failure, then an error is returned. ### Examples ```rust use std::collections::TryReserveError; fn process_data(data: &str) -> Result { let mut output = String::new(); // Pre-reserve the memory, exiting if we can't output.try_reserve_exact(data.len())?; // Now we know this can't OOM in the middle of our complex work output.push_str(data); Ok(output) } ``` ``` -------------------------------- ### Deserialization Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/polls/type.PollOptionID.html This section covers the implementation of the `Deserialize` trait for `String`, enabling deserialization from Serde deserializers. ```APIDOC ## `Deserialize<'de>` for `String` ### `fn deserialize(deserializer: D) -> Result>::Error>` where D: Deserializer<'de>, Deserialize this value from the given Serde deserializer. ``` -------------------------------- ### get_db_size Source: https://docs.rs/imessage-database/latest/imessage_database/tables/table/fn.get_db_size.html Get the size of the database on the disk. It takes a path to the database file and returns the size in bytes as a u64, or a TableError if an issue occurs. ```APIDOC ## Function get_db_size ### Description Get the size of the database on the disk. ### Signature ```rust pub fn get_db_size(path: &Path) -> Result ``` ### Parameters * **path** (*&Path*) - The path to the database file. ### Returns * `Result` - Returns the size of the database in bytes as a `u64` on success, or a `TableError` on failure. ### Example ```rust use imessage_database::{ util::dirs::default_db_path, tables::table::get_db_size }; let db_path = default_db_path(); let database_size_in_bytes = get_db_size(&db_path); ``` ``` -------------------------------- ### Implement Equivalent for Q, K Source: https://docs.rs/imessage-database/latest/imessage_database/message_types/placemark/struct.Placemark.html Checks for equivalence between two types, where one can be borrowed as the other. This is useful for lookups in collections. ```rust impl Equivalent for Q where Q: Eq + ?Sized, K: Borrow + ?Sized, Source§ #### fn equivalent(&self, key: &K) -> bool Checks if this value is equivalent to the given key. Read more ``` ```rust Compare self to `key` and return `true` if they are equal. ``` -------------------------------- ### as_signed_integer Source: https://docs.rs/imessage-database/latest/imessage_database/util/typedstream/fn.as_signed_integer.html Converts a `Property` to an `Option` if it is a signed integer or similar structure. ```APIDOC ## Function as_signed_integer ### Description Converts a `Property` to an `Option` if it is a signed integer or similar structure. ### Signature ```rust pub fn as_signed_integer(property: &Property<'_, '_>) -> Option ``` ```