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: u64,
pub is_sticker: bool,
pub hide_attachment: i32,
pub copied_path: Option<PathBuf>,
}Expand description
Represents a single row in the attachment table.
Fields§
§rowid: i32§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: u64The total amount of data transferred over the network (not necessarily the size of the file)
is_sticker: booltrue if the attachment was a sticker, else false
hide_attachment: i32§copied_path: Option<PathBuf>Auxiliary data to denote that an attachment has been copied
Implementations§
source§impl Attachment
impl Attachment
sourcepub fn from_message(
db: &Connection,
msg: &Message,
) -> Result<Vec<Attachment>, TableError>
pub fn from_message( db: &Connection, msg: &Message, ) -> Result<Vec<Attachment>, TableError>
Gets a Vector of attachments for a single message
sourcepub fn as_bytes(
&self,
platform: &Platform,
db_path: &Path,
custom_attachment_root: Option<&str>,
) -> Result<Option<Vec<u8>>, AttachmentError>
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().
sourcepub fn get_sticker_effect(
&self,
platform: &Platform,
db_path: &Path,
custom_attachment_root: Option<&str>,
) -> Result<Option<StickerEffect>, AttachmentError>
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().
sourcepub fn extension(&self) -> Option<&str>
pub fn extension(&self) -> Option<&str>
Get the file name extension of an attachment, if it exists
sourcepub fn filename(&self) -> &str
pub fn filename(&self) -> &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.
sourcepub fn get_total_attachment_bytes(
db: &Connection,
context: &QueryContext,
) -> Result<u64, TableError>
pub fn get_total_attachment_bytes( db: &Connection, context: &QueryContext, ) -> Result<u64, TableError>
Get the total attachment bytes referenced in the table
sourcepub fn resolved_attachment_path(
&self,
platform: &Platform,
db_path: &Path,
custom_attachment_root: Option<&str>,
) -> Option<String>
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/...
sourcepub fn run_diagnostic(
db: &Connection,
db_path: &Path,
platform: &Platform,
) -> Result<(), TableError>
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 from the filesystem or are missing one of the following columns:
ck_server_change_token_blobsr_ck_server_change_token_blob
§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().