Skip to main content

imessage_database/tables/messages/models/
attachment_meta.rs

1/*!
2 Attachment metadata carried on a body range.
3*/
4
5use crabstep::deserializer::iter::Property;
6
7/// Attachment metadata attached to a body range.
8#[derive(Debug, PartialEq, Default, Clone)]
9pub struct AttachmentMeta {
10    /// GUID of the attachment row.
11    pub guid: Option<String>,
12    /// Audio transcription stored on the attributed range.
13    pub transcription: Option<String>,
14    /// Inline media height in points.
15    pub height: Option<f64>,
16    /// Inline media width in points.
17    pub width: Option<f64>,
18    /// Original attachment filename.
19    pub name: Option<String>,
20}
21
22impl AttachmentMeta {
23    /// Applies a single typedstream attribute key/value pair to the metadata,
24    /// ignoring any key that isn't attachment metadata. Driven per-key by the
25    /// body parser's `build_range`, which walks the full attribute dictionary
26    /// so non-attachment-meta keys on the same range are still processed.
27    pub(crate) fn set_from_key_value<'a>(&mut self, key: &str, value: &Property<'a, 'a>) {
28        match key {
29            "__kIMFileTransferGUIDAttributeName" => {
30                self.guid = value.as_string().map(String::from);
31            }
32            "IMAudioTranscription" => self.transcription = value.as_string().map(String::from),
33            "__kIMInlineMediaHeightAttributeName" => self.height = value.as_f64(),
34            "__kIMInlineMediaWidthAttributeName" => self.width = value.as_f64(),
35            "__kIMFilenameAttributeName" => self.name = value.as_string().map(String::from),
36            _ => {}
37        }
38    }
39}