From 70fa688d256c8a9dccebda73990c4f6fdad149cd Mon Sep 17 00:00:00 2001 From: Maurus Decimus <11444311+mdecimus@users.noreply.github.com> Date: Mon, 28 Sep 2026 11:38:10 +0200 Subject: [PATCH] Fix IMAP: import failed after authenticating to Dovecot when a capability contained `:`, such as `IMAPSIEVE=sieve://...` (fixes #43) --- CHANGELOG.md | 10 + Cargo.lock | 6 +- Cargo.toml | 7 +- src/dav/parse.rs | 150 +++--- src/exchange_ews/autodiscover.rs | 22 +- src/exchange_ews/parse.rs | 619 ++++++++++++------------ src/imap/client.rs | 10 + src/imap/response.rs | 92 +++- src/sync/import_exchange_ews/folders.rs | 2 +- src/sync/import_exchange_ews/items.rs | 4 +- tests/integration/dovecot.rs | 6 + tests/integration/stalwart.rs | 2 +- tests/integration_dovecot.rs | 28 ++ tests/mock_exchange_ews.rs | 8 +- tests/mock_imap.rs | 100 +++- tests/seeder/admin.rs | 2 +- tests/sync_jmap.rs | 10 +- 17 files changed, 617 insertions(+), 461 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e694c3..d51adc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.11] - 2026-09-28 + +### Added + +### Changed +- Replaced `base64` with `encodify`. + +### Fixed +- IMAP: import failed after authenticating to Dovecot when a capability contained `:`, such as `IMAPSIEVE=sieve://...` (fixes #43) + ## [1.0.10] - 2026-08-27 ### Added diff --git a/Cargo.lock b/Cargo.lock index fd7d0fe..870f71f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -724,6 +724,8 @@ checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" [[package]] name = "encodify" version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fda1e5c788c2b59096e152ad1a76ce72a2ab80c75985eb94ca82de0b6555db7" dependencies = [ "memchr", "simdutf8", @@ -1936,9 +1938,9 @@ checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac" [[package]] name = "quick-xml" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1" +checksum = "41b1177fdf999d2321d3fb46ff47159d9c1fb9ad66a4879f8c50a0b504615e9b" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index f86d3d9..675c998 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ bundled-sqlite = ["rusqlite/bundled"] [dependencies] serde = { version = "1.0.228", features = ["derive"] } serde_json = "1.0" -indexmap = { version = "2.14.0", features = ["serde"] } +indexmap = { version = "2.14", features = ["serde"] } rusqlite = { version = "0.40", features = ["blob"] } blake3 = "1.8.5" time = { version = "0.3.47", features = ["serde-well-known", "macros"] } @@ -43,7 +43,7 @@ rustls = { version = "0.23.40", default-features = false, features = ["aws-lc-rs rustls-platform-verifier = "0.7" regex = "1.13" flate2 = "1.1.9" -quick-xml = "0.41" +quick-xml = "0.42" chrono = { version = "0.4", default-features = false, features = ["std"] } chrono-tz = { version = "0.10", default-features = false } psl = "2.1.226" @@ -56,6 +56,3 @@ testcontainers = { version = "0.28", features = ["blocking"] } [profile.dist] inherits = "release" lto = "thin" - -[patch.crates-io] -encodify = { path = "../encodify" } diff --git a/src/dav/parse.rs b/src/dav/parse.rs index 6d9c006..198c976 100644 --- a/src/dav/parse.rs +++ b/src/dav/parse.rs @@ -78,13 +78,13 @@ fn classify_ns(ns: &ResolveResult<'_>) -> NsKind { match ns { ResolveResult::Bound(prefix) => { let p = prefix.as_ref(); - if p == NS_DAV.as_bytes() { + if p == NS_DAV { NsKind::Dav - } else if p == NS_CALDAV.as_bytes() { + } else if p == NS_CALDAV { NsKind::Caldav - } else if p == NS_CARDDAV.as_bytes() { + } else if p == NS_CARDDAV { NsKind::Carddav - } else if p == NS_APPLE_ICAL.as_bytes() { + } else if p == NS_APPLE_ICAL { NsKind::Apple } else { NsKind::Other @@ -94,7 +94,7 @@ fn classify_ns(ns: &ResolveResult<'_>) -> NsKind { } } -fn is(ns: NsKind, local: &[u8], expected_ns: NsKind, target: &[u8]) -> bool { +fn is(ns: NsKind, local: &str, expected_ns: NsKind, target: &str) -> bool { ns == expected_ns && local.eq_ignore_ascii_case(target) } @@ -102,17 +102,17 @@ fn is(ns: NsKind, local: &[u8], expected_ns: NsKind, target: &[u8]) -> bool { enum Step { StartElement { ns: NsKind, - local: Vec, - attrs: Vec<(Vec, Vec)>, + local: String, + attrs: Vec<(String, String)>, }, EmptyElement { ns: NsKind, - local: Vec, - attrs: Vec<(Vec, Vec)>, + local: String, + attrs: Vec<(String, String)>, }, EndElement { ns: NsKind, - local: Vec, + local: String, }, Text(String), CData(String), @@ -125,7 +125,7 @@ fn resolve_entity(g: &BytesRef) -> Option { if let Ok(Some(c)) = g.resolve_char_ref() { return Some(c); } - match g.decode().ok()?.as_ref() { + match g.as_ref() { "amp" => Some('&'), "lt" => Some('<'), "gt" => Some('>'), @@ -141,11 +141,12 @@ fn next_step(xml: &mut NsReader, buf: &mut Vec) -> Result { - let local = e.local_name().as_ref().to_vec(); - let mut attrs: Vec<(Vec, Vec)> = Vec::new(); - for a in e.attributes().flatten() { - attrs.push((a.key.as_ref().to_vec(), a.value.as_ref().to_vec())); - } + let local = e.local_name().as_ref().to_owned(); + let attrs = e + .attributes() + .flatten() + .map(|a| (a.key.as_ref().to_owned(), a.value.into_owned())) + .collect(); Step::StartElement { ns: ns_kind, local, @@ -153,11 +154,12 @@ fn next_step(xml: &mut NsReader, buf: &mut Vec) -> Result { - let local = e.local_name().as_ref().to_vec(); - let mut attrs: Vec<(Vec, Vec)> = Vec::new(); - for a in e.attributes().flatten() { - attrs.push((a.key.as_ref().to_vec(), a.value.as_ref().to_vec())); - } + let local = e.local_name().as_ref().to_owned(); + let attrs = e + .attributes() + .flatten() + .map(|a| (a.key.as_ref().to_owned(), a.value.into_owned())) + .collect(); Step::EmptyElement { ns: ns_kind, local, @@ -166,13 +168,10 @@ fn next_step(xml: &mut NsReader, buf: &mut Vec) -> Result Step::EndElement { ns: ns_kind, - local: e.local_name().as_ref().to_vec(), + local: e.local_name().as_ref().to_owned(), }, - Event::Text(t) => { - let s = t.decode().map_err(|e| ParseError::Xml(e.to_string()))?; - Step::Text(s.into_owned()) - } - Event::CData(cd) => Step::CData(String::from_utf8_lossy(cd.as_ref()).into_owned()), + Event::Text(t) => Step::Text(t.into_inner().into_owned()), + Event::CData(cd) => Step::CData(cd.into_inner().into_owned()), Event::GeneralRef(g) => match resolve_entity(&g) { Some(c) => Step::Entity(c), None => Step::Other, @@ -194,7 +193,7 @@ pub fn parse_multistatus( loop { let step = next_step(&mut xml, &mut buf)?; match step { - Step::StartElement { ns, local, .. } if is(ns, &local, NsKind::Dav, b"response") => { + Step::StartElement { ns, local, .. } if is(ns, &local, NsKind::Dav, "response") => { if let Some(r) = parse_response(&mut xml, base_url)? && seen.insert(r.href.as_str().to_owned()) { @@ -222,15 +221,15 @@ fn parse_response( let step = next_step(xml, &mut buf)?; match step { Step::StartElement { ns, local, .. } => { - if is(ns, &local, NsKind::Dav, b"href") { + if is(ns, &local, NsKind::Dav, "href") { let text = read_token(xml)?; if href.is_none() { href = Some(text); } - } else if is(ns, &local, NsKind::Dav, b"status") { + } else if is(ns, &local, NsKind::Dav, "status") { let text = read_token(xml)?; status = parse_http_status(&text); - } else if is(ns, &local, NsKind::Dav, b"propstat") { + } else if is(ns, &local, NsKind::Dav, "propstat") { let (block_status, block_props) = parse_propstat(xml)?; match block_status { Some(s) if (200..300).contains(&s) => merge_props(&mut props, block_props), @@ -241,7 +240,7 @@ fn parse_response( skip_element(xml, &local)?; } } - Step::EndElement { ns, local } if is(ns, &local, NsKind::Dav, b"response") => break, + Step::EndElement { ns, local } if is(ns, &local, NsKind::Dav, "response") => break, Step::Eof => return Err(ParseError::Xml("unexpected EOF in ".into())), _ => {} } @@ -270,16 +269,16 @@ fn parse_propstat( let step = next_step(xml, &mut buf)?; match step { Step::StartElement { ns, local, .. } => { - if is(ns, &local, NsKind::Dav, b"status") { + if is(ns, &local, NsKind::Dav, "status") { let text = read_token(xml)?; status = parse_http_status(&text); - } else if is(ns, &local, NsKind::Dav, b"prop") { + } else if is(ns, &local, NsKind::Dav, "prop") { parse_prop_block(xml, &mut props)?; } else { skip_element(xml, &local)?; } } - Step::EndElement { ns, local } if is(ns, &local, NsKind::Dav, b"propstat") => break, + Step::EndElement { ns, local } if is(ns, &local, NsKind::Dav, "propstat") => break, Step::Eof => return Err(ParseError::Xml("unexpected EOF in ".into())), _ => {} } @@ -299,7 +298,7 @@ fn parse_prop_block( handle_prop_element(xml, props, ns, &local)?; } Step::EmptyElement { .. } => {} - Step::EndElement { ns, local } if is(ns, &local, NsKind::Dav, b"prop") => break, + Step::EndElement { ns, local } if is(ns, &local, NsKind::Dav, "prop") => break, Step::Eof => return Err(ParseError::Xml("unexpected EOF in ".into())), _ => {} } @@ -311,53 +310,53 @@ fn handle_prop_element( xml: &mut NsReader, props: &mut ResourceProps, ns: NsKind, - local: &[u8], + local: &str, ) -> Result<(), ParseError> { - if is(ns, local, NsKind::Dav, b"resourcetype") { + if is(ns, local, NsKind::Dav, "resourcetype") { consume_resourcetype(xml, props)?; - } else if is(ns, local, NsKind::Dav, b"displayname") { + } else if is(ns, local, NsKind::Dav, "displayname") { props.displayname = Some(read_token(xml)?); - } else if is(ns, local, NsKind::Dav, b"current-user-principal") { - props.current_user_principal = read_first_href(xml, b"current-user-principal")?; - } else if is(ns, local, NsKind::Caldav, b"calendar-home-set") { - props.calendar_home_set = read_first_href(xml, b"calendar-home-set")?; - } else if is(ns, local, NsKind::Carddav, b"addressbook-home-set") { - props.addressbook_home_set = read_first_href(xml, b"addressbook-home-set")?; - } else if is(ns, local, NsKind::Dav, b"getetag") { + } else if is(ns, local, NsKind::Dav, "current-user-principal") { + props.current_user_principal = read_first_href(xml, "current-user-principal")?; + } else if is(ns, local, NsKind::Caldav, "calendar-home-set") { + props.calendar_home_set = read_first_href(xml, "calendar-home-set")?; + } else if is(ns, local, NsKind::Carddav, "addressbook-home-set") { + props.addressbook_home_set = read_first_href(xml, "addressbook-home-set")?; + } else if is(ns, local, NsKind::Dav, "getetag") { let raw = read_token(xml)?; if !raw.is_empty() { props.etag = Some(raw); } - } else if is(ns, local, NsKind::Dav, b"getcontenttype") { + } else if is(ns, local, NsKind::Dav, "getcontenttype") { props.content_type = Some(read_token(xml)?); - } else if is(ns, local, NsKind::Dav, b"getlastmodified") { + } else if is(ns, local, NsKind::Dav, "getlastmodified") { props.last_modified = Some(read_token(xml)?); - } else if is(ns, local, NsKind::Dav, b"creationdate") { + } else if is(ns, local, NsKind::Dav, "creationdate") { props.creation_date = Some(read_token(xml)?); - } else if is(ns, local, NsKind::Dav, b"getcontentlength") { + } else if is(ns, local, NsKind::Dav, "getcontentlength") { let raw = read_token(xml)?; props.content_length = raw.parse::().ok(); - } else if is(ns, local, NsKind::Caldav, b"calendar-description") { + } else if is(ns, local, NsKind::Caldav, "calendar-description") { props.calendar_description = Some(read_token(xml)?); - } else if is(ns, local, NsKind::Carddav, b"addressbook-description") { + } else if is(ns, local, NsKind::Carddav, "addressbook-description") { props.addressbook_description = Some(read_token(xml)?); - } else if is(ns, local, NsKind::Apple, b"calendar-color") { + } else if is(ns, local, NsKind::Apple, "calendar-color") { props.calendar_color = Some(read_token(xml)?); - } else if is(ns, local, NsKind::Apple, b"calendar-order") { + } else if is(ns, local, NsKind::Apple, "calendar-order") { let raw = read_token(xml)?; props.calendar_order = raw.parse::().ok(); - } else if is(ns, local, NsKind::Caldav, b"calendar-timezone") { + } else if is(ns, local, NsKind::Caldav, "calendar-timezone") { props.calendar_timezone = Some(read_token(xml)?); } else if is( ns, local, NsKind::Caldav, - b"supported-calendar-component-set", + "supported-calendar-component-set", ) { consume_supported_components(xml, props)?; - } else if is(ns, local, NsKind::Caldav, b"calendar-data") { + } else if is(ns, local, NsKind::Caldav, "calendar-data") { props.calendar_data = Some(read_text(xml)?); - } else if is(ns, local, NsKind::Carddav, b"address-data") { + } else if is(ns, local, NsKind::Carddav, "address-data") { props.address_data = Some(read_text(xml)?); } else { skip_element(xml, local)?; @@ -380,7 +379,7 @@ fn consume_resourcetype( Step::EmptyElement { ns, local, .. } => { mark_resourcetype(ns, &local, props); } - Step::EndElement { ns, local } if is(ns, &local, NsKind::Dav, b"resourcetype") => break, + Step::EndElement { ns, local } if is(ns, &local, NsKind::Dav, "resourcetype") => break, Step::Eof => { return Err(ParseError::Xml("unexpected EOF in ".into())); } @@ -390,12 +389,12 @@ fn consume_resourcetype( Ok(()) } -fn mark_resourcetype(ns: NsKind, local: &[u8], props: &mut ResourceProps) { - if is(ns, local, NsKind::Dav, b"collection") { +fn mark_resourcetype(ns: NsKind, local: &str, props: &mut ResourceProps) { + if is(ns, local, NsKind::Dav, "collection") { props.is_collection = true; - } else if is(ns, local, NsKind::Caldav, b"calendar") { + } else if is(ns, local, NsKind::Caldav, "calendar") { props.is_calendar = true; - } else if is(ns, local, NsKind::Carddav, b"addressbook") { + } else if is(ns, local, NsKind::Carddav, "addressbook") { props.is_addressbook = true; } } @@ -412,8 +411,8 @@ fn consume_supported_components( ns, local, ref attrs, - } if is(ns, &local, NsKind::Caldav, b"comp") => { - if let Some(name) = attr_lookup(attrs, b"name") { + } if is(ns, &local, NsKind::Caldav, "comp") => { + if let Some(name) = attr_lookup(attrs, "name") { props.supported_components.push(name); } skip_element(xml, &local)?; @@ -422,8 +421,8 @@ fn consume_supported_components( ns, local, ref attrs, - } if is(ns, &local, NsKind::Caldav, b"comp") => { - if let Some(name) = attr_lookup(attrs, b"name") { + } if is(ns, &local, NsKind::Caldav, "comp") => { + if let Some(name) = attr_lookup(attrs, "name") { props.supported_components.push(name); } } @@ -432,7 +431,7 @@ fn consume_supported_components( ns, &local, NsKind::Caldav, - b"supported-calendar-component-set", + "supported-calendar-component-set", ) => { break; @@ -448,13 +447,8 @@ fn consume_supported_components( Ok(()) } -fn attr_lookup(attrs: &[(Vec, Vec)], key: &[u8]) -> Option { - for (k, v) in attrs { - if k == key { - return Some(String::from_utf8_lossy(v).into_owned()); - } - } - None +fn attr_lookup(attrs: &[(String, String)], key: &str) -> Option { + attrs.iter().find(|(k, _)| k == key).map(|(_, v)| v.clone()) } fn read_text(xml: &mut NsReader) -> Result { @@ -480,7 +474,7 @@ fn read_token(xml: &mut NsReader) -> Result { fn read_first_href( xml: &mut NsReader, - closing_local: &[u8], + closing_local: &str, ) -> Result, ParseError> { let mut buf = Vec::new(); let mut out: Option = None; @@ -488,7 +482,7 @@ fn read_first_href( let step = next_step(xml, &mut buf)?; match step { Step::StartElement { ns, local, .. } => { - if out.is_none() && is(ns, &local, NsKind::Dav, b"href") { + if out.is_none() && is(ns, &local, NsKind::Dav, "href") { out = Some(read_token(xml)?); } else { skip_element(xml, &local)?; @@ -505,7 +499,7 @@ fn read_first_href( Ok(out) } -fn skip_element(xml: &mut NsReader, target: &[u8]) -> Result<(), ParseError> { +fn skip_element(xml: &mut NsReader, target: &str) -> Result<(), ParseError> { let mut buf = Vec::new(); let mut depth: i32 = 1; while depth > 0 { diff --git a/src/exchange_ews/autodiscover.rs b/src/exchange_ews/autodiscover.rs index 42e224a..cb28b4f 100644 --- a/src/exchange_ews/autodiscover.rs +++ b/src/exchange_ews/autodiscover.rs @@ -435,31 +435,31 @@ fn parse_pox_response(body: &[u8]) -> Result { let (_, ev) = xml.read_resolved_event_into(&mut buf)?; match ev { Event::Start(e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); cur.clear(); - if local.eq_ignore_ascii_case(b"Protocol") { + if local.eq_ignore_ascii_case("Protocol") { current_type = None; } - if local.eq_ignore_ascii_case(b"Type") { + if local.eq_ignore_ascii_case("Type") { current = Some("type"); - } else if local.eq_ignore_ascii_case(b"EwsUrl") { + } else if local.eq_ignore_ascii_case("EwsUrl") { if matches!(current_type.as_deref(), Some("EXPR") | Some("EXCH")) { current = Some("ewsUrl"); } else { current = None; } - } else if local.eq_ignore_ascii_case(b"Action") { + } else if local.eq_ignore_ascii_case("Action") { current = Some("action"); - } else if local.eq_ignore_ascii_case(b"RedirectAddr") { + } else if local.eq_ignore_ascii_case("RedirectAddr") { current = Some("redirectAddr"); - } else if local.eq_ignore_ascii_case(b"RedirectUrl") { + } else if local.eq_ignore_ascii_case("RedirectUrl") { current = Some("redirectUrl"); } else { current = None; } } Event::End(e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); if let Some(field) = current.take() { let text = std::mem::take(&mut cur); match field { @@ -472,15 +472,15 @@ fn parse_pox_response(body: &[u8]) -> Result { } } cur.clear(); - if local.eq_ignore_ascii_case(b"Protocol") { + if local.eq_ignore_ascii_case("Protocol") { current_type = None; } } Event::Text(t) => { - cur.push_str(&t.decode().map(|c| c.into_owned()).unwrap_or_default()); + cur.push_str(&t); } Event::CData(c) => { - cur.push_str(&String::from_utf8_lossy(c.as_ref())); + cur.push_str(&c); } Event::GeneralRef(g) => { if let Some(c) = entity_to_char(&g) { diff --git a/src/exchange_ews/parse.rs b/src/exchange_ews/parse.rs index 358c847..0024b54 100644 --- a/src/exchange_ews/parse.rs +++ b/src/exchange_ews/parse.rs @@ -26,9 +26,9 @@ fn classify(ns: &ResolveResult<'_>) -> Ns { match ns { ResolveResult::Bound(prefix) => { let p = prefix.as_ref(); - if p == NS_MESSAGES.as_bytes() { + if p == NS_MESSAGES { Ns::Messages - } else if p == NS_TYPES.as_bytes() { + } else if p == NS_TYPES { Ns::Types } else { Ns::Other @@ -38,18 +38,18 @@ fn classify(ns: &ResolveResult<'_>) -> Ns { } } -fn is(ns: Ns, local: &[u8], expected_ns: Ns, target: &[u8]) -> bool { +fn is(ns: Ns, local: &str, expected_ns: Ns, target: &str) -> bool { ns == expected_ns && local.eq_ignore_ascii_case(target) } -fn attr_value(e: &BytesStart<'_>, name: &[u8]) -> Option { +fn attr_value(e: &BytesStart<'_>, name: &str) -> Option { for a in e.attributes().flatten() { let key = a.key.local_name(); if key.as_ref().eq_ignore_ascii_case(name) { return Some( a.normalized_value(XmlVersion::Implicit1_0) .map(|c| c.into_owned()) - .unwrap_or_else(|_| String::from_utf8_lossy(a.value.as_ref()).into_owned()), + .unwrap_or_else(|_| a.value.into_owned()), ); } } @@ -63,10 +63,10 @@ fn capture_id_attrs(e: &BytesStart<'_>, id_out: &mut String, ck_out: &mut String let v = a .normalized_value(XmlVersion::Implicit1_0) .map(|c| c.into_owned()) - .unwrap_or_else(|_| String::from_utf8_lossy(a.value.as_ref()).into_owned()); - if kb.eq_ignore_ascii_case(b"Id") { + .unwrap_or_else(|_| a.value.into_owned()); + if kb.eq_ignore_ascii_case("Id") { *id_out = v; - } else if kb.eq_ignore_ascii_case(b"ChangeKey") { + } else if kb.eq_ignore_ascii_case("ChangeKey") { *ck_out = v; } } @@ -94,16 +94,16 @@ fn read_version_attrs(e: &BytesStart<'_>, out: &mut ServerVersionInfo) { for a in e.attributes().flatten() { let key = a.key.local_name(); let kb = key.as_ref(); - let v = String::from_utf8_lossy(a.value.as_ref()).into_owned(); - if kb.eq_ignore_ascii_case(b"MajorVersion") { + let v = a.value.into_owned(); + if kb.eq_ignore_ascii_case("MajorVersion") { out.major_version = v.parse().ok(); - } else if kb.eq_ignore_ascii_case(b"MinorVersion") { + } else if kb.eq_ignore_ascii_case("MinorVersion") { out.minor_version = v.parse().ok(); - } else if kb.eq_ignore_ascii_case(b"MajorBuildNumber") { + } else if kb.eq_ignore_ascii_case("MajorBuildNumber") { out.major_build = v.parse().ok(); - } else if kb.eq_ignore_ascii_case(b"MinorBuildNumber") { + } else if kb.eq_ignore_ascii_case("MinorBuildNumber") { out.minor_build = v.parse().ok(); - } else if kb.eq_ignore_ascii_case(b"Version") { + } else if kb.eq_ignore_ascii_case("Version") { out.version = Some(v); } } @@ -140,13 +140,13 @@ pub fn read_envelope_summary(bytes: &[u8]) -> Result { let ns_kind = classify(&ns); match ev { Event::Start(ref e) | Event::Empty(ref e) => { - let local = e.local_name().as_ref().to_vec(); - if is(ns_kind, &local, Ns::Types, b"ServerVersionInfo") { + let local = e.local_name().as_ref().to_owned(); + if is(ns_kind, &local, Ns::Types, "ServerVersionInfo") { read_version_attrs(e, &mut version); - } else if local.eq_ignore_ascii_case(b"Fault") { + } else if local.eq_ignore_ascii_case("Fault") { let fault = parse_fault(&mut xml)?; return Ok(EnvelopeKind::Fault { version, fault }); - } else if local.eq_ignore_ascii_case(b"Body") { + } else if local.eq_ignore_ascii_case("Body") { seen_body = true; } } @@ -177,24 +177,24 @@ fn parse_fault(xml: &mut NsReader) -> Result match ev { Event::Start(e) => { depth += 1; - let local = e.local_name().as_ref().to_vec(); - if local.eq_ignore_ascii_case(b"faultcode") { + let local = e.local_name().as_ref().to_owned(); + if local.eq_ignore_ascii_case("faultcode") { text_target = Some("faultcode"); - } else if local.eq_ignore_ascii_case(b"faultstring") { + } else if local.eq_ignore_ascii_case("faultstring") { text_target = Some("faultstring"); - } else if local.eq_ignore_ascii_case(b"ResponseCode") { + } else if local.eq_ignore_ascii_case("ResponseCode") { text_target = Some("responseCode"); - } else if local.eq_ignore_ascii_case(b"Value") && ns_kind == Ns::Types { - last_value_name = attr_value(&e, b"Name"); + } else if local.eq_ignore_ascii_case("Value") && ns_kind == Ns::Types { + last_value_name = attr_value(&e, "Name"); text_target = Some("messageXmlValue"); } else { text_target = None; } } Event::Empty(e) => { - let local = e.local_name().as_ref().to_vec(); - if is(ns_kind, &local, Ns::Types, b"Value") { - last_value_name = attr_value(&e, b"Name"); + let local = e.local_name().as_ref().to_owned(); + if is(ns_kind, &local, Ns::Types, "Value") { + last_value_name = attr_value(&e, "Name"); } } Event::End(_) => { @@ -208,7 +208,7 @@ fn parse_fault(xml: &mut NsReader) -> Result } } Event::Text(t) => { - let text = t.decode().map(|c| c.into_owned()).unwrap_or_default(); + let text = t.into_inner().into_owned(); match text_target { Some("faultcode") => fault_code = text, Some("faultstring") => fault_string.push_str(&text), @@ -222,7 +222,7 @@ fn parse_fault(xml: &mut NsReader) -> Result } } Event::CData(c) if text_target == Some("faultstring") => { - fault_string.push_str(&String::from_utf8_lossy(c.as_ref())); + fault_string.push_str(&c); } Event::GeneralRef(ref g) if text_target == Some("faultstring") => { if let Some(c) = entity_to_char(g) { @@ -291,16 +291,16 @@ pub enum FolderElement { } impl FolderElement { - fn from_local(local: &[u8]) -> Option { - if local.eq_ignore_ascii_case(b"Folder") { + fn from_local(local: &str) -> Option { + if local.eq_ignore_ascii_case("Folder") { Some(FolderElement::Folder) - } else if local.eq_ignore_ascii_case(b"CalendarFolder") { + } else if local.eq_ignore_ascii_case("CalendarFolder") { Some(FolderElement::CalendarFolder) - } else if local.eq_ignore_ascii_case(b"ContactsFolder") { + } else if local.eq_ignore_ascii_case("ContactsFolder") { Some(FolderElement::ContactsFolder) - } else if local.eq_ignore_ascii_case(b"TasksFolder") { + } else if local.eq_ignore_ascii_case("TasksFolder") { Some(FolderElement::TasksFolder) - } else if local.eq_ignore_ascii_case(b"SearchFolder") { + } else if local.eq_ignore_ascii_case("SearchFolder") { Some(FolderElement::SearchFolder) } else { None @@ -319,12 +319,12 @@ pub fn parse_find_folder_response(body: &[u8]) -> Result { - let local = e.local_name().as_ref().to_vec(); - if is(ns_kind, &local, Ns::Messages, b"RootFolder") { - if let Some(v) = attr_value(e, b"TotalItemsInView") { + let local = e.local_name().as_ref().to_owned(); + if is(ns_kind, &local, Ns::Messages, "RootFolder") { + if let Some(v) = attr_value(e, "TotalItemsInView") { out.total_in_view = v.trim().parse().ok(); } - if let Some(v) = attr_value(e, b"IncludesLastItemInRange") { + if let Some(v) = attr_value(e, "IncludesLastItemInRange") { out.more = !matches!(v.trim(), "true" | "1"); } } else if ns_kind == Ns::Types @@ -352,7 +352,7 @@ pub fn parse_folder_inner(inner_xml: &str) -> Result, EwsErr match ev { Event::Start(_) | Event::Empty(_) => { let local = match &ev { - Event::Start(e) | Event::Empty(e) => e.local_name().as_ref().to_vec(), + Event::Start(e) | Event::Empty(e) => e.local_name().as_ref().to_owned(), _ => continue, }; if ns_kind == Ns::Types @@ -379,7 +379,7 @@ pub fn parse_get_folder_response(body: &[u8]) -> Result, EwsErr match ev { Event::Start(_) | Event::Empty(_) => { let local = match &ev { - Event::Start(e) | Event::Empty(e) => e.local_name().as_ref().to_vec(), + Event::Start(e) | Event::Empty(e) => e.local_name().as_ref().to_owned(), _ => continue, }; if ns_kind == Ns::Types @@ -419,31 +419,31 @@ fn parse_folder_element( if !is_empty { depth += 1; } - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); if ns_kind == Ns::Types { - if local.eq_ignore_ascii_case(b"FolderId") { + if local.eq_ignore_ascii_case("FolderId") { capture_id_attrs( e, &mut entry.folder_id.id, &mut entry.folder_id.change_key, ); - } else if local.eq_ignore_ascii_case(b"ParentFolderId") { + } else if local.eq_ignore_ascii_case("ParentFolderId") { let mut pid = String::new(); let mut ck = String::new(); capture_id_attrs(e, &mut pid, &mut ck); if !pid.is_empty() { entry.parent_id = Some(pid); } - } else if local.eq_ignore_ascii_case(b"DisplayName") { + } else if local.eq_ignore_ascii_case("DisplayName") { current = Some("displayName"); cur.clear(); - } else if local.eq_ignore_ascii_case(b"FolderClass") { + } else if local.eq_ignore_ascii_case("FolderClass") { current = Some("folderClass"); cur.clear(); - } else if local.eq_ignore_ascii_case(b"TotalCount") { + } else if local.eq_ignore_ascii_case("TotalCount") { current = Some("totalCount"); cur.clear(); - } else if local.eq_ignore_ascii_case(b"ChildFolderCount") { + } else if local.eq_ignore_ascii_case("ChildFolderCount") { current = Some("childCount"); cur.clear(); } else { @@ -474,10 +474,10 @@ fn parse_folder_element( } } Event::Text(t) => { - cur.push_str(&t.decode().map(|c| c.into_owned()).unwrap_or_default()); + cur.push_str(&t); } Event::CData(c) => { - cur.push_str(&String::from_utf8_lossy(c.as_ref())); + cur.push_str(&c); } Event::GeneralRef(ref g) => { if let Some(c) = entity_to_char(g) { @@ -516,22 +516,22 @@ pub fn parse_find_item_response(body: &[u8]) -> Result { - let local = e.local_name().as_ref().to_vec(); - if is(ns_kind, &local, Ns::Messages, b"RootFolder") { + let local = e.local_name().as_ref().to_owned(); + if is(ns_kind, &local, Ns::Messages, "RootFolder") { in_root = true; - if let Some(v) = attr_value(e, b"TotalItemsInView") { + if let Some(v) = attr_value(e, "TotalItemsInView") { out.total_in_view = v.trim().parse().ok(); } - if let Some(v) = attr_value(e, b"IncludesLastItemInRange") { + if let Some(v) = attr_value(e, "IncludesLastItemInRange") { out.more = !matches!(v.trim(), "true" | "1"); } } else if in_root && ns_kind == Ns::Types { if is_item_element(&local) { out.items.push(ItemEntry { - element: String::from_utf8_lossy(&local).into_owned(), + element: local.clone(), id: ItemId::default(), }); - } else if local.eq_ignore_ascii_case(b"ItemId") + } else if local.eq_ignore_ascii_case("ItemId") && let Some(last) = out.items.last_mut() { capture_id_attrs(e, &mut last.id.id, &mut last.id.change_key); @@ -539,8 +539,8 @@ pub fn parse_find_item_response(body: &[u8]) -> Result { - let local = e.local_name().as_ref().to_vec(); - if local.eq_ignore_ascii_case(b"RootFolder") { + let local = e.local_name().as_ref().to_owned(); + if local.eq_ignore_ascii_case("RootFolder") { in_root = false; } } @@ -555,7 +555,7 @@ pub(crate) fn entity_to_char(g: &BytesRef) -> Option { if let Ok(Some(c)) = g.resolve_char_ref() { return Some(c); } - match g.decode().ok()?.as_ref() { + match g.as_ref() { "amp" => Some('&'), "lt" => Some('<'), "gt" => Some('>'), @@ -565,18 +565,18 @@ pub(crate) fn entity_to_char(g: &BytesRef) -> Option { } } -fn is_item_element(local: &[u8]) -> bool { +fn is_item_element(local: &str) -> bool { matches!( - local.to_ascii_lowercase().as_slice(), - b"message" - | b"calendaritem" - | b"contact" - | b"distributionlist" - | b"meetingrequest" - | b"meetingresponse" - | b"meetingmessage" - | b"meetingcancellation" - | b"item" + local.to_ascii_lowercase().as_str(), + "message" + | "calendaritem" + | "contact" + | "distributionlist" + | "meetingrequest" + | "meetingresponse" + | "meetingmessage" + | "meetingcancellation" + | "item" ) } @@ -590,7 +590,7 @@ pub struct ResponseMessage { pub fn parse_response_messages( body: &[u8], - response_message_local: &[u8], + response_message_local: &str, ) -> Result, EwsError> { let mut xml = NsReader::from_reader(body); xml.config_mut().trim_text(false); @@ -602,10 +602,10 @@ pub fn parse_response_messages( let ns_kind = classify(&ns); match ev { Event::Start(e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); if is(ns_kind, &local, Ns::Messages, response_message_local) { let response_class = - attr_value(&e, b"ResponseClass").unwrap_or_else(|| "Success".to_owned()); + attr_value(&e, "ResponseClass").unwrap_or_else(|| "Success".to_owned()); let msg = parse_one_response_message(&mut xml, response_class)?; out.push(msg); } @@ -636,15 +636,15 @@ fn parse_one_response_message( match ev { Event::Start(e) => { depth += 1; - let local = e.local_name().as_ref().to_vec(); - if !in_capture && is(ns_kind, &local, Ns::Messages, b"ResponseCode") { + let local = e.local_name().as_ref().to_owned(); + if !in_capture && is(ns_kind, &local, Ns::Messages, "ResponseCode") { current = Some("responseCode"); - } else if !in_capture && is(ns_kind, &local, Ns::Messages, b"MessageText") { + } else if !in_capture && is(ns_kind, &local, Ns::Messages, "MessageText") { current = Some("messageText"); } else if !in_capture - && (is(ns_kind, &local, Ns::Messages, b"Items") - || is(ns_kind, &local, Ns::Messages, b"Attachments") - || is(ns_kind, &local, Ns::Messages, b"Folders")) + && (is(ns_kind, &local, Ns::Messages, "Items") + || is(ns_kind, &local, Ns::Messages, "Attachments") + || is(ns_kind, &local, Ns::Messages, "Folders")) { capture_depth = 1; current = None; @@ -656,11 +656,11 @@ fn parse_one_response_message( } } Event::Empty(e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); if in_capture { write_empty_xml(&mut inner, &e); - } else if is(ns_kind, &local, Ns::Messages, b"ResponseCode") - || is(ns_kind, &local, Ns::Messages, b"MessageText") + } else if is(ns_kind, &local, Ns::Messages, "ResponseCode") + || is(ns_kind, &local, Ns::Messages, "MessageText") { } } @@ -683,7 +683,7 @@ fn parse_one_response_message( } } Event::Text(t) => { - let text = t.decode().map(|c| c.into_owned()).unwrap_or_default(); + let text = t.into_inner().into_owned(); if in_capture { write_text_xml(&mut inner, &text); } else { @@ -695,7 +695,7 @@ fn parse_one_response_message( } } Event::CData(c) => { - let text = String::from_utf8_lossy(c.as_ref()).into_owned(); + let text = c.into_inner().into_owned(); if in_capture { write_text_xml(&mut inner, &text); } @@ -703,9 +703,7 @@ fn parse_one_response_message( Event::GeneralRef(ref g) => { if in_capture { inner.push('&'); - if let Ok(name) = g.decode() { - inner.push_str(&name); - } + inner.push_str(g.as_ref()); inner.push(';'); } } @@ -732,12 +730,12 @@ fn wrap_inner_with_namespaces(inner: &str) -> String { fn write_start_xml(out: &mut String, e: &BytesStart<'_>) { out.push('<'); - out.push_str(&String::from_utf8_lossy(e.name().as_ref())); + out.push_str(e.name().as_ref()); for a in e.attributes().flatten() { out.push(' '); - out.push_str(&String::from_utf8_lossy(a.key.as_ref())); + out.push_str(a.key.as_ref()); out.push_str("=\""); - let val = String::from_utf8_lossy(a.value.as_ref()); + let val = a.value; for ch in val.chars() { match ch { '&' => out.push_str("&"), @@ -754,12 +752,12 @@ fn write_start_xml(out: &mut String, e: &BytesStart<'_>) { fn write_empty_xml(out: &mut String, e: &BytesStart<'_>) { out.push('<'); - out.push_str(&String::from_utf8_lossy(e.name().as_ref())); + out.push_str(e.name().as_ref()); for a in e.attributes().flatten() { out.push(' '); - out.push_str(&String::from_utf8_lossy(a.key.as_ref())); + out.push_str(a.key.as_ref()); out.push_str("=\""); - let val = String::from_utf8_lossy(a.value.as_ref()); + let val = a.value; for ch in val.chars() { match ch { '&' => out.push_str("&"), @@ -776,7 +774,7 @@ fn write_empty_xml(out: &mut String, e: &BytesStart<'_>) { fn write_end_xml_event(out: &mut String, e: &quick_xml::events::BytesEnd<'_>) { out.push_str("'); } @@ -824,47 +822,47 @@ pub fn parse_sync_folder_items_response(body: &[u8]) -> Result { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let is_empty = matches!(ev, Event::Empty(_)); - if is(ns_kind, &local, Ns::Messages, b"SyncState") { + if is(ns_kind, &local, Ns::Messages, "SyncState") { current_text = Some("syncState"); - } else if is(ns_kind, &local, Ns::Messages, b"IncludesLastItemInRange") { + } else if is(ns_kind, &local, Ns::Messages, "IncludesLastItemInRange") { current_text = Some("includesLast"); - } else if is(ns_kind, &local, Ns::Messages, b"Changes") { + } else if is(ns_kind, &local, Ns::Messages, "Changes") { in_changes = true; } else if in_changes && ns_kind == Ns::Types { - if local.eq_ignore_ascii_case(b"Create") { + if local.eq_ignore_ascii_case("Create") { current_change = Some(SyncChange::Create { id: ItemId::default(), element: String::new(), }); - } else if local.eq_ignore_ascii_case(b"Update") { + } else if local.eq_ignore_ascii_case("Update") { current_change = Some(SyncChange::Update { id: ItemId::default(), element: String::new(), }); - } else if local.eq_ignore_ascii_case(b"Delete") { + } else if local.eq_ignore_ascii_case("Delete") { current_change = Some(SyncChange::Delete { id: ItemId::default(), }); - } else if local.eq_ignore_ascii_case(b"ReadFlagChange") { + } else if local.eq_ignore_ascii_case("ReadFlagChange") { current_change = Some(SyncChange::ReadFlagChange { id: ItemId::default(), is_read: false, }); pending_is_read = None; - } else if local.eq_ignore_ascii_case(b"ItemId") { + } else if local.eq_ignore_ascii_case("ItemId") { if let Some(change) = current_change.as_mut() { let (id, ck) = item_id_mut(change); capture_id_attrs(e, id, ck); } - } else if local.eq_ignore_ascii_case(b"IsRead") { + } else if local.eq_ignore_ascii_case("IsRead") { reading_is_read = true; } else if is_item_element(&local) { match current_change.as_mut() { Some(SyncChange::Create { element, .. }) | Some(SyncChange::Update { element, .. }) => { - *element = String::from_utf8_lossy(&local).into_owned(); + *element = local.clone(); } _ => {} } @@ -875,10 +873,10 @@ pub fn parse_sync_folder_items_response(body: &[u8]) -> Result { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let lower = local.to_ascii_lowercase(); - match lower.as_slice() { - b"create" | b"update" | b"delete" | b"readflagchange" => { + match lower.as_str() { + "create" | "update" | "delete" | "readflagchange" => { if let Some(mut change) = current_change.take() { if let SyncChange::ReadFlagChange { is_read, .. } = &mut change && let Some(v) = pending_is_read.take() @@ -888,14 +886,14 @@ pub fn parse_sync_folder_items_response(body: &[u8]) -> Result reading_is_read = false, - b"changes" => in_changes = false, + "isread" => reading_is_read = false, + "changes" => in_changes = false, _ => {} } current_text = None; } Event::Text(t) => { - let text = t.decode().map(|c| c.into_owned()).unwrap_or_default(); + let text = t.into_inner().into_owned(); if reading_is_read { pending_is_read = Some(matches!(text.trim(), "true" | "1")); } @@ -906,7 +904,7 @@ pub fn parse_sync_folder_items_response(body: &[u8]) -> Result { - let text = String::from_utf8_lossy(c.as_ref()).into_owned(); + let text = c.into_inner().into_owned(); if current_text == Some("syncState") { sync_state = text; } @@ -964,48 +962,48 @@ pub fn parse_message_item(inner_xml: &str) -> Result { let ns_kind = classify(&ns); match ev { Event::Start(ref e) | Event::Empty(ref e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let is_empty = matches!(ev, Event::Empty(_)); if item.element.is_empty() && is_item_element(&local) { - item.element = String::from_utf8_lossy(&local).into_owned(); + item.element = local.clone(); } else if ns_kind == Ns::Types { cur.clear(); - if local.eq_ignore_ascii_case(b"ItemId") { + if local.eq_ignore_ascii_case("ItemId") { capture_id_attrs(e, &mut item.id.id, &mut item.id.change_key); - } else if local.eq_ignore_ascii_case(b"ParentFolderId") { + } else if local.eq_ignore_ascii_case("ParentFolderId") { let mut pid = String::new(); let mut ck = String::new(); capture_id_attrs(e, &mut pid, &mut ck); if !pid.is_empty() { item.parent_folder_id = Some(pid); } - } else if local.eq_ignore_ascii_case(b"MimeContent") { - mime_charset = attr_value(e, b"CharacterSet"); + } else if local.eq_ignore_ascii_case("MimeContent") { + mime_charset = attr_value(e, "CharacterSet"); current = Some("mimeContent"); - } else if local.eq_ignore_ascii_case(b"Subject") { + } else if local.eq_ignore_ascii_case("Subject") { current = Some("subject"); - } else if local.eq_ignore_ascii_case(b"DateTimeReceived") { + } else if local.eq_ignore_ascii_case("DateTimeReceived") { current = Some("received"); - } else if local.eq_ignore_ascii_case(b"IsRead") { + } else if local.eq_ignore_ascii_case("IsRead") { current = Some("isRead"); - } else if local.eq_ignore_ascii_case(b"IsDraft") { + } else if local.eq_ignore_ascii_case("IsDraft") { current = Some("isDraft"); - } else if local.eq_ignore_ascii_case(b"IsReadReceiptRequested") { + } else if local.eq_ignore_ascii_case("IsReadReceiptRequested") { current = Some("readReceipt"); - } else if local.eq_ignore_ascii_case(b"Categories") { + } else if local.eq_ignore_ascii_case("Categories") { category_collecting = true; - } else if category_collecting && local.eq_ignore_ascii_case(b"String") { + } else if category_collecting && local.eq_ignore_ascii_case("String") { current = Some("category"); - } else if local.eq_ignore_ascii_case(b"Flag") { + } else if local.eq_ignore_ascii_case("Flag") { in_flag = true; - } else if in_flag && local.eq_ignore_ascii_case(b"FlagStatus") { + } else if in_flag && local.eq_ignore_ascii_case("FlagStatus") { current = Some("flagStatus"); - } else if local.eq_ignore_ascii_case(b"ExtendedFieldURI") { - if let Some(tag) = attr_value(e, b"PropertyTag") { + } else if local.eq_ignore_ascii_case("ExtendedFieldURI") { + if let Some(tag) = attr_value(e, "PropertyTag") { let t = tag.trim().to_ascii_lowercase(); in_flagstatus_ext = t == "0x1090" || t == "4240"; } - } else if in_flagstatus_ext && local.eq_ignore_ascii_case(b"Value") { + } else if in_flagstatus_ext && local.eq_ignore_ascii_case("Value") { current = Some("flagStatusExt"); } else { current = None; @@ -1016,7 +1014,7 @@ pub fn parse_message_item(inner_xml: &str) -> Result { } } Event::End(e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let lower = local.to_ascii_lowercase(); if let Some(field) = current.take() { let text = std::mem::take(&mut cur); @@ -1042,19 +1040,19 @@ pub fn parse_message_item(inner_xml: &str) -> Result { } } cur.clear(); - if lower == b"categories" { + if lower == "categories" { category_collecting = false; - } else if lower == b"flag" { + } else if lower == "flag" { in_flag = false; - } else if lower == b"extendedproperty" { + } else if lower == "extendedproperty" { in_flagstatus_ext = false; } } Event::Text(ref t) => { - cur.push_str(&t.decode().map(|c| c.into_owned()).unwrap_or_default()); + cur.push_str(t); } Event::CData(ref c) => { - cur.push_str(&String::from_utf8_lossy(c.as_ref())); + cur.push_str(c); } Event::GeneralRef(ref g) => { if let Some(c) = entity_to_char(g) { @@ -1198,7 +1196,7 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result let mut deleted_stack: Vec = Vec::new(); let mut in_modified = false; let mut in_deleted = false; - let mut recurrence_path: Vec> = Vec::new(); + let mut recurrence_path: Vec = Vec::new(); let mut recurrence_text: Option<&'static str> = None; let mut recurrence = RawRecurrence::default(); let mut pending = PendingRecurrence::default(); @@ -1210,10 +1208,10 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result let ns_kind = classify(&ns); match ev { Event::Start(ref e) | Event::Empty(ref e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let is_empty = matches!(ev, Event::Empty(_)); if item.element.is_empty() && is_item_element(&local) { - item.element = String::from_utf8_lossy(&local).into_owned(); + item.element = local.clone(); continue; } if ns_kind != Ns::Types { @@ -1221,39 +1219,39 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result } if !recurrence_path.is_empty() { recurrence_path.push(local.clone()); - if local.eq_ignore_ascii_case(b"Interval") { + if local.eq_ignore_ascii_case("Interval") { recurrence_text = Some("interval"); - } else if local.eq_ignore_ascii_case(b"DaysOfWeek") { + } else if local.eq_ignore_ascii_case("DaysOfWeek") { recurrence_text = Some("daysOfWeek"); - } else if local.eq_ignore_ascii_case(b"DayOfMonth") { + } else if local.eq_ignore_ascii_case("DayOfMonth") { recurrence_text = Some("dayOfMonth"); - } else if local.eq_ignore_ascii_case(b"DayOfWeekIndex") { + } else if local.eq_ignore_ascii_case("DayOfWeekIndex") { recurrence_text = Some("dayOfWeekIndex"); - } else if local.eq_ignore_ascii_case(b"Month") { + } else if local.eq_ignore_ascii_case("Month") { recurrence_text = Some("month"); - } else if local.eq_ignore_ascii_case(b"StartDate") { + } else if local.eq_ignore_ascii_case("StartDate") { recurrence_text = Some("startDate"); - } else if local.eq_ignore_ascii_case(b"EndDate") { + } else if local.eq_ignore_ascii_case("EndDate") { recurrence_text = Some("endDate"); - } else if local.eq_ignore_ascii_case(b"NumberOfOccurrences") { + } else if local.eq_ignore_ascii_case("NumberOfOccurrences") { recurrence_text = Some("numberOfOccurrences"); - } else if local.eq_ignore_ascii_case(b"DailyRecurrence") { + } else if local.eq_ignore_ascii_case("DailyRecurrence") { pending.pattern_choice = Some("Daily"); - } else if local.eq_ignore_ascii_case(b"WeeklyRecurrence") { + } else if local.eq_ignore_ascii_case("WeeklyRecurrence") { pending.pattern_choice = Some("Weekly"); - } else if local.eq_ignore_ascii_case(b"AbsoluteMonthlyRecurrence") { + } else if local.eq_ignore_ascii_case("AbsoluteMonthlyRecurrence") { pending.pattern_choice = Some("AbsoluteMonthly"); - } else if local.eq_ignore_ascii_case(b"RelativeMonthlyRecurrence") { + } else if local.eq_ignore_ascii_case("RelativeMonthlyRecurrence") { pending.pattern_choice = Some("RelativeMonthly"); - } else if local.eq_ignore_ascii_case(b"AbsoluteYearlyRecurrence") { + } else if local.eq_ignore_ascii_case("AbsoluteYearlyRecurrence") { pending.pattern_choice = Some("AbsoluteYearly"); - } else if local.eq_ignore_ascii_case(b"RelativeYearlyRecurrence") { + } else if local.eq_ignore_ascii_case("RelativeYearlyRecurrence") { pending.pattern_choice = Some("RelativeYearly"); - } else if local.eq_ignore_ascii_case(b"NoEndRecurrence") { + } else if local.eq_ignore_ascii_case("NoEndRecurrence") { pending.range_choice = Some("NoEnd"); - } else if local.eq_ignore_ascii_case(b"EndDateRecurrence") { + } else if local.eq_ignore_ascii_case("EndDateRecurrence") { pending.range_choice = Some("EndDate"); - } else if local.eq_ignore_ascii_case(b"NumberedRecurrence") { + } else if local.eq_ignore_ascii_case("NumberedRecurrence") { pending.range_choice = Some("Numbered"); } else { recurrence_text = None; @@ -1265,7 +1263,7 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result continue; } cur.clear(); - if local.eq_ignore_ascii_case(b"ItemId") { + if local.eq_ignore_ascii_case("ItemId") { if in_modified { if let Some(occ) = occurrence_stack.last_mut() { capture_id_attrs(e, &mut occ.item_id.id, &mut occ.item_id.change_key); @@ -1277,127 +1275,126 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result } else { capture_id_attrs(e, &mut item.id.id, &mut item.id.change_key); } - } else if local.eq_ignore_ascii_case(b"ParentFolderId") { + } else if local.eq_ignore_ascii_case("ParentFolderId") { let mut pid = String::new(); let mut ck = String::new(); capture_id_attrs(e, &mut pid, &mut ck); if !pid.is_empty() { item.parent_folder_id = Some(pid); } - } else if local.eq_ignore_ascii_case(b"UID") { + } else if local.eq_ignore_ascii_case("UID") { text_target = Some("uid"); - } else if local.eq_ignore_ascii_case(b"Subject") { + } else if local.eq_ignore_ascii_case("Subject") { text_target = Some("subject"); - } else if local.eq_ignore_ascii_case(b"Start") { + } else if local.eq_ignore_ascii_case("Start") { if in_modified || in_deleted { text_target = Some("occStart"); } else { text_target = Some("start"); } - } else if local.eq_ignore_ascii_case(b"End") { + } else if local.eq_ignore_ascii_case("End") { if in_modified || in_deleted { text_target = Some("occEnd"); } else { text_target = Some("end"); } - } else if local.eq_ignore_ascii_case(b"OriginalStart") { + } else if local.eq_ignore_ascii_case("OriginalStart") { if in_modified || in_deleted { text_target = Some("occOrig"); } else { text_target = Some("originalStart"); } - } else if local.eq_ignore_ascii_case(b"IsAllDayEvent") { + } else if local.eq_ignore_ascii_case("IsAllDayEvent") { text_target = Some("isAllDay"); - } else if local.eq_ignore_ascii_case(b"LegacyFreeBusyStatus") { + } else if local.eq_ignore_ascii_case("LegacyFreeBusyStatus") { text_target = Some("freeBusy"); - } else if local.eq_ignore_ascii_case(b"Location") { + } else if local.eq_ignore_ascii_case("Location") { text_target = Some("location"); - } else if local.eq_ignore_ascii_case(b"CalendarItemType") { + } else if local.eq_ignore_ascii_case("CalendarItemType") { text_target = Some("calendarItemType"); - } else if local.eq_ignore_ascii_case(b"RecurrenceId") { + } else if local.eq_ignore_ascii_case("RecurrenceId") { text_target = Some("recurrenceId"); - } else if local.eq_ignore_ascii_case(b"StartTimeZone") { - if let Some(v) = attr_value(e, b"Id") { + } else if local.eq_ignore_ascii_case("StartTimeZone") { + if let Some(v) = attr_value(e, "Id") { item.start_tz = Some(v); } - } else if local.eq_ignore_ascii_case(b"EndTimeZone") { - if let Some(v) = attr_value(e, b"Id") { + } else if local.eq_ignore_ascii_case("EndTimeZone") { + if let Some(v) = attr_value(e, "Id") { item.end_tz = Some(v); } - } else if local.eq_ignore_ascii_case(b"Recurrence") { + } else if local.eq_ignore_ascii_case("Recurrence") { recurrence_path.push(local.clone()); - } else if local.eq_ignore_ascii_case(b"ModifiedOccurrences") { + } else if local.eq_ignore_ascii_case("ModifiedOccurrences") { in_modified = true; - } else if local.eq_ignore_ascii_case(b"DeletedOccurrences") { + } else if local.eq_ignore_ascii_case("DeletedOccurrences") { in_deleted = true; - } else if local.eq_ignore_ascii_case(b"Occurrence") { + } else if local.eq_ignore_ascii_case("Occurrence") { let mut occ = RawOccurrence::default(); capture_id_attrs(e, &mut occ.item_id.id, &mut occ.item_id.change_key); occurrence_stack.push(occ); - } else if local.eq_ignore_ascii_case(b"DeletedOccurrence") { + } else if local.eq_ignore_ascii_case("DeletedOccurrence") { deleted_stack.push(RawOccurrence::default()); - } else if local.eq_ignore_ascii_case(b"Organizer") { + } else if local.eq_ignore_ascii_case("Organizer") { in_organizer = true; - } else if local.eq_ignore_ascii_case(b"RequiredAttendees") { + } else if local.eq_ignore_ascii_case("RequiredAttendees") { attendee_kind = Some("required"); - } else if local.eq_ignore_ascii_case(b"OptionalAttendees") { + } else if local.eq_ignore_ascii_case("OptionalAttendees") { attendee_kind = Some("optional"); - } else if local.eq_ignore_ascii_case(b"Resources") { + } else if local.eq_ignore_ascii_case("Resources") { attendee_kind = Some("resource"); - } else if local.eq_ignore_ascii_case(b"ReminderIsSet") { + } else if local.eq_ignore_ascii_case("ReminderIsSet") { text_target = Some("reminderIsSet"); - } else if local.eq_ignore_ascii_case(b"ReminderMinutesBeforeStart") { + } else if local.eq_ignore_ascii_case("ReminderMinutesBeforeStart") { text_target = Some("reminderMinutes"); - } else if local.eq_ignore_ascii_case(b"IsOnlineMeeting") { + } else if local.eq_ignore_ascii_case("IsOnlineMeeting") { text_target = Some("isOnlineMeeting"); - } else if local.eq_ignore_ascii_case(b"JoinOnlineMeetingUrl") { + } else if local.eq_ignore_ascii_case("JoinOnlineMeetingUrl") { text_target = Some("joinUrl"); - } else if local.eq_ignore_ascii_case(b"NetShowUrl") { + } else if local.eq_ignore_ascii_case("NetShowUrl") { text_target = Some("netShowUrl"); - } else if local.eq_ignore_ascii_case(b"MeetingWorkspaceUrl") { + } else if local.eq_ignore_ascii_case("MeetingWorkspaceUrl") { text_target = Some("workspaceUrl"); - } else if local.eq_ignore_ascii_case(b"Attendee") && attendee_kind.is_some() { + } else if local.eq_ignore_ascii_case("Attendee") && attendee_kind.is_some() { current_attendee = Some(RawAttendee::default()); - } else if local.eq_ignore_ascii_case(b"Mailbox") { + } else if local.eq_ignore_ascii_case("Mailbox") { in_mailbox = true; - } else if local.eq_ignore_ascii_case(b"Name") && in_mailbox { + } else if local.eq_ignore_ascii_case("Name") && in_mailbox { text_target = Some(if in_organizer { "organizerName" } else { "attendeeName" }); - } else if local.eq_ignore_ascii_case(b"EmailAddress") && in_mailbox { + } else if local.eq_ignore_ascii_case("EmailAddress") && in_mailbox { text_target = Some(if in_organizer { "organizerEmail" } else { "attendeeEmail" }); - } else if local.eq_ignore_ascii_case(b"RoutingType") && in_mailbox { + } else if local.eq_ignore_ascii_case("RoutingType") && in_mailbox { text_target = Some(if in_organizer { "organizerRouting" } else { "attendeeRouting" }); - } else if local.eq_ignore_ascii_case(b"ResponseType") && current_attendee.is_some() - { + } else if local.eq_ignore_ascii_case("ResponseType") && current_attendee.is_some() { text_target = Some("attendeeResponse"); - } else if local.eq_ignore_ascii_case(b"Categories") { + } else if local.eq_ignore_ascii_case("Categories") { category_collecting = true; - } else if category_collecting && local.eq_ignore_ascii_case(b"String") { + } else if category_collecting && local.eq_ignore_ascii_case("String") { text_target = Some("category"); - } else if local.eq_ignore_ascii_case(b"DateTimeCreated") { + } else if local.eq_ignore_ascii_case("DateTimeCreated") { text_target = Some("created"); - } else if local.eq_ignore_ascii_case(b"LastModifiedTime") { + } else if local.eq_ignore_ascii_case("LastModifiedTime") { text_target = Some("lastModified"); - } else if local.eq_ignore_ascii_case(b"Body") { - let body_type = attr_value(e, b"BodyType").unwrap_or_default(); + } else if local.eq_ignore_ascii_case("Body") { + let body_type = attr_value(e, "BodyType").unwrap_or_default(); text_target = Some(if body_type.eq_ignore_ascii_case("HTML") { "bodyHtml" } else { "bodyText" }); - } else if local.eq_ignore_ascii_case(b"FileAttachment") - || local.eq_ignore_ascii_case(b"ItemAttachment") + } else if local.eq_ignore_ascii_case("FileAttachment") + || local.eq_ignore_ascii_case("ItemAttachment") { let att = parse_attachment_ref(&mut xml, &local)?; item.attachments.push(att); @@ -1409,7 +1406,7 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result } } Event::End(e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let lower = local.to_ascii_lowercase(); if !recurrence_path.is_empty() { recurrence_path.pop(); @@ -1501,20 +1498,20 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result } cur.clear(); text_target = None; - match lower.as_slice() { - b"modifiedoccurrences" => in_modified = false, - b"deletedoccurrences" => in_deleted = false, - b"occurrence" => { + match lower.as_str() { + "modifiedoccurrences" => in_modified = false, + "deletedoccurrences" => in_deleted = false, + "occurrence" => { if let Some(occ) = occurrence_stack.pop() { item.modified_occurrences.push(occ); } } - b"deletedoccurrence" => { + "deletedoccurrence" => { if let Some(occ) = deleted_stack.pop() { item.deleted_occurrences.push(occ); } } - b"attendee" => { + "attendee" => { if let Some(att) = current_attendee.take() { match attendee_kind { Some("required") => item.required_attendees.push(att), @@ -1524,17 +1521,15 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result } } } - b"requiredattendees" | b"optionalattendees" | b"resources" => { - attendee_kind = None - } - b"organizer" => in_organizer = false, - b"mailbox" => in_mailbox = false, - b"categories" => category_collecting = false, + "requiredattendees" | "optionalattendees" | "resources" => attendee_kind = None, + "organizer" => in_organizer = false, + "mailbox" => in_mailbox = false, + "categories" => category_collecting = false, _ => {} } } Event::Text(ref t) => { - let text = t.decode().map(|c| c.into_owned()).unwrap_or_default(); + let text = t.as_ref().to_owned(); if !recurrence_path.is_empty() { match recurrence_text { Some("interval") => pending.interval = text.trim().parse().unwrap_or(1), @@ -1563,7 +1558,7 @@ pub fn parse_calendar_item(inner_xml: &str) -> Result } Event::CData(ref c) => { if recurrence_path.is_empty() { - cur.push_str(&String::from_utf8_lossy(c.as_ref())); + cur.push_str(c); } } Event::GeneralRef(ref g) => { @@ -1718,14 +1713,14 @@ pub fn parse_contact_item(inner_xml: &str) -> Result { let ns_kind = classify(&ns); match ev { Event::Start(ref e) | Event::Empty(ref e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let is_empty = matches!(ev, Event::Empty(_)); if !seen_root_contact - && (local.eq_ignore_ascii_case(b"Contact") - || local.eq_ignore_ascii_case(b"DistributionList")) + && (local.eq_ignore_ascii_case("Contact") + || local.eq_ignore_ascii_case("DistributionList")) { seen_root_contact = true; - if local.eq_ignore_ascii_case(b"DistributionList") { + if local.eq_ignore_ascii_case("DistributionList") { item.is_group = true; } continue; @@ -1734,91 +1729,91 @@ pub fn parse_contact_item(inner_xml: &str) -> Result { continue; } cur.clear(); - if local.eq_ignore_ascii_case(b"ItemId") { + if local.eq_ignore_ascii_case("ItemId") { capture_id_attrs(e, &mut item.id.id, &mut item.id.change_key); - } else if local.eq_ignore_ascii_case(b"ParentFolderId") { + } else if local.eq_ignore_ascii_case("ParentFolderId") { let mut pid = String::new(); let mut ck = String::new(); capture_id_attrs(e, &mut pid, &mut ck); if !pid.is_empty() { item.parent_folder_id = Some(pid); } - } else if local.eq_ignore_ascii_case(b"DisplayName") { + } else if local.eq_ignore_ascii_case("DisplayName") { text_target = Some("displayName"); - } else if local.eq_ignore_ascii_case(b"GivenName") { + } else if local.eq_ignore_ascii_case("GivenName") { text_target = Some("givenName"); - } else if local.eq_ignore_ascii_case(b"MiddleName") { + } else if local.eq_ignore_ascii_case("MiddleName") { text_target = Some("middleName"); - } else if local.eq_ignore_ascii_case(b"Surname") { + } else if local.eq_ignore_ascii_case("Surname") { text_target = Some("surname"); - } else if local.eq_ignore_ascii_case(b"Initials") { + } else if local.eq_ignore_ascii_case("Initials") { text_target = Some("initials"); - } else if local.eq_ignore_ascii_case(b"Nickname") { + } else if local.eq_ignore_ascii_case("Nickname") { text_target = Some("nickname"); - } else if local.eq_ignore_ascii_case(b"CompanyName") { + } else if local.eq_ignore_ascii_case("CompanyName") { text_target = Some("companyName"); - } else if local.eq_ignore_ascii_case(b"Department") { + } else if local.eq_ignore_ascii_case("Department") { text_target = Some("department"); - } else if local.eq_ignore_ascii_case(b"JobTitle") { + } else if local.eq_ignore_ascii_case("JobTitle") { text_target = Some("jobTitle"); - } else if local.eq_ignore_ascii_case(b"Generation") { + } else if local.eq_ignore_ascii_case("Generation") { text_target = Some("generation"); - } else if local.eq_ignore_ascii_case(b"OfficeLocation") { + } else if local.eq_ignore_ascii_case("OfficeLocation") { text_target = Some("officeLocation"); - } else if local.eq_ignore_ascii_case(b"BusinessHomePage") { + } else if local.eq_ignore_ascii_case("BusinessHomePage") { text_target = Some("url"); - } else if local.eq_ignore_ascii_case(b"Birthday") { + } else if local.eq_ignore_ascii_case("Birthday") { text_target = Some("birthday"); - } else if local.eq_ignore_ascii_case(b"WeddingAnniversary") { + } else if local.eq_ignore_ascii_case("WeddingAnniversary") { text_target = Some("weddingAnniversary"); - } else if local.eq_ignore_ascii_case(b"Manager") { + } else if local.eq_ignore_ascii_case("Manager") { text_target = Some("manager"); - } else if local.eq_ignore_ascii_case(b"SpouseName") { + } else if local.eq_ignore_ascii_case("SpouseName") { text_target = Some("spouse"); - } else if local.eq_ignore_ascii_case(b"AssistantName") { + } else if local.eq_ignore_ascii_case("AssistantName") { text_target = Some("assistant"); - } else if local.eq_ignore_ascii_case(b"Profession") { + } else if local.eq_ignore_ascii_case("Profession") { text_target = Some("profession"); - } else if local.eq_ignore_ascii_case(b"PostalAddressIndex") { + } else if local.eq_ignore_ascii_case("PostalAddressIndex") { text_target = Some("postalAddressIndex"); - } else if local.eq_ignore_ascii_case(b"Members") { + } else if local.eq_ignore_ascii_case("Members") { in_members = true; - } else if in_members && local.eq_ignore_ascii_case(b"Member") { + } else if in_members && local.eq_ignore_ascii_case("Member") { current_member = Some(RawGroupMember::default()); - } else if in_members && local.eq_ignore_ascii_case(b"Mailbox") { + } else if in_members && local.eq_ignore_ascii_case("Mailbox") { member_mailbox = true; - } else if member_mailbox && local.eq_ignore_ascii_case(b"Name") { + } else if member_mailbox && local.eq_ignore_ascii_case("Name") { text_target = Some("memberName"); - } else if member_mailbox && local.eq_ignore_ascii_case(b"EmailAddress") { + } else if member_mailbox && local.eq_ignore_ascii_case("EmailAddress") { text_target = Some("memberEmail"); - } else if local.eq_ignore_ascii_case(b"Body") { + } else if local.eq_ignore_ascii_case("Body") { text_target = Some("notes"); - } else if local.eq_ignore_ascii_case(b"DateTimeCreated") { + } else if local.eq_ignore_ascii_case("DateTimeCreated") { text_target = Some("created"); - } else if local.eq_ignore_ascii_case(b"LastModifiedTime") { + } else if local.eq_ignore_ascii_case("LastModifiedTime") { text_target = Some("lastModified"); - } else if local.eq_ignore_ascii_case(b"Categories") { + } else if local.eq_ignore_ascii_case("Categories") { category_collecting = true; - } else if category_collecting && local.eq_ignore_ascii_case(b"String") { + } else if category_collecting && local.eq_ignore_ascii_case("String") { text_target = Some("category"); - } else if local.eq_ignore_ascii_case(b"Children") { + } else if local.eq_ignore_ascii_case("Children") { children_collecting = true; - } else if children_collecting && local.eq_ignore_ascii_case(b"String") { + } else if children_collecting && local.eq_ignore_ascii_case("String") { text_target = Some("child"); - } else if local.eq_ignore_ascii_case(b"Companies") { + } else if local.eq_ignore_ascii_case("Companies") { companies_collecting = true; - } else if companies_collecting && local.eq_ignore_ascii_case(b"String") { + } else if companies_collecting && local.eq_ignore_ascii_case("String") { text_target = Some("company"); - } else if local.eq_ignore_ascii_case(b"EmailAddresses") { + } else if local.eq_ignore_ascii_case("EmailAddresses") { entry_container = Some("email"); - } else if local.eq_ignore_ascii_case(b"PhoneNumbers") { + } else if local.eq_ignore_ascii_case("PhoneNumbers") { entry_container = Some("phone"); - } else if local.eq_ignore_ascii_case(b"ImAddresses") { + } else if local.eq_ignore_ascii_case("ImAddresses") { entry_container = Some("im"); - } else if local.eq_ignore_ascii_case(b"PhysicalAddresses") { + } else if local.eq_ignore_ascii_case("PhysicalAddresses") { entry_container = Some("address"); - } else if local.eq_ignore_ascii_case(b"Entry") { - entry_key = attr_value(e, b"Key"); + } else if local.eq_ignore_ascii_case("Entry") { + entry_key = attr_value(e, "Key"); if entry_container == Some("address") { current_address = Some(RawContactAddress { key: entry_key.clone().unwrap_or_default(), @@ -1828,21 +1823,21 @@ pub fn parse_contact_item(inner_xml: &str) -> Result { text_target = Some("entryValue"); } } else if current_address.is_some() { - if local.eq_ignore_ascii_case(b"Street") { + if local.eq_ignore_ascii_case("Street") { address_text = Some("street"); - } else if local.eq_ignore_ascii_case(b"City") { + } else if local.eq_ignore_ascii_case("City") { address_text = Some("city"); - } else if local.eq_ignore_ascii_case(b"State") { + } else if local.eq_ignore_ascii_case("State") { address_text = Some("state"); - } else if local.eq_ignore_ascii_case(b"CountryOrRegion") { + } else if local.eq_ignore_ascii_case("CountryOrRegion") { address_text = Some("country"); - } else if local.eq_ignore_ascii_case(b"PostalCode") { + } else if local.eq_ignore_ascii_case("PostalCode") { address_text = Some("postal"); } else { address_text = None; } - } else if local.eq_ignore_ascii_case(b"FileAttachment") - || local.eq_ignore_ascii_case(b"ItemAttachment") + } else if local.eq_ignore_ascii_case("FileAttachment") + || local.eq_ignore_ascii_case("ItemAttachment") { let att = parse_attachment_ref(&mut xml, &local)?; item.attachments.push(att); @@ -1855,7 +1850,7 @@ pub fn parse_contact_item(inner_xml: &str) -> Result { } } Event::End(e) => { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let lower = local.to_ascii_lowercase(); if let Some(at) = address_text { if let Some(addr) = current_address.as_mut() { @@ -1922,22 +1917,22 @@ pub fn parse_contact_item(inner_xml: &str) -> Result { cur.clear(); text_target = None; address_text = None; - match lower.as_slice() { - b"categories" => category_collecting = false, - b"children" => children_collecting = false, - b"companies" => companies_collecting = false, - b"emailaddresses" | b"phonenumbers" | b"imaddresses" | b"physicaladdresses" => { + match lower.as_str() { + "categories" => category_collecting = false, + "children" => children_collecting = false, + "companies" => companies_collecting = false, + "emailaddresses" | "phonenumbers" | "imaddresses" | "physicaladdresses" => { entry_container = None } - b"entry" => { + "entry" => { if let Some(addr) = current_address.take() { item.addresses.push(addr); } entry_key = None; } - b"members" => in_members = false, - b"mailbox" => member_mailbox = false, - b"member" => { + "members" => in_members = false, + "mailbox" => member_mailbox = false, + "member" => { if let Some(m) = current_member.take() && (m.email.is_some() || m.name.is_some()) { @@ -1948,10 +1943,10 @@ pub fn parse_contact_item(inner_xml: &str) -> Result { } } Event::Text(ref t) => { - cur.push_str(&t.decode().map(|c| c.into_owned()).unwrap_or_default()); + cur.push_str(t); } Event::CData(ref c) => { - cur.push_str(&String::from_utf8_lossy(c.as_ref())); + cur.push_str(c); } Event::GeneralRef(ref g) => { if let Some(c) = entity_to_char(g) { @@ -1967,10 +1962,10 @@ pub fn parse_contact_item(inner_xml: &str) -> Result { fn parse_attachment_ref( xml: &mut NsReader, - element_local: &[u8], + element_local: &str, ) -> Result { let mut att = RawAttachmentRef { - is_item_attachment: element_local.eq_ignore_ascii_case(b"itemattachment"), + is_item_attachment: element_local.eq_ignore_ascii_case("itemattachment"), ..RawAttachmentRef::default() }; let mut buf = Vec::new(); @@ -1987,18 +1982,18 @@ fn parse_attachment_ref( if !is_empty { depth += 1; } - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); if ns_kind == Ns::Types { cur.clear(); - if local.eq_ignore_ascii_case(b"AttachmentId") { - if let Some(v) = attr_value(e, b"Id") { + if local.eq_ignore_ascii_case("AttachmentId") { + if let Some(v) = attr_value(e, "Id") { att.attachment_id = v; } - } else if local.eq_ignore_ascii_case(b"Name") { + } else if local.eq_ignore_ascii_case("Name") { current = Some("name"); - } else if local.eq_ignore_ascii_case(b"ContentType") { + } else if local.eq_ignore_ascii_case("ContentType") { current = Some("contentType"); - } else if local.eq_ignore_ascii_case(b"IsContactPhoto") { + } else if local.eq_ignore_ascii_case("IsContactPhoto") { current = Some("isContactPhoto"); } else { current = None; @@ -2030,10 +2025,10 @@ fn parse_attachment_ref( } } Event::Text(ref t) => { - cur.push_str(&t.decode().map(|c| c.into_owned()).unwrap_or_default()); + cur.push_str(t); } Event::CData(ref c) => { - cur.push_str(&String::from_utf8_lossy(c.as_ref())); + cur.push_str(c); } Event::GeneralRef(ref g) => { if let Some(c) = entity_to_char(g) { @@ -2069,27 +2064,27 @@ pub fn parse_get_attachment_inline(body: &[u8]) -> Result { - let local = e.local_name().as_ref().to_vec(); + let local = e.local_name().as_ref().to_owned(); let is_empty = matches!(ev, Event::Empty(_)); if ns_kind == Ns::Types - && (local.eq_ignore_ascii_case(b"FileAttachment") - || local.eq_ignore_ascii_case(b"ItemAttachment")) + && (local.eq_ignore_ascii_case("FileAttachment") + || local.eq_ignore_ascii_case("ItemAttachment")) { current = Some(GetAttachmentInline::default()); } else if let Some(cur) = current.as_mut() && ns_kind == Ns::Types { - if local.eq_ignore_ascii_case(b"AttachmentId") { - if let Some(v) = attr_value(e, b"Id") { + if local.eq_ignore_ascii_case("AttachmentId") { + if let Some(v) = attr_value(e, "Id") { cur.attachment_id = v; } - } else if local.eq_ignore_ascii_case(b"Name") { + } else if local.eq_ignore_ascii_case("Name") { text_target = Some("name"); - } else if local.eq_ignore_ascii_case(b"ContentType") { + } else if local.eq_ignore_ascii_case("ContentType") { text_target = Some("contentType"); - } else if local.eq_ignore_ascii_case(b"IsContactPhoto") { + } else if local.eq_ignore_ascii_case("IsContactPhoto") { text_target = Some("isContactPhoto"); - } else if local.eq_ignore_ascii_case(b"Content") { + } else if local.eq_ignore_ascii_case("Content") { text_target = Some("content"); } else { text_target = None; @@ -2100,9 +2095,9 @@ pub fn parse_get_attachment_inline(body: &[u8]) -> Result { - let local = e.local_name().as_ref().to_vec(); - if (local.eq_ignore_ascii_case(b"FileAttachment") - || local.eq_ignore_ascii_case(b"ItemAttachment")) + let local = e.local_name().as_ref().to_owned(); + if (local.eq_ignore_ascii_case("FileAttachment") + || local.eq_ignore_ascii_case("ItemAttachment")) && let Some(att) = current.take() { out.push(att); @@ -2111,8 +2106,8 @@ pub fn parse_get_attachment_inline(body: &[u8]) -> Result { let text = match ev { - Event::Text(ref t) => t.decode().map(|c| c.into_owned()).unwrap_or_default(), - Event::CData(ref c) => String::from_utf8_lossy(c.as_ref()).into_owned(), + Event::Text(ref t) => t.as_ref().to_owned(), + Event::CData(ref c) => c.as_ref().to_owned(), _ => unreachable!(), }; @@ -2261,7 +2256,7 @@ mod tests { \ " ); - let r = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let r = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); assert_eq!(r.len(), 2); assert!(r[0].success); assert!(r[0].inner_xml.contains("{message_xml}\ " ); - let r = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let r = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); parse_message_item(&r[0].inner_xml).unwrap() } @@ -2323,7 +2318,7 @@ mod tests { false\ " ); - let r = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let r = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); let p = parse_message_item(&r[0].inner_xml).unwrap(); assert_eq!( p.flag_status.as_deref(), @@ -2628,7 +2623,7 @@ mod tests { AT&T\ " ); - let msgs = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let msgs = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); assert!( msgs[0].inner_xml.contains("AT&T") || msgs[0].inner_xml.contains("AT&T"), "capture must preserve the entity for the per-item parser: {}", @@ -2684,7 +2679,7 @@ mod tests { \ " ); - let msgs = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let msgs = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); assert_eq!(msgs.len(), 1); let item = parse_message_item(&msgs[0].inner_xml).unwrap(); assert_eq!(item.id.id, "NP1"); @@ -2758,7 +2753,7 @@ mod tests { \ " ); - let r = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let r = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); assert_eq!(r.len(), 1); assert!(r[0].success, "Warning should be success-equivalent"); } @@ -2776,7 +2771,7 @@ mod tests { ErrorAccessDenied\ " ); - let msgs = parse_response_messages(body.as_bytes(), b"GetFolderResponseMessage").unwrap(); + let msgs = parse_response_messages(body.as_bytes(), "GetFolderResponseMessage").unwrap(); assert_eq!(msgs.len(), 2); assert!(msgs[0].success); let f = parse_folder_inner(&msgs[0].inner_xml).unwrap().unwrap(); diff --git a/src/imap/client.rs b/src/imap/client.rs index 5d1c8cd..066ce26 100644 --- a/src/imap/client.rs +++ b/src/imap/client.rs @@ -655,6 +655,16 @@ mod tests { c.authenticate_plain("alice", "p@ss").unwrap(); } + #[test] + fn authenticate_plain_accepts_dovecot_post_login_untagged_capability() { + let server = b"* CAPABILITY IMAP4rev1 SASL-IR MOVE IMAPSIEVE=sieve://127.0.0.1:4190 QUOTA\r\nA0001 OK [CAPABILITY IMAP4rev1 SASL-IR MOVE IMAPSIEVE=sieve://127.0.0.1:4190 QUOTA] Logged in\r\n"; + let mut c = client_with(server); + c.capabilities.insert("SASL-IR".to_owned()); + c.authenticate_plain("alice", "p@ss").unwrap(); + assert!(c.has_capability("MOVE")); + assert!(c.has_capability("IMAPSIEVE=sieve://127.0.0.1:4190")); + } + #[test] fn authenticate_plain_continuation_path() { let server = b"+ \r\nA0001 OK auth done\r\n"; diff --git a/src/imap/response.rs b/src/imap/response.rs index 898f553..1bbc097 100644 --- a/src/imap/response.rs +++ b/src/imap/response.rs @@ -190,17 +190,7 @@ impl<'r, R: BufRead> Parser<'r, R> { } Ok(Untagged::StatusLine(line)) } - "CAPABILITY" => { - let mut caps = Vec::new(); - while !self.at_end() { - self.skip_ws(); - if self.at_end() { - break; - } - caps.push(self.read_atom_string()?); - } - Ok(Untagged::Capability(caps)) - } + "CAPABILITY" => Ok(Untagged::Capability(self.read_space_separated()?)), "LIST" | "LSUB" => { self.skip_ws(); self.expect(b'(')?; @@ -300,17 +290,7 @@ impl<'r, R: BufRead> Parser<'r, R> { Ok(Untagged::Flags(flags)) } "NAMESPACE" => self.parse_namespace(), - "ENABLED" => { - let mut exts = Vec::new(); - while !self.at_end() { - self.skip_ws(); - if self.at_end() { - break; - } - exts.push(self.read_atom_string()?); - } - Ok(Untagged::Enabled(exts)) - } + "ENABLED" => Ok(Untagged::Enabled(self.read_space_separated()?)), _ => { if let Ok(num) = upper.parse::() { self.skip_ws(); @@ -651,6 +631,15 @@ impl<'r, R: BufRead> Parser<'r, R> { .map_err(|e| ImapError::Parse(format!("non-utf8 atom: {e}"))) } + fn read_space_separated(&mut self) -> Result, ImapError> { + let end = self.buf.len().saturating_sub(self.tail_crlf_len()); + let rest = self.buf.get(self.pos..end).unwrap_or_default(); + self.pos = self.pos.max(end); + std::str::from_utf8(rest) + .map(|s| s.split_ascii_whitespace().map(str::to_owned).collect()) + .map_err(|e| ImapError::Parse(format!("non-utf8 token: {e}"))) + } + fn read_seq_set_token(&mut self) -> String { let start = self.pos; while let Some(b) = self.peek() { @@ -735,10 +724,7 @@ impl<'r, R: BufRead> Parser<'r, R> { } fn is_atom_byte(b: u8) -> bool { - matches!(b, b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' - | b'-' | b'.' | b'_' | b'!' | b'#' | b'$' | b'&' - | b'\'' | b'+' | b'/' | b';' | b'<' | b'=' | b'>' | b'?' - | b'@' | b'\\' | b'^' | b'`' | b'|' | b'~' | b'*') + b.is_ascii_graphic() && !matches!(b, b'(' | b')' | b'{' | b'%' | b'"' | b']') } fn parse_seq_set(s: &str) -> Vec { @@ -833,6 +819,60 @@ mod tests { } } + #[test] + fn untagged_capability_accepts_uri_valued_tokens() { + let r = parse( + b"* CAPABILITY IMAP4rev1 SASL-IR SPECIAL-USE IMAPSIEVE=sieve://127.0.0.1:4190 QUOTA ACL RIGHTS=texk\r\n", + ); + match r { + Response::Untagged(Untagged::Capability(caps)) => assert_eq!( + caps, + vec![ + "IMAP4rev1", + "SASL-IR", + "SPECIAL-USE", + "IMAPSIEVE=sieve://127.0.0.1:4190", + "QUOTA", + "ACL", + "RIGHTS=texk", + ] + ), + other => panic!("expected Capability, got {other:?}"), + } + } + + #[test] + fn untagged_enabled_accepts_non_atom_tokens() { + let r = parse(b"* ENABLED UTF8=ACCEPT X-VENDOR=a:b,c\r\n"); + match r { + Response::Untagged(Untagged::Enabled(exts)) => { + assert_eq!(exts, vec!["UTF8=ACCEPT", "X-VENDOR=a:b,c"]); + } + other => panic!("expected Enabled, got {other:?}"), + } + } + + #[test] + fn atom_accepts_colon_comma_and_brackets() { + let r = parse(b"* LIST (\\HasNoChildren) \"/\" Work:2026,Q1[a}\r\n"); + match r { + Response::Untagged(Untagged::List { name, .. }) => { + assert_eq!(name, "Work:2026,Q1[a}"); + } + other => panic!("expected List, got {other:?}"), + } + } + + #[test] + fn atom_stops_at_atom_specials() { + for b in b"(){%\"] \x7f\x00" { + assert!(!is_atom_byte(*b), "{b:#04x} must not be an atom byte"); + } + for b in b":,[}=/.-_+" { + assert!(is_atom_byte(*b), "{:?} must be an atom byte", *b as char); + } + } + #[test] fn quoted_mailbox_name_with_utf8_bytes_is_decoded_as_utf8() { let r = parse("* LIST (\\HasNoChildren) \"/\" \"Envoy\u{e9}s\"\r\n".as_bytes()); diff --git a/src/sync/import_exchange_ews/folders.rs b/src/sync/import_exchange_ews/folders.rs index 1df194b..fc4a791 100644 --- a/src/sync/import_exchange_ews/folders.rs +++ b/src/sync/import_exchange_ews/folders.rs @@ -131,7 +131,7 @@ fn resolve_well_known_roles( } }; let messages = - parse_response_messages(&resp.body, b"GetFolderResponseMessage").unwrap_or_default(); + parse_response_messages(&resp.body, "GetFolderResponseMessage").unwrap_or_default(); let mut map: HashMap = HashMap::new(); for (msg, (_, role)) in messages.into_iter().zip(WELL_KNOWN_ROLES.iter()) { if !msg.success { diff --git a/src/sync/import_exchange_ews/items.rs b/src/sync/import_exchange_ews/items.rs index fec72f5..7439c91 100644 --- a/src/sync/import_exchange_ews/items.rs +++ b/src/sync/import_exchange_ews/items.rs @@ -294,7 +294,7 @@ pub fn get_items( for chunk in ids.chunks(batch) { let body = get_item_body(shape, chunk, version); match ctx.client.call(ctx.url, "GetItem", &body) { - Ok(resp) => match parse_response_messages(&resp.body, b"GetItemResponseMessage") { + Ok(resp) => match parse_response_messages(&resp.body, "GetItemResponseMessage") { Ok(mut msgs) => all.append(&mut msgs), Err(e) if is_per_batch_fault(&e) => { ctx.logger.warn(&format!( @@ -331,7 +331,7 @@ pub fn get_items( let body = get_item_body(shape, &chunk, version); let n = chunk.len(); let result = match client.call(&url, "GetItem", &body) { - Ok(resp) => parse_response_messages(&resp.body, b"GetItemResponseMessage"), + Ok(resp) => parse_response_messages(&resp.body, "GetItemResponseMessage"), Err(e) => Err(e), }; (n, result) diff --git a/tests/integration/dovecot.rs b/tests/integration/dovecot.rs index 7ce33f3..ccb46ee 100644 --- a/tests/integration/dovecot.rs +++ b/tests/integration/dovecot.rs @@ -82,6 +82,10 @@ service managesieve-login { } } +protocol imap { + mail_plugins = $mail_plugins imap_sieve +} + protocol sieve { managesieve_max_line_length = 1M managesieve_max_compile_errors = 5 @@ -96,6 +100,7 @@ info_log_path = /dev/stderr plugin { sieve = file:~/sieve;active=~/.dovecot.sieve sieve_max_script_size = 1M + imapsieve_url = sieve://127.0.0.1:4190 } "#; @@ -139,6 +144,7 @@ impl Dovecot { let host = container.get_host()?.to_string(); let imap = Endpoint::new(host.clone(), container.get_host_port_ipv4(IMAP_PORT.tcp())?); let sieve = Endpoint::new(host, container.get_host_port_ipv4(SIEVE_PORT.tcp())?); + ImapSeed::connect(&imap.host, imap.port)?.logout()?; let accounts: Vec = layouts::accounts() .iter() diff --git a/tests/integration/stalwart.rs b/tests/integration/stalwart.rs index bd71818..01dfeec 100644 --- a/tests/integration/stalwart.rs +++ b/tests/integration/stalwart.rs @@ -74,7 +74,7 @@ impl Stalwart { .with_mapped_port(sieve_port, SIEVE_PORT.tcp()) .with_startup_timeout(Duration::from_secs(180)); - let container = request.start()?; + let container = request.pull_image()?.start()?; let me = Self { _container: container, diff --git a/tests/integration_dovecot.rs b/tests/integration_dovecot.rs index 77bdcf6..f99e8ba 100644 --- a/tests/integration_dovecot.rs +++ b/tests/integration_dovecot.rs @@ -18,6 +18,9 @@ use integration::validate::{ use rusqlite::Connection; use vandelay::error::Error; +use vandelay::imap::client::{ConnectMode, ImapClient}; +use vandelay::imap::transport::Connector; +use vandelay::logging::Logger; use vandelay::sync::import_imap::{ImapAuth, ImapImportConfig}; use vandelay::sync::import_managesieve::{ManageSieveAuth, ManageSieveImportConfig}; use vandelay::sync::{import_imap, import_managesieve}; @@ -561,3 +564,28 @@ fn dovecot_non_ascii_mailbox_names_round_trip() { ); cleanup(&archive); } + +#[test] +#[ignore = "requires Docker"] +fn dovecot_post_login_capability_with_imapsieve_url_is_parsed() { + let d = Dovecot::start().expect("dovecot start"); + let account = d.accounts.first().expect("account"); + let connector = Connector::new(true).expect("connector"); + let mut client = ImapClient::connect( + &connector, + &d.imap.host, + d.imap.port, + ConnectMode::StartTls, + Logger::from_flags(false, 0), + ) + .expect("connect"); + assert!(client.has_capability("SASL-IR")); + client + .authenticate_plain(&account.username, &account.password) + .expect("AUTHENTICATE PLAIN must survive the untagged post-login CAPABILITY"); + assert!( + client.has_capability("IMAPSIEVE=sieve://127.0.0.1:4190"), + "post-login capabilities must carry the IMAPSIEVE URL: {:?}", + client.capabilities + ); +} diff --git a/tests/mock_exchange_ews.rs b/tests/mock_exchange_ews.rs index aa0c87f..f4dd7ac 100644 --- a/tests/mock_exchange_ews.rs +++ b/tests/mock_exchange_ews.rs @@ -221,7 +221,7 @@ fn get_item_mixed_success_and_per_item_error() { \ " )); - let r = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let r = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); assert_eq!(r.len(), 2); assert!(r[0].success); assert!(r[0].inner_xml.contains("SGVsbG8=")); @@ -312,7 +312,7 @@ fn mime_content_round_trips_through_base64_decode() { \ " )); - let r = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let r = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); let item = vandelay::exchange_ews::parse::parse_message_item(&r[0].inner_xml).unwrap(); let s = item.mime_content.unwrap(); let bytes = LENIENT.decode(&s).unwrap(); @@ -890,7 +890,7 @@ fn warning_response_class_is_treated_as_success_in_mock() { \ " )); - let r = parse_response_messages(body.as_bytes(), b"GetItemResponseMessage").unwrap(); + let r = parse_response_messages(body.as_bytes(), "GetItemResponseMessage").unwrap(); assert!(r[0].success); } @@ -930,7 +930,7 @@ fn get_folder_messages_preserve_position_when_one_errors() { \ " )); - let msgs = parse_response_messages(body.as_bytes(), b"GetFolderResponseMessage").unwrap(); + let msgs = parse_response_messages(body.as_bytes(), "GetFolderResponseMessage").unwrap(); assert_eq!(msgs.len(), 3, "all three messages must be present"); assert!(msgs[0].success); assert!(!msgs[1].success); diff --git a/tests/mock_imap.rs b/tests/mock_imap.rs index a7e194c..4ec2ab7 100644 --- a/tests/mock_imap.rs +++ b/tests/mock_imap.rs @@ -487,26 +487,35 @@ fn write_fetch_message( conn.write_raw(b")\r\n") } +fn serve_one_folder( + conn: &mut MockConn, + uidvalidity: u32, + uidnext: u32, + uids: &[u32], +) -> std::io::Result<()> { + let (tag, cmd) = conn.read_command()?; + assert_eq!(cmd, "LIST \"\" \"*\""); + conn.write_line("* LIST () \"/\" \"INBOX\"")?; + conn.write_line(&format!("{tag} OK LIST done"))?; + let (tag, cmd) = conn.read_command()?; + assert_eq!(cmd, "LSUB \"\" \"*\""); + conn.write_line(&format!("{tag} OK LSUB done"))?; + let (tag, cmd) = conn.read_command()?; + assert_eq!(cmd, "SELECT \"INBOX\""); + write_select(conn, &tag, uidvalidity, uidnext, uids.len() as u32)?; + let (tag, cmd) = conn.read_command()?; + assert_eq!(cmd, "UID SEARCH ALL"); + let uid_strs: Vec = uids.iter().map(|u| u.to_string()).collect(); + conn.write_line(&format!("* SEARCH {}", uid_strs.join(" ")))?; + conn.write_line(&format!("{tag} OK SEARCH done"))?; + drain_until_close(conn); + Ok(()) +} + fn control_script_one_folder(uidvalidity: u32, uidnext: u32, uids: &'static [u32]) -> Script { Box::new(move |conn: &mut MockConn| -> std::io::Result<()> { auth_preamble(conn, "IMAP4rev2 LITERAL+ AUTH=PLAIN")?; - let (tag, cmd) = conn.read_command()?; - assert_eq!(cmd, "LIST \"\" \"*\""); - conn.write_line("* LIST () \"/\" \"INBOX\"")?; - conn.write_line(&format!("{tag} OK LIST done"))?; - let (tag, cmd) = conn.read_command()?; - assert_eq!(cmd, "LSUB \"\" \"*\""); - conn.write_line(&format!("{tag} OK LSUB done"))?; - let (tag, cmd) = conn.read_command()?; - assert_eq!(cmd, "SELECT \"INBOX\""); - write_select(conn, &tag, uidvalidity, uidnext, uids.len() as u32)?; - let (tag, cmd) = conn.read_command()?; - assert_eq!(cmd, "UID SEARCH ALL"); - let uid_strs: Vec = uids.iter().map(|u| u.to_string()).collect(); - conn.write_line(&format!("* SEARCH {}", uid_strs.join(" ")))?; - conn.write_line(&format!("{tag} OK SEARCH done"))?; - drain_until_close(conn); - Ok(()) + serve_one_folder(conn, uidvalidity, uidnext, uids) }) } @@ -583,6 +592,63 @@ fn coordinator_imports_one_folder_one_message() { assert_eq!(folder_role(&conn, "INBOX"), Some("inbox".to_owned())); } +const DOVECOT_PRE_LOGIN_CAPS: &str = + "IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN"; +const DOVECOT_POST_LOGIN_CAPS: &str = "IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT \ + UIDPLUS LITERAL+ NOTIFY IMAPSIEVE=sieve://127.0.0.1:4190 \ + QUOTA ACL RIGHTS=texk"; + +#[test] +fn coordinator_accepts_dovecot_post_login_capability_with_imapsieve_url() { + let control: Script = Box::new(|conn: &mut MockConn| -> std::io::Result<()> { + conn.write_line(&format!( + "* OK [CAPABILITY {DOVECOT_PRE_LOGIN_CAPS}] Dovecot (Debian) ready." + ))?; + let (tag, cmd) = conn.read_command()?; + assert_eq!(cmd, "CAPABILITY"); + write_capability(conn, DOVECOT_PRE_LOGIN_CAPS)?; + conn.write_line(&format!( + "{tag} OK Pre-login capabilities listed, post-login capabilities have more." + ))?; + let (tag, cmd) = conn.read_command()?; + assert!( + cmd.starts_with("AUTHENTICATE PLAIN "), + "expected SASL-IR form, got {cmd}" + ); + write_capability(conn, DOVECOT_POST_LOGIN_CAPS)?; + conn.write_line(&format!( + "{tag} OK [CAPABILITY {DOVECOT_POST_LOGIN_CAPS}] Logged in" + ))?; + let (tag, cmd) = conn.read_command()?; + assert_eq!(cmd, "CAPABILITY"); + write_capability(conn, DOVECOT_POST_LOGIN_CAPS)?; + conn.write_line(&format!("{tag} OK Capability completed."))?; + serve_one_folder(conn, 12345, 2, &[1]) + }); + let server = MockImap::start_scripts(vec![ + control, + worker_fetch_script( + "IMAP4rev1 SASL-IR LITERAL+ AUTH=PLAIN IMAPSIEVE=sieve://127.0.0.1:4190", + "INBOX", + 12345, + 2, + 1, + vec![(1, 1, MSG_BODY)], + ), + ]); + let archive = tempfile("dovecot-imapsieve"); + let summary = run_import(&server, "alice", archive.clone(), |_| {}).expect("import"); + let email = summary + .per_type + .iter() + .find(|(k, _)| *k == "email") + .unwrap(); + assert_eq!(email.1.created, 1, "summary={summary:?}"); + let conn = Connection::open(&archive).unwrap(); + db::init::apply_schema(&conn).unwrap(); + assert_eq!(count(&conn, "emails"), 1); +} + #[test] fn coordinator_uses_esearch_when_advertised() { let control: Script = Box::new(|conn: &mut MockConn| -> std::io::Result<()> { diff --git a/tests/seeder/admin.rs b/tests/seeder/admin.rs index 9aa6fc6..5a3f954 100644 --- a/tests/seeder/admin.rs +++ b/tests/seeder/admin.rs @@ -197,7 +197,7 @@ impl Admin { "encryptionAtRest": { "@type": "Disabled" }, "permissions": { "@type": "Inherit" }, "roles": { "@type": role }, - "locale": "en_US" + "locale": "en-US" } }); let response = diff --git a/tests/sync_jmap.rs b/tests/sync_jmap.rs index a995280..bd51ef4 100644 --- a/tests/sync_jmap.rs +++ b/tests/sync_jmap.rs @@ -1243,6 +1243,10 @@ fn apply_jmap_settings( .is_some(), "x:Jmap/set not applied: {resp}" ); + assert!( + resp.pointer("/methodResponses/1/1/created/r").is_some(), + "ReloadSettings failed, so the x:Jmap/set values are not in effect: {resp}" + ); } #[test] @@ -1255,8 +1259,13 @@ fn live_blob_quota_429_triggers_retry_after_then_succeeds() { let fx = seeder::provision(base_url()).expect("provision"); let acc = fx.account("test1").expect("test1"); + let blob_size = 8 * 1024 * 1024; let mut updates = serde_json::Map::new(); updates.insert("uploadTtl".to_owned(), serde_json::json!(5_000)); + updates.insert( + "uploadQuota".to_owned(), + serde_json::json!(blob_size * 5 / 2), + ); let _ttl_guard = JmapSettingsGuard::override_settings(updates); let client = HttpClient::new(basic("test1"), RetryPolicy::new(20), true); @@ -1264,7 +1273,6 @@ fn live_blob_quota_429_triggers_retry_after_then_succeeds() { let limits = session.core_limits().expect("core limits"); client.set_limits(&limits); - let blob_size = 8 * 1024 * 1024; let mut blob = vec![0u8; blob_size]; let max_uploads = 8u32; let mut accepted = 0u32;