Skip to content

Commit

Permalink
Merge pull request #213 from ReagentX/feat/cs/fix-rare-messages
Browse files Browse the repository at this point in the history
Feat/cs/fix rare messages
  • Loading branch information
ReagentX committed Nov 24, 2023
2 parents ba4e7db + cb95a99 commit 9bf81fa
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 31 deletions.
12 changes: 12 additions & 0 deletions imessage-database/src/message_types/handwriting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*!
Placeholder for currently unsupported handwritten iMessages
*/

/// Placeholder for currently unsupported [handwritten](https://support.apple.com/en-us/HT206894) iMessages
pub struct HandwrittenMessage {}

impl HandwrittenMessage {
pub fn new() -> Self {
Self {}
}
}
1 change: 1 addition & 0 deletions imessage-database/src/message_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ pub mod expressives;
pub mod music;
pub mod placemark;
pub mod sticker;
pub mod handwriting;
pub mod url;
pub mod variants;
5 changes: 3 additions & 2 deletions imessage-exporter/src/exporters/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use imessage_database::{
error::{message::MessageError, plist::PlistParseError, table::TableError},
message_types::{
app::AppMessage, app_store::AppStoreMessage, collaboration::CollaborationMessage,
music::MusicMessage, placemark::PlacemarkMessage, url::URLMessage,
handwriting::HandwrittenMessage, music::MusicMessage, placemark::PlacemarkMessage,
url::URLMessage,
},
tables::{attachment::Attachment, messages::Message},
};
Expand Down Expand Up @@ -66,7 +67,7 @@ pub(super) trait BalloonFormatter<T> {
/// Format a shared location message
fn format_placemark(&self, balloon: &PlacemarkMessage, indent: T) -> String;
/// Format a handwritten note message
fn format_handwriting(&self, balloon: &AppMessage, indent: T) -> String;
fn format_handwriting(&self, balloon: &HandwrittenMessage, indent: T) -> String;
/// Format an Apple Pay message
fn format_apple_pay(&self, balloon: &AppMessage, indent: T) -> String;
/// Format a Fitness message
Expand Down
43 changes: 26 additions & 17 deletions imessage-exporter/src/exporters/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use imessage_database::{
collaboration::CollaborationMessage,
edited::EditedMessage,
expressives::{BubbleEffect, Expressive, ScreenEffect},
handwriting::HandwrittenMessage,
music::MusicMessage,
placemark::PlacemarkMessage,
url::URLMessage,
Expand Down Expand Up @@ -282,21 +283,24 @@ impl<'a> Writer<'a> for HTML<'a> {
"",
);

// Render edited messages
if message.is_edited() {
let edited = match self.format_edited(message, "") {
Ok(s) => s,
Err(why) => format!("{}, {}", message.guid, why),
};
self.add_line(
&mut formatted_message,
&edited,
"<div class=\"edited\">",
"</div>",
);
continue;
}

match message_part {
BubbleType::Text(text) => {
// Render edited messages
if message.is_edited() {
let edited = match self.format_edited(message, "") {
Ok(s) => s,
Err(why) => format!("{}, {}", message.guid, why),
};
self.add_line(
&mut formatted_message,
&edited,
"<div class=\"edited\">",
"</div>",
);
} else if text.starts_with(FITNESS_RECEIVER) {
if text.starts_with(FITNESS_RECEIVER) {
self.add_line(
&mut formatted_message,
&text.replace(FITNESS_RECEIVER, YOU),
Expand Down Expand Up @@ -534,10 +538,14 @@ impl<'a> Writer<'a> for HTML<'a> {
if let Variant::App(balloon) = message.variant() {
let mut app_bubble = String::new();

if let Some(payload) = message.payload_data(&self.config.db) {
let parsed = parse_plist(&payload)?;
// Handwritten messages use a different payload type, so handle that first
if matches!(balloon, CustomBalloon::Handwriting) {
return Ok(self.format_handwriting(&HandwrittenMessage::new(), message));
}

if let Some(payload) = message.payload_data(&self.config.db) {
let res = if message.is_url() {
let parsed = parse_plist(&payload)?;
let bubble = URLMessage::get_url_message_override(&parsed)?;
match bubble {
URLOverride::Normal(balloon) => self.format_url(&balloon, message),
Expand All @@ -551,17 +559,18 @@ impl<'a> Writer<'a> for HTML<'a> {
}
}
} else {
let parsed = parse_plist(&payload)?;
match AppMessage::from_map(&parsed) {
Ok(bubble) => match balloon {
CustomBalloon::Application(bundle_id) => {
self.format_generic_app(&bubble, bundle_id, attachments, message)
}
CustomBalloon::Handwriting => self.format_handwriting(&bubble, message),
CustomBalloon::ApplePay => self.format_apple_pay(&bubble, message),
CustomBalloon::Fitness => self.format_fitness(&bubble, message),
CustomBalloon::Slideshow => self.format_slideshow(&bubble, message),
CustomBalloon::CheckIn => self.format_check_in(&bubble, message),
CustomBalloon::FindMy => self.format_find_my(&bubble, message),
CustomBalloon::Handwriting => unreachable!(),
CustomBalloon::URL => unreachable!(),
},
Err(why) => return Err(why),
Expand Down Expand Up @@ -1062,7 +1071,7 @@ impl<'a> BalloonFormatter<&'a Message> for HTML<'a> {
out_s
}

fn format_handwriting(&self, _: &AppMessage, _: &Message) -> String {
fn format_handwriting(&self, _: &HandwrittenMessage, _: &Message) -> String {
String::from("Handwritten messages are not yet supported!")
}

Expand Down
33 changes: 21 additions & 12 deletions imessage-exporter/src/exporters/txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use imessage_database::{
collaboration::CollaborationMessage,
edited::EditedMessage,
expressives::{BubbleEffect, Expressive, ScreenEffect},
handwriting::HandwrittenMessage,
music::MusicMessage,
placemark::PlacemarkMessage,
url::URLMessage,
Expand Down Expand Up @@ -182,17 +183,19 @@ impl<'a> Writer<'a> for TXT<'a> {

// Generate the message body from it's components
for (idx, message_part) in message_parts.iter().enumerate() {
// Render edited messages
if message.is_edited() {
let edited = match self.format_edited(message, &indent) {
Ok(s) => s,
Err(why) => format!("{}, {}", message.guid, why),
};
self.add_line(&mut formatted_message, &edited, &indent);
continue;
}
match message_part {
// Fitness messages have a prefix that we need to replace with the opposite if who sent the message
BubbleType::Text(text) => {
// Render edited messages
if message.is_edited() {
let edited = match self.format_edited(message, &indent) {
Ok(s) => s,
Err(why) => format!("{}, {}", message.guid, why),
};
self.add_line(&mut formatted_message, &edited, &indent);
} else if text.starts_with(FITNESS_RECEIVER) {
if text.starts_with(FITNESS_RECEIVER) {
self.add_line(
&mut formatted_message,
&text.replace(FITNESS_RECEIVER, YOU),
Expand Down Expand Up @@ -345,11 +348,15 @@ impl<'a> Writer<'a> for TXT<'a> {
if let Variant::App(balloon) = message.variant() {
let mut app_bubble = String::new();

if let Some(payload) = message.payload_data(&self.config.db) {
let parsed = parse_plist(&payload)?;
// Handwritten messages use a different payload type, so handle that first
if matches!(balloon, CustomBalloon::Handwriting) {
return Ok(self.format_handwriting(&HandwrittenMessage::new(), indent));
}

if let Some(payload) = message.payload_data(&self.config.db) {
// Handle URL messages separately since they are a special case
let res = if message.is_url() {
let parsed = parse_plist(&payload)?;
let bubble = URLMessage::get_url_message_override(&parsed)?;
match bubble {
URLOverride::Normal(balloon) => self.format_url(&balloon, indent),
Expand All @@ -362,19 +369,21 @@ impl<'a> Writer<'a> for TXT<'a> {
self.format_placemark(&balloon, indent)
}
}
// Handwriting uses a different payload type than the rest of the branches
} else {
// Handle the app case
let parsed = parse_plist(&payload)?;
match AppMessage::from_map(&parsed) {
Ok(bubble) => match balloon {
CustomBalloon::Application(bundle_id) => {
self.format_generic_app(&bubble, bundle_id, attachments, indent)
}
CustomBalloon::Handwriting => self.format_handwriting(&bubble, indent),
CustomBalloon::ApplePay => self.format_apple_pay(&bubble, indent),
CustomBalloon::Fitness => self.format_fitness(&bubble, indent),
CustomBalloon::Slideshow => self.format_slideshow(&bubble, indent),
CustomBalloon::CheckIn => self.format_check_in(&bubble, indent),
CustomBalloon::FindMy => self.format_find_my(&bubble, indent),
CustomBalloon::Handwriting => unreachable!(),
CustomBalloon::URL => unreachable!(),
},
Err(why) => return Err(why),
Expand Down Expand Up @@ -690,7 +699,7 @@ impl<'a> BalloonFormatter<&'a str> for TXT<'a> {
out_s.strip_suffix('\n').unwrap_or(&out_s).to_string()
}

fn format_handwriting(&self, _: &AppMessage, indent: &str) -> String {
fn format_handwriting(&self, _: &HandwrittenMessage, indent: &str) -> String {
format!("{indent}Handwritten messages are not yet supported!")
}

Expand Down

0 comments on commit 9bf81fa

Please sign in to comment.