1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::collections::HashMap;
use rusqlite::{Connection, Error, OpenFlags, Result, Row, Statement};
use crate::error::table::TableError;
pub trait Table {
fn from_row(row: &Row) -> Result<Self>
where
Self: Sized;
fn get(db: &Connection) -> Statement;
fn extract(item: Result<Result<Self, Error>, Error>) -> Result<Self, TableError>
where
Self: Sized;
}
pub trait Cacheable {
type K;
type V;
fn cache(db: &Connection) -> Result<HashMap<Self::K, Self::V>, TableError>;
}
pub trait Deduplicate {
type T;
fn dedupe(duplicated_data: &HashMap<i32, Self::T>) -> HashMap<i32, i32>;
}
pub trait Diagnostic {
fn run_diagnostic(db: &Connection);
}
pub fn get_connection(path: &str) -> Connection {
match Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_ONLY) {
Ok(res) => res,
Err(why) => panic!("Unable to read from chat database: {}\nEnsure full disk access is enabled for your terminal emulator in System Preferences > Security and Privacy > Full Disk Access", why),
}
}
pub const HANDLE: &str = "handle";
pub const MESSAGE: &str = "message";
pub const CHAT: &str = "chat";
pub const ATTACHMENT: &str = "attachment";
pub const CHAT_MESSAGE_JOIN: &str = "chat_message_join";
pub const MESSAGE_ATTACHMENT_JOIN: &str = "message_attachment_join";
pub const CHAT_HANDLE_JOIN: &str = "chat_handle_join";
pub const MESSAGE_PAYLOAD: &str = "payload_data";
pub const MESSAGE_SUMMARY_INFO: &str = "message_summary_info";
pub const ATTRIBUTED_BODY: &str = "attributedBody";
pub const ME: &str = "Me";
pub const UNKNOWN: &str = "Unknown";
pub const DEFAULT_PATH: &str = "Library/Messages/chat.db";
pub const ORPHANED: &str = "orphaned";
pub const DEFAULT_OUTPUT_DIR: &str = "imessage_export";
pub const MAX_LENGTH: usize = 240;
pub const FITNESS_RECEIVER: &str = "$(kIMTranscriptPluginBreadcrumbTextReceiverIdentifier)";