@@ -307,8 +307,8 @@ impl MessageParts {
307307 msg
308308 }
309309
310- fn to_sms ( & self , using_number : & str , mms : bool ) -> ( String , Vec < RawSmsIncomingMessageData > ) {
311- let mut parts = vec ! [ format!( "s:{}" , using_number ) ] ;
310+ fn to_sms ( & self , from_handle : & str , mms : bool ) -> ( String , Vec < RawSmsIncomingMessageData > ) {
311+ let mut parts = vec ! [ format!( "s:{}" , from_handle ) ] ;
312312 let mut out = vec ! [ ] ;
313313 if !mms {
314314 parts. push ( "(null)(0)" . to_string ( ) ) ;
@@ -360,13 +360,7 @@ impl MessageParts {
360360 }
361361
362362 fn parse_sms ( raw : & RawSmsIncomingMessage ) -> MessageParts {
363- MessageParts ( raw. format . split ( "|" ) . skip ( 1 ) . enumerate ( ) . map ( |( idx, part) | {
364- let corresponding = if part. starts_with ( "(null)" ) {
365- raw. content . iter ( ) . find ( |i| i. content_id . is_none ( ) ) . unwrap ( )
366- } else {
367- let filename = part. split ( "(" ) . next ( ) . unwrap ( ) ;
368- raw. content . iter ( ) . find ( |i| i. content_location . as_ref ( ) . map ( |i| i. as_str ( ) ) == Some ( filename) ) . unwrap ( )
369- } ;
363+ fn parse_data ( idx : usize , corresponding : & RawSmsIncomingMessageData ) -> IndexedMessagePart {
370364 let typ = if corresponding. mime_type == "text/plain" {
371365 MessagePart :: Text ( String :: from_utf8 ( corresponding. data . clone ( ) . into ( ) ) . unwrap ( ) , Default :: default ( ) )
372366 } else {
@@ -384,7 +378,21 @@ impl MessageParts {
384378 idx : None ,
385379 ext : None
386380 }
387- } ) . collect ( ) )
381+ }
382+
383+ if raw. format . starts_with ( "s:" ) {
384+ MessageParts ( raw. format . split ( "|" ) . skip ( 1 ) . enumerate ( ) . map ( |( idx, part) | {
385+ let corresponding = if part. starts_with ( "(null)" ) {
386+ raw. content . iter ( ) . find ( |i| i. content_id . is_none ( ) ) . unwrap ( )
387+ } else {
388+ let filename = part. split ( "(" ) . next ( ) . unwrap ( ) ;
389+ raw. content . iter ( ) . find ( |i| i. content_location . as_ref ( ) . map ( |i| i. as_str ( ) ) == Some ( filename) ) . unwrap ( )
390+ } ;
391+ parse_data ( idx, corresponding)
392+ } ) . collect ( ) )
393+ } else {
394+ MessageParts ( raw. content . iter ( ) . enumerate ( ) . map ( |( idx, part) | parse_data ( idx, part) ) . collect ( ) )
395+ }
388396 }
389397
390398 // parse XML parts
@@ -1539,13 +1547,23 @@ impl Message {
15391547 pub fn get_c ( & self ) -> u8 {
15401548 match self {
15411549 Self :: Message ( msg) => {
1542- match msg. service {
1550+ match & msg. service {
15431551 MessageType :: IMessage => 100 ,
1544- MessageType :: SMS { is_phone : _, using_number : _, from_handle : _ } => {
1545- if msg. parts . has_attachments ( ) {
1546- 144
1552+ MessageType :: SMS { is_phone : _, using_number : _, from_handle } => {
1553+ if let Some ( _) = from_handle {
1554+ // forwarded message
1555+ if msg. parts . has_attachments ( ) {
1556+ 141
1557+ } else {
1558+ 140
1559+ }
15471560 } else {
1548- 143
1561+ // non-forwarded message
1562+ if msg. parts . has_attachments ( ) {
1563+ 144
1564+ } else {
1565+ 143
1566+ }
15491567 }
15501568 }
15511569 }
@@ -1621,6 +1639,9 @@ impl Message {
16211639 ( "gC" , Value :: Integer ( 70000 . into ( ) ) ) ,
16221640 ( "pID" , Value :: Dictionary ( Dictionary :: new ( ) ) ) ,
16231641 ] ) ,
1642+ Message :: Message ( NormalMessage { service : MessageType :: SMS { .. } , .. } ) => Dictionary :: from_iter ( [
1643+ ( "htu" , Value :: Boolean ( true ) ) ,
1644+ ] ) ,
16241645 _ => Default :: default ( ) ,
16251646 }
16261647 }
@@ -2179,7 +2200,7 @@ impl MessageInst {
21792200 . filter ( |p| * p != self . sender . as_ref ( ) . unwrap ( ) && * p != from_handle)
21802201 . map ( |p| p. replace ( "tel:" , "" ) ) . collect ( ) ;
21812202 let is_mms = my_participants. len ( ) > 1 || normal. parts . has_attachments ( ) ;
2182- let ( format, content) = normal. parts . to_sms ( & using_number , is_mms) ;
2203+ let ( format, content) = normal. parts . to_sms ( & from_handle , is_mms) ;
21832204 let raw = RawSmsIncomingMessage {
21842205 participants : if is_mms { my_participants } else { vec ! [ ] } ,
21852206 sender : from_handle. replace ( "tel:" , "" ) ,
@@ -2610,7 +2631,12 @@ impl MessageInst {
26102631 let mut msg = wrapper. to_message (
26112632 Some ( ConversationData {
26122633 participants : if loaded. participants . len ( ) > 0 {
2613- loaded. participants . iter ( ) . chain ( std:: iter:: once ( & loaded. sender ) ) . map ( |p| format ! ( "tel:{p}" ) ) . collect ( )
2634+ let mut participants = loaded. participants . clone ( ) ;
2635+ // duplicates cause chat matching in dart to fail (it is duplicate for RCS)
2636+ if !participants. contains ( & loaded. sender ) {
2637+ participants. push ( loaded. sender . clone ( ) ) ;
2638+ }
2639+ participants. iter ( ) . map ( |p| format ! ( "tel:{p}" ) ) . collect ( )
26142640 } else {
26152641 vec ! [ format!( "tel:{}" , loaded. sender) , format!( "tel:{}" , loaded. recieved_number) ]
26162642 } ,
@@ -2637,6 +2663,7 @@ impl MessageInst {
26372663 } )
26382664 ) ?;
26392665 msg. sent_timestamp = system_recv. duration_since ( UNIX_EPOCH ) . unwrap ( ) . as_millis ( ) as u64 ;
2666+ return Ok ( msg) ;
26402667 }
26412668 if let Ok ( loaded) = plist:: from_value :: < RawSmsOutgoingMessage > ( & value) {
26422669 let parts = loaded. message . xhtml . as_ref ( ) . map_or_else ( || {
0 commit comments