diff --git a/src/location.rs b/src/location.rs index 488852140..bd12767dc 100644 --- a/src/location.rs +++ b/src/location.rs @@ -76,9 +76,6 @@ impl Location { /// for documentation. #[derive(Debug, Clone, Default)] pub struct Kml { - /// Nonstandard `addr` attribute of the `Document` tag storing the user email address. - pub addr: Option, - /// Placemarks. pub locations: Vec, @@ -221,19 +218,7 @@ impl Kml { let tag = String::from_utf8_lossy(event.name().as_ref()) .trim() .to_lowercase(); - if tag == "document" { - if let Some(addr) = event.attributes().filter_map(|a| a.ok()).find(|attr| { - String::from_utf8_lossy(attr.key.as_ref()) - .trim() - .to_lowercase() - == "addr" - }) { - self.addr = addr - .decoded_and_normalized_value(XmlVersion::Implicit1_0, reader.decoder()) - .ok() - .map(|a| a.into_owned()); - } - } else if tag == "placemark" { + if tag == "placemark" { self.tag = KmlTag::Placemark; self.curr.timestamp = 0; self.curr.latitude = 0.0; @@ -527,8 +512,6 @@ pub(crate) async fn delete_orphaned_poi(context: &Context) -> Result<()> { pub async fn get_kml(context: &Context, chat_id: ChatId) -> Result> { let mut last_added_location_timestamp: Option = None; - let self_addr = context.get_primary_self_addr().await?; - let (locations_send_begin, locations_send_until, locations_last_sent) = context.sql.query_row( "SELECT locations_send_begin, locations_send_until, locations_last_sent FROM chats WHERE id=?;", (chat_id,), |row| { @@ -543,10 +526,8 @@ pub async fn get_kml(context: &Context, chat_id: ChatId) -> Result\n\ - \n\n", - ); + ret += "\n\ + \n\n"; context .sql @@ -872,32 +853,35 @@ mod tests { #[test] fn test_kml_parse() { - let xml = - b"\n\n\n2019-03-06T21:09:57Z9.423110,53.790302\n\n \n\t2018-12-13T22:11:12Z\t 19.423110 \t , \n 63.790302\n \n\n"; + let xmls = [ + &b"\n\n\n2019-03-06T21:09:57Z9.423110,53.790302\n\n \n\t2018-12-13T22:11:12Z\t 19.423110 \t , \n 63.790302\n \n\n"[..], + // Older version that included `addr` attribute with email address + // in the `Document` tag. + &b"\n\n\n2019-03-06T21:09:57Z9.423110,53.790302\n\n \n\t2018-12-13T22:11:12Z\t 19.423110 \t , \n 63.790302\n \n\n"[..] + ]; - let kml = Kml::parse(xml).expect("parsing failed"); + for xml in xmls { + let kml = Kml::parse(xml).expect("parsing failed"); - assert!(kml.addr.is_some()); - assert_eq!(kml.addr.as_ref().unwrap(), "user@example.org",); + let locations_ref = &kml.locations; + assert_eq!(locations_ref.len(), 2); - let locations_ref = &kml.locations; - assert_eq!(locations_ref.len(), 2); + assert!(locations_ref[0].latitude > 53.6f64); + assert!(locations_ref[0].latitude < 53.8f64); + assert!(locations_ref[0].longitude > 9.3f64); + assert!(locations_ref[0].longitude < 9.5f64); + assert!(locations_ref[0].accuracy > 31.9f64); + assert!(locations_ref[0].accuracy < 32.1f64); + assert_eq!(locations_ref[0].timestamp, 1551906597); - assert!(locations_ref[0].latitude > 53.6f64); - assert!(locations_ref[0].latitude < 53.8f64); - assert!(locations_ref[0].longitude > 9.3f64); - assert!(locations_ref[0].longitude < 9.5f64); - assert!(locations_ref[0].accuracy > 31.9f64); - assert!(locations_ref[0].accuracy < 32.1f64); - assert_eq!(locations_ref[0].timestamp, 1551906597); - - assert!(locations_ref[1].latitude > 63.6f64); - assert!(locations_ref[1].latitude < 63.8f64); - assert!(locations_ref[1].longitude > 19.3f64); - assert!(locations_ref[1].longitude < 19.5f64); - assert!(locations_ref[1].accuracy > 2.4f64); - assert!(locations_ref[1].accuracy < 2.6f64); - assert_eq!(locations_ref[1].timestamp, 1544739072); + assert!(locations_ref[1].latitude > 63.6f64); + assert!(locations_ref[1].latitude < 63.8f64); + assert!(locations_ref[1].longitude > 19.3f64); + assert!(locations_ref[1].longitude < 19.5f64); + assert!(locations_ref[1].accuracy > 2.4f64); + assert!(locations_ref[1].accuracy < 2.6f64); + assert_eq!(locations_ref[1].timestamp, 1544739072); + } } #[test] @@ -981,7 +965,7 @@ Content-Disposition: attachment; filename="location.kml" - + 2021-11-21T00:00:00Z10.00000000000000,20.00000000000000 @@ -1030,7 +1014,7 @@ Content-Disposition: attachment; filename="location.kml" - + 2021-11-21T00:00:00Z10.00000000000000,20.00000000000000 diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 8ca77bfa9..ea24dff75 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -2588,24 +2588,11 @@ async fn save_locations( } if let Some(location_kml) = &mime_parser.location_kml - && let Some(addr) = &location_kml.addr + && location::save(context, chat_id, from_id, &location_kml.locations, false) + .await? + .is_some() { - let contact = Contact::get_by_id(context, from_id).await?; - if contact.get_addr().to_lowercase() == addr.to_lowercase() { - if location::save(context, chat_id, from_id, &location_kml.locations, false) - .await? - .is_some() - { - send_event = true; - } - } else { - warn!( - context, - "Address in location.kml {:?} is not the same as the sender address {:?}.", - addr, - contact.get_addr() - ); - } + send_event = true; } if send_event { context.emit_location_changed(Some(from_id)).await?;