Attachment

Struct Attachment 

Source
pub struct Attachment {
    pub rowid: i32,
    pub filename: Option<String>,
    pub uti: Option<String>,
    pub mime_type: Option<String>,
    pub transfer_name: Option<String>,
    pub total_bytes: i64,
    pub is_sticker: bool,
    pub hide_attachment: i32,
    pub emoji_description: Option<String>,
    pub copied_path: Option<PathBuf>,
}
Expand description

Represents a single row in the attachment table.

Fields§

§rowid: i32

The unique identifier for the attachment in the database

§filename: Option<String>

The path to the file on disk

§uti: Option<String>§mime_type: Option<String>

String representation of the file’s MIME type

§transfer_name: Option<String>

The name of the file when sent or received

§total_bytes: i64

The total amount of data transferred over the network (not necessarily the size of the file)

§is_sticker: bool

true if the attachment was a sticker, else false

§hide_attachment: i32

Flag indicating whether the attachment should be hidden in the UI

§emoji_description: Option<String>

The prompt used to generate a Genmoji

§copied_path: Option<PathBuf>

Auxiliary data to denote that an attachment has been copied

Implementations§

Source§

impl Attachment

Source

pub fn from_message( db: &Connection, msg: &Message, ) -> Result<Vec<Attachment>, TableError>

Gets a Vector of attachments associated with a single message

The order of the attachments aligns with the order of the BubbleComponent::Attachments in the message’s body().

Source

pub fn mime_type(&self) -> MediaType<'_>

Get the media type of an attachment

Source

pub fn as_bytes( &self, platform: &Platform, db_path: &Path, custom_attachment_root: Option<&str>, ) -> Result<Option<Vec<u8>>, AttachmentError>

Read the attachment from the disk into a vector of bytes in memory

db_path is the path to the root of the backup directory. This is the same path used by get_connection().

Source

pub fn get_sticker_effect( &self, platform: &Platform, db_path: &Path, custom_attachment_root: Option<&str>, ) -> Result<Option<StickerEffect>, AttachmentError>

Determine the StickerEffect of a sticker message

db_path is the path to the root of the backup directory. This is the same path used by get_connection().

Source

pub fn path(&self) -> Option<&Path>

Get the path to an attachment, if it exists

Source

pub fn extension(&self) -> Option<&str>

Get the file name extension of an attachment, if it exists

Source

pub fn filename(&self) -> Option<&str>

Get a reasonable filename for an attachment

If the transfer_name field is populated, use that. If it is not present, fall back to the filename field.

Source

pub fn file_size(&self) -> String

Get a human readable file size for an attachment using format_file_size

Source

pub fn get_total_attachment_bytes( db: &Connection, context: &QueryContext, ) -> Result<u64, TableError>

Get the total attachment bytes referenced in the table

Source

pub fn resolved_attachment_path( &self, platform: &Platform, db_path: &Path, custom_attachment_root: Option<&str>, ) -> Option<String>

Given a platform and database source, resolve the path for the current attachment

For macOS, db_path is unused. For iOS, db_path is the path to the root of the backup directory. This is the same path used by get_connection().

On iOS, file names are derived from SHA-1 hash of MediaDomain- concatenated with the relative self.filename(). Between the domain and the path there is a dash. Read more here.

Use the optional custom_attachment_root parameter when the attachments are not stored in the same place as the database expects.The expected location is DEFAULT_ATTACHMENT_ROOT. A custom attachment root like /custom/path will overwrite a path like ~/Library/Messages/Attachments/3d/... to /custom/path/3d/...

Source

pub fn run_diagnostic( db: &Connection, db_path: &Path, platform: &Platform, ) -> Result<(), TableError>

Emit diagnostic data for the Attachments table

This is defined outside of Diagnostic because it requires additional data.

Get the number of attachments that are missing, either because the path is missing from the table or the path does not point to a file.

§Example:
use imessage_database::util::{dirs::default_db_path, platform::Platform};
use imessage_database::tables::table::{Diagnostic, get_connection};
use imessage_database::tables::attachment::Attachment;

let db_path = default_db_path();
let conn = get_connection(&db_path).unwrap();
Attachment::run_diagnostic(&conn, &db_path, &Platform::macOS);

db_path is the path to the root of the backup directory. This is the same path used by get_connection().

Source

pub fn get_sticker_source(&self, db: &Connection) -> Option<StickerSource>

Parse a sticker’s source from the Bundle ID stored in STICKER_USER_INFO plist data

Calling this hits the database, so it is expensive and should only get invoked when needed.

Source

pub fn get_sticker_source_application_name( &self, db: &Connection, ) -> Option<String>

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.

Trait Implementations§

Source§

impl Debug for Attachment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Table for Attachment

Source§

fn from_row(row: &Row<'_>) -> Result<Attachment>

Deserialize a single row into Self, returning a rusqlite::Result
Source§

fn get(db: &Connection) -> Result<CachedStatement<'_>, TableError>

Prepare SELECT * statement
Source§

fn extract( attachment: Result<Result<Self, Error>, Error>, ) -> Result<Self, TableError>

Map a rusqlite::Result<Self> into our TableError
Source§

fn stream<F, E>(db: &Connection, callback: F) -> Result<(), TableError>
where F: FnMut(Result<Self, TableError>) -> Result<(), E>,

Process all rows from the table using a callback. This is the most memory-efficient approach for large tables. Read more
Source§

fn get_blob<'a>( &self, db: &'a Connection, table: &str, column: &str, rowid: i64, ) -> Option<Blob<'a>>

Get a BLOB from the table Read more
Source§

fn has_blob( &self, db: &Connection, table: &str, column: &str, rowid: i64, ) -> bool

Check if a BLOB exists in the table

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.