### Quick Start Source: https://docs.rs/minicaldav/latest/index.html This code snippet demonstrates how to use the minicaldav crate to fetch calendars and events from a CalDAV endpoint. ```rust let agent = ureq::Agent::new(); let url = url::Url::parse("http://mycaldav.com/").unwrap(); let username = "foo"; let password = "s3cret!"; let credentials = minicaldav::Credentials::Basic(username.into(), password.into()); let calendars = minicaldav::get_calendars(agent.clone(), &credentials, &url).unwrap(); for calendar in calendars { println!("{:?}", calendar); let credentials = minicaldav::Credentials::Basic(username.into(), password.into()); let (events, errors) = minicaldav::get_events(agent.clone(), &credentials, &calendar).unwrap(); for event in events { println!("{:?}", event); } for error in errors { println!("Error: {:?}", error); } } ``` -------------------------------- ### Example iCalendar Event Structure Source: https://docs.rs/minicaldav/latest/src/minicaldav/ical.rs.html Illustrates the structure of an iCalendar event with various properties and a nested VEVENT. ```rust Ical { name: "VCALENDAR".into(), properties: vec![ Property::new("VERSION", "2.0"), Property::new("PRODID", "-//Example Corp.//Example Calendar//EN"), Property::new("CALSCALE", "GREGORIAN"), Property::new("METHOD", "PUBLISH"), ], children: vec![ Ical { name: "VEVENT".into(), properties: vec![ Property::new("SUMMARY", "Abraham Lincoln"), Property::new("UID", "c7614cff-3549-4a00-9152-d25cc1fe077d"), Property::new("SEQUENCE", "0"), Property::new("STATUS", "CONFIRMED"), Property::new("TRANSP", "TRANSPARENT"), Property::new("RRULE", "FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12"), Property::new("DTSTART", "20080212"), Property::new("DTEND", "20080213"), Property::new("DTSTAMP", "20150421T141403"), Property::new("CATEGORIES", "U.S. Presidents,Civil War People"), Property::new("LOCATION", "Hodgenville\\, Kentucky"), Property::new("GEO", "37.5739497;-85.7399606"), Property::new("DESCRIPTION", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"), Property::new("URL", "http://americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincoln"), ], children: vec![] } ] }) ``` -------------------------------- ### HomeSet Request Body Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html XML body for a PROPFIND request to get the calendar home set. ```xml ``` -------------------------------- ### Parsing iCalendar Data Source: https://docs.rs/minicaldav/latest/src/minicaldav/ical.rs.html Example of parsing a string containing iCalendar data into a `Cal` object and asserting specific properties. ```rust let ical = "BEGIN:VCALENDAR\nCALSCALE:GREGORIAN\nPRODID:-//Apple Inc.//iOS 13.2//EN\nVERSION:2.0\nBEGIN:VTIMEZONE\nTZID:America/Vancouver\nBEGIN:DAYLIGHT\nDTSTART:20070311T020000\nRRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\nTZNAME:GMT-7\nTZOFFSETFROM:-0800\nTZOFFSETTO:-0700\nEND:DAYLIGHT\nBEGIN:STANDARD\nDTSTART:20071104T020000\nRRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\nTZNAME:GMT-8\nTZOFFSETFROM:-0700\nTZOFFSETTO:-0800\nEND:STANDARD\nEND:VTIMEZONE\nBEGIN:VEVENT\nCREATED:20191002T181641Z\nDTEND;TZID=America/Vancouver:20191014T090000\nDTSTAMP:20191014T050818Z\nDTSTART;TZID=America/Vancouver:20191014T070000\nLAST-MODIFIED:20191002T181641Z\nLOCATION:312 Boren Ave South\nSeattle WA 98144\nUSA\nSEQUENCE:0\nSUMMARY:Truline Swaybar Bushing Installation\nTRANSP:OPAQUE\nUID:2DC25870-241F-4279-9720-AB26C8DA5A60\nURL;VALUE=URI:\nX-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=312 Boren Ave South\\nSe\n attle WA 98144\\nUSA;X-APPLE-ABUID=Doug Tate Tru-Line’s Work;X-APPLE-MAP\n KIT-HANDLE=CAESjQIIwjsaEglN7OsKx8xHQBF/pyRGKpRewCKEAQoNVW5pdGVkIFN0YXRlc\n xICVVMaCldhc2hpbmd0b24iAldBKgRLaW5nMgdTZWF0dGxlOgU5ODE0NEIIQXRsYW50aWNSC\n 0JvcmVuIEF2ZSBTWgMzMTJiDzMxMiBCb3JlbiBBdmUgU4oBEENlbnRyYWwgRGlzdHJpY3SKA\n QhBdGxhbnRpYyoPMzEyIEJvcmVuIEF2ZSBTMg8zMTIgQm9yZW4gQXZlIFMyElNlYXR0bGUsI\n FdBICA5ODE0NDINVW5pdGVkIFN0YXRlczg5QARaJAoiEhIJTezrCsfMR0ARf6ckRiqUXsAYw\n jsgodmfx+vg0YSuAQ==;X-APPLE-RADIUS=22.28845908357249;X-APPLE-REFERENCEFR\nAME=1;X-TITLE=312 Boren Ave South\\nSeattle WA 98144\\nUSA:geo:47.599824\n ,-122.315080\nX-APPLE-TRAVEL-ADVISORY-BEHAVIOR:DISABLED\nBEGIN:VALARM\nACTION:DISPLAY\nDESCRIPTION:Reminder\nTRIGGER:-PT30M\nUID:02D84865-7611-4380-9B6E-41EAE7D4A6C8\nX-WR-ALARMUID:02D84865-7611-4380-9B6E-41EAE7D4A6C8\nEND:VALARM\nBEGIN:VALARM\nACTION:DISPLAY\nDESCRIPTION:Reminder\nTRIGGER:-P1D\nUID:087E2F5A-0104-4DAE-B6C7-E63A50A52B03\nX-WR-ALARMUID:087E2F5A-0104-4DAE-B6C7-E63A50A52B03\nEND:VALARM\nEND:VEVENT\nEND:VCALENDAR\n ``` ```rust let ical = r#"BEGIN:VCALENDAR CALSCALE:GREGORIAN PRODID:-//Apple Inc.//iOS 13.2//EN VERSION:2.0 BEGIN:VTIMEZONE TZID:America/Vancouver BEGIN:DAYLIGHT DTSTART:20070311T020000 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU TZNAME:GMT-7 TZOFFSETFROM:-0800 TZOFFSETTO:-0700 END:DAYLIGHT BEGIN:STANDARD DTSTART:20071104T020000 RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU TZNAME:GMT-8 TZOFFSETFROM:-0700 TZOFFSETTO:-0800 END:STANDARD END:VTIMEZONE BEGIN:VEVENT CREATED:20191002T181641Z DTEND;TZID=America/Vancouver:20191014T090000 DTSTAMP:20191014T050818Z DTSTART;TZID=America/Vancouver:20191014T070000 LAST-MODIFIED:20191002T181641Z LOCATION:312 Boren Ave South\nSeattle WA 98144\nUSA SEQUENCE:0 SUMMARY:Truline Swaybar Bushing Installation TRANSP:OPAQUE UID:2DC25870-241F-4279-9720-AB26C8DA5A60 URL;VALUE=URI: X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=312 Boren Ave South\nSe attle WA 98144\nUSA;X-APPLE-ABUID=Doug Tate Tru-Line’s Work;X-APPLE-MAP KIT-HANDLE=CAESjQIIwjsaEglN7OsKx8xHQBF/pyRGKpRewCKEAQoNVW5pdGVkIFN0YXRlc xICVVMaCldhc2hpbmd0b24iAldBKgRLaW5nMgdTZWF0dGxlOgU5ODE0NEIIQXRsYW50aWNSC 0JvcmVuIEF2ZSBTWgMzMTJiDzMxMiBCb3JlbiBBdmUgU4oBEENlbnRyYWwgRGlzdHJpY3SKA QhBdGxhbnRpYyoPMzEyIEJvcmVuIEF2ZSBTMg8zMTIgQm9yZW4gQXZlIFMyElNlYXR0bGUsI FdBICA5ODE0NDINVW5pdGVkIFN0YXRlczg5QARaJAoiEhIJTezrCsfMR0ARf6ckRiqUXsAYw jsgodmfx+vg0YSuAQ==;X-APPLE-RADIUS=22.28845908357249;X-APPLE-REFERENCEFR AME=1;X-TITLE=312 Boren Ave South\nSeattle WA 98144\nUSA:geo:47.599824 ,-122.315080 X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:DISABLED BEGIN:VALARM ACTION:DISPLAY DESCRIPTION:Reminder TRIGGER:-PT30M UID:02D84865-7611-4380-9B6E-41EAE7D4A6C8 X-WR-ALARMUID:02D84865-7611-4380-9B6E-41EAE7D4A6C8 END:VALARM BEGIN:VALARM ACTION:DISPLAY DESCRIPTION:Reminder TRIGGER:-P1D UID:087E2F5A-0104-4DAE-B6C7-E63A50A52B03 X-WR-ALARMUID:087E2F5A-0104-4DAE-B6C7-E63A50A52B03 END:VALARM END:VEVENT END:VCALENDAR "#; let parsed = Ical::parse(&LineIterator::new(ical)); assert!(parsed.is_ok()); let cal = parsed.unwrap(); let apple_location = &cal.children[1].properties[11]; assert_eq!(apple_location.name, "X-APPLE-STRUCTURED-LOCATION"); assert_eq!(apple_location.value, "geo:47.599824,-122.315080"); } ``` -------------------------------- ### Get Todos Function Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html Rust function to fetch calendar todos from a CalDAV server using a REPORT request. ```rust pub fn get_todos( client: Agent, credentials: &Credentials, base_url: &Url, calendar_ref: &CalendarRef, ) -> Result, Error> { let auth = get_auth_header(credentials); let content = client .request("REPORT", calendar_ref.url.as_str()) .set("Authorization", &auth) .set("Depth", "1") .set("Content-Type", "application/xml") .send_bytes(CALENDAR_TODOS_REQUEST.as_bytes())? .into_string() .map_err(|e| Error { kind: ErrorKind::Parsing, message: e.to_string(), })?; trace!("Read CalDAV events: {:?}", content); let reader = content.as_bytes(); let root = xmltree::Element::parse(reader)?; let mut todos = Vec::new(); for c in &root.children { if let Some(child) = c.as_element() { let href = child.get_child("href").and_then(|e| e.get_text()); let etag = child .get_child("propstat") .and_then(|e| e.get_child("prop")) .and_then(|e| e.get_child("getetag")) .and_then(|e| e.get_text()) .map(|e| e.to_string()); let data = child .get_child("propstat") ``` -------------------------------- ### Get all todos in the given `Calendar`. Source: https://docs.rs/minicaldav/latest/src/minicaldav/api.rs.html Function to retrieve all todos from a specific calendar, returning parsed todos and any parsing errors. ```rust pub fn get_todos( agent: Agent, credentials: &Credentials, calendar: &Calendar, ) -> Result<(Vec, Vec), Error> { let todo_refs = caldav::get_todos(agent, credentials, &calendar.base_url, &calendar.inner)?; let mut todos = Vec::new(); let mut errors = Vec::new(); for todo_ref in todo_refs { let lines = ical::LineIterator::new(&todo_ref.data); match ical::Ical::parse(&lines) { Ok(ical) => todos.push(Event { url: todo_ref.url.clone(), etag: todo_ref.etag.clone(), ical, }), Err(e) => errors.push(Error::Ical(format!( "Could not parse todo {}: {:?}", todo_ref.data, e ))), } } Ok((todos, errors)) } ``` -------------------------------- ### Get all events in the given `Calendar`. Source: https://docs.rs/minicaldav/latest/src/minicaldav/api.rs.html Function to retrieve all events from a specific calendar, returning parsed events and any parsing errors. ```rust pub fn get_events( agent: Agent, credentials: &Credentials, calendar: &Calendar, ) -> Result<(Vec, Vec), Error> { let event_refs = caldav::get_events(agent, credentials, &calendar.base_url, calendar.url())?; let mut events = Vec::new(); let mut errors = Vec::new(); for event_ref in event_refs { let lines = ical::LineIterator::new(&event_ref.data); match ical::Ical::parse(&lines) { Ok(ical) => events.push(Event { url: event_ref.url.clone(), etag: event_ref.etag.clone(), ical, }), Err(e) => errors.push(Error::Ical(format!( "Could not parse event {}: {:?}", event_ref.data, e ))), } } Ok((events, errors)) } ``` -------------------------------- ### Get Events Function Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html Rust function to fetch calendar events from a CalDAV server using a REPORT request. ```rust pub fn get_events( client: Agent, credentials: &Credentials, base_url: &Url, calendar_url: &Url, ) -> Result, Error> { let auth = get_auth_header(credentials); let content = client .request("REPORT", calendar_url.as_str()) .set("Authorization", &auth) .set("Depth", "1") .set("Content-Type", "application/xml") .send_bytes(CALENDAR_EVENTS_REQUEST.as_bytes())? .into_string() .map_err(|e| Error { kind: ErrorKind::Parsing, message: e.to_string(), })?; trace!("Read CalDAV events: {:?}", content); let reader = content.as_bytes(); let root = xmltree::Element::parse(reader)?; let mut events = Vec::new(); for c in &root.children { if let Some(child) = c.as_element() { let href = child.get_child("href").and_then(|e| e.get_text()); let etag = child .get_child("propstat") .and_then(|e| e.get_child("prop")) .and_then(|e| e.get_child("getetag")) .and_then(|e| e.get_text()) .map(|e| e.to_string()); let data = child .get_child("propstat") .and_then(|e| e.get_child("prop")) .and_then(|e| e.get_child("calendar-data")) .and_then(|e| e.get_text()); if href.is_none() || etag.is_none() || data.is_none() { continue; } if let Some((href, data)) = href.and_then(|href| data.map(|data| (href, data))) { if let Ok(url) = base_url.join(&href) { events.push(EventRef { url, data: data.to_string(), etag, }) } else { error!("Could not parse url {}/{}", base_url, href) } } } } Ok(events) } ``` -------------------------------- ### Get all calendars from the given CalDAV endpoint. Source: https://docs.rs/minicaldav/latest/src/minicaldav/api.rs.html Function to retrieve all calendars from a CalDAV endpoint. ```rust pub fn get_calendars( agent: Agent, credentials: &Credentials, base_url: &Url, ) -> Result, Error> { let calendar_refs = caldav::get_calendars(agent, credentials, base_url)?; let mut calendars = Vec::new(); for calendar_ref in calendar_refs { calendars.push(Calendar { base_url: base_url.clone(), inner: calendar_ref, }); } Ok(calendars) } ``` -------------------------------- ### get_calendars function Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html Function to retrieve a list of calendars for the given credentials. It performs a PROPFIND request to get calendar details and filters them based on resource type and supported components. ```rust /// Get calendars for the given credentials. pub fn get_calendars( client: Agent, credentials: &Credentials, base_url: &Url, ) -> Result, Error> { let mut calendars = Vec::new(); let result = match get_home_set_url(client.clone(), credentials, base_url) { Ok(homeset_url) => propfind_get( client.clone(), credentials, &homeset_url, CALENDARS_REQUEST, &[], "1", ), Err(_e) => propfind_get( client.clone(), credentials, base_url, CALENDARS_REQUEST, &[], "1", ), }; let root = if result.is_err() { propfind_get(client, credentials, base_url, CALENDARS_QUERY, &[], "1")?.1 } else { result?.1 }; for response in &root.children { if let Some(response) = response.as_element() { let name = response .get_child("propstat") .and_then(|e| e.get_child("prop")), .and_then(|e| e.get_child("displayname")), .and_then(|e| e.get_text()); let color = response .get_child("propstat") .and_then(|e| e.get_child("prop")), .and_then(|e| e.get_child("calendar-color")), .and_then(|e| e.get_text()); let is_calendar = response .get_child("propstat") .and_then(|e| e.get_child("prop")), .and_then(|e| e.get_child("resourcetype")), .map(|e| e.get_child("calendar").is_some()) .unwrap_or(false); let supports_vevents = response .get_child("propstat") .and_then(|e| e.get_child("prop")), .and_then(|e| e.get_child("supported-calendar-component-set")), .map(|e| { for c in &e.children { if let Some(child) = c.as_element() { if child.name == "comp" { if let Some(name) = child.attributes.get("name") { if (name == "VEVENT") || (name == "VTODO") { return true; } } } } } false }) .unwrap_or(false); let href = response.get_child("href").and_then(|e| e.get_text()); if !is_calendar || !supports_vevents { continue; } if let Some((href, name)) = href.and_then(|href| name.map(|name| (href, name))) { if let Ok(url) = base_url.join(&href) { calendars.push(CalendarRef { url, name: name.to_string(), color: color.map(|c| c.into()), }) } else { error!("Could not parse url: {}/{}", base_url, href); } } else { continue; } } } Ok(calendars) } ``` -------------------------------- ### Calendars Request Body Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html XML body for a PROPFIND request to get calendar details including display name, resource type, and calendar color. ```xml ``` -------------------------------- ### User Principal Request Body Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html XML body for a PROPFIND request to get the current user's principal. ```xml ``` -------------------------------- ### Any Implementation - type_id Source: https://docs.rs/minicaldav/latest/minicaldav/struct.Calendar.html Gets the TypeId of the Calendar. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### Keyboard Shortcuts Source: https://docs.rs/minicaldav/latest/help.html A list of keyboard shortcuts available in Rustdoc for navigation and interaction. ```text `?` Show this help dialog `S` / `/` Focus the search field `↑` Move up in search results `↓` Move down in search results `←` / `→` Switch result tab (when results focused) `⏎` Go to active search result `+` Expand all sections `-` Collapse all sections `_` Collapse all sections, including impl blocks ``` -------------------------------- ### Search Tricks Source: https://docs.rs/minicaldav/latest/help.html Tips for using the Rustdoc search functionality, including type prefixes and exact name matching. ```text Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given item kind. Accepted kinds are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`. Search functions by type signature (e.g., `vec -> usize` or `-> vec` or `String, enum:Cow -> bool`) You can look for items with an exact name by putting double quotes around your request: `"string"` Look for functions that accept or return slices and arrays by writing square brackets (e.g., `-> [u8]` or `[] -> Option`) Look for items inside another one by searching for a path: `vec::Vec` ``` -------------------------------- ### minicaldav: Small and easy CalDAV client. Source: https://docs.rs/minicaldav/latest/src/minicaldav/api.rs.html License and copyright information for the minicaldav project. ```rust 1// minicaldav: Small and easy CalDAV client. 2// Copyright (C) 2022 Florian Loers 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13// 14// You should have received a copy of the GNU General Public License 15// along with this program. If not, see . 16 ``` -------------------------------- ### CalDAV PROPFIND Request Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html Sends a PROPFIND request to a CalDAV endpoint, searches the XML response for a specific value, and returns the extracted text and the root XML element. ```rust pub fn propfind_get( client: Agent, credentials: &Credentials, url: &Url, body: &str, prop_path: &[&str], depth: &str, ) -> Result<(String, xmltree::Element), Error> { let auth = get_auth_header(credentials); let content = client .request("PROPFIND", url.as_str()) .set("Authorization", &auth) .set("Content-Type", "application/xml") .set("Depth", depth) .send_bytes(body.as_bytes())? .into_string() .map_err(|e| Error { kind: ErrorKind::Parsing, message: e.to_string(), })?; trace!("CalDAV propfind response: {:?}", content); let reader = content.as_bytes(); let root = xmltree::Element::parse(reader)?; let mut element = &root; let mut searched = 0; for prop in prop_path { for e in &element.children { if let Some(child) = e.as_element() { if child.name == *prop { searched += 1; element = child; break; } } } } if searched != prop_path.len() { Err(Error { kind: ErrorKind::Parsing, message: format!("Could not find data {:?} in PROPFIND response.", prop_path), }) } else { Ok(( element .get_text() .map(|s| s.to_string()) .unwrap_or_else(|| "".to_string()), root, )) } } ``` -------------------------------- ### HOMESET_REQUEST Source: https://docs.rs/minicaldav/latest/minicaldav/caldav/static.HOMESET_REQUEST.html Static HOMESET_REQUEST Copy item path ```rust pub static HOMESET_REQUEST: &str ``` -------------------------------- ### USER_PRINCIPAL_REQUEST Static Source: https://docs.rs/minicaldav/latest/minicaldav/caldav/static.USER_PRINCIPAL_REQUEST.html Static definition of USER_PRINCIPAL_REQUEST in minicaldav::caldav. ```rust pub static USER_PRINCIPAL_REQUEST: &str ``` -------------------------------- ### CloneToUninit Implementation - clone_to_uninit Source: https://docs.rs/minicaldav/latest/minicaldav/struct.Calendar.html Performs copy-assignment from Calendar to uninitialized memory. This is a nightly-only experimental API. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Calendar Todos Request XML Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html XML query to retrieve calendar todos, including their ETag and calendar data. ```xml ``` -------------------------------- ### CALENDARS_QUERY Source: https://docs.rs/minicaldav/latest/src/minicaldav/caldav.rs.html XML query used to retrieve calendar information, including display name, color, resource type, and supported components. ```rust pub static CALENDARS_QUERY: &str = r#" "#; ``` -------------------------------- ### MiniCalDAV Builder Methods Source: https://docs.rs/minicaldav/latest/src/minicaldav/api.rs.html This snippet shows various builder methods for adding properties to an iCalendar event, such as STATUS, LOCATION, DTSTART, DTEND, DESCRIPTION, and RRULE. ```rust pub fn status(mut self, value: String) -> Self { self.properties.push(ical::Property { name: "STATUS".to_string(), value, attributes: HashMap::new(), }); self } pub fn generic(mut self, name: String, value: String) -> Self { self.properties.push(ical::Property { name, value, attributes: HashMap::new(), }); self } pub fn location(mut self, value: Option) -> Self { if let Some(value) = value { self.properties.push(ical::Property { name: "LOCATION".to_string(), value, attributes: HashMap::new(), }); } self } pub fn start(mut self, value: String, attributes: Vec<(&str, &str)>) -> Self { let mut attribs = HashMap::new(); for (k, v) in attributes { attribs.insert(k.into(), v.into()); } self.properties.push(ical::Property { name: "DTSTART".to_string(), value, attributes: attribs, }); self } pub fn end(mut self, value: String, attributes: Vec<(&str, &str)>) -> Self { let mut attribs = HashMap::new(); for (k, v) in attributes { attribs.insert(k.into(), v.into()); } self.properties.push(ical::Property { name: "DTEND".to_string(), value, attributes: attribs, }); self } pub fn description(mut self, value: Option) -> Self { if let Some(value) = value { self.properties.push(ical::Property { name: "DESCRIPTION".to_string(), value, attributes: HashMap::new(), }); } self } pub fn rrule(mut self, value: Option) -> Self { if let Some(value) = value { self.properties.push(ical::Property { name: "RRULE".to_string(), value, attributes: HashMap::new(), }); } self } } ``` -------------------------------- ### Ical::new function Source: https://docs.rs/minicaldav/latest/src/minicaldav/ical.rs.html Creates a new ICAL container with a given name. ```rust impl Ical { /// Create a new ical container. The name represents the value of the enclosing `BEGIN:` - `END:` pair. pub fn new(name: String) -> Self { Self { name, ..Default::default() } } // ... other methods ``` -------------------------------- ### propfind_get function signature Source: https://docs.rs/minicaldav/latest/minicaldav/caldav/fn.propfind_get.html Signature for the propfind_get function. ```rust pub fn propfind_get( client: Agent, credentials: &Credentials, url: &Url, body: &str, prop_path: &[&str], depth: &str, ) -> Result<(String, Element), Error> ``` -------------------------------- ### Event Builder Source: https://docs.rs/minicaldav/latest/src/minicaldav/api.rs.html Builder pattern for creating Event objects. ```rust pub fn builder(url: Url) -> EventBuilder { EventBuilder { url, etag: None, properties: vec![], } } pub fn set_etag(&mut self, etag: Option) { self.etag = etag } ``` -------------------------------- ### EventBuilder Methods Source: https://docs.rs/minicaldav/latest/src/minicaldav/api.rs.html Methods for adding properties like UID, DTSTAMP, SUMMARY, PRIORITY, and DUE to an EventBuilder. ```rust pub fn uid(mut self, value: String) -> Self { self.properties.push(ical::Property { name: "UID".to_string(), value, attributes: HashMap::new(), }); self } pub fn timestamp(mut self, value: String) -> Self { self.properties.push(ical::Property { name: "DTSTAMP".to_string(), value, attributes: HashMap::new(), }); self } pub fn summary(mut self, value: String) -> Self { self.properties.push(ical::Property { name: "SUMMARY".to_string(), value, attributes: HashMap::new(), }); self } pub fn priority(mut self, value: String) -> Self { self.properties.push(ical::Property { name: "PRIORITY".to_string(), value, attributes: HashMap::new(), }); self } pub fn duedate(mut self, value: String) -> Self { self.properties.push(ical::Property { name: "DUE".to_string(), value, attributes: HashMap::new(), }); self } ``` -------------------------------- ### Property struct and its methods Source: https://docs.rs/minicaldav/latest/src/minicaldav/ical.rs.html Represents an iCalendar property with a name, value, and attributes. Includes methods for creation, parsing, checking, and serialization. ```Rust #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] /// An ICAL property. Currently only simple key-value properties are supported. #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct Property { pub name: String, pub value: String, pub attributes: HashMap, } impl Property { /// Creates a new property. pub fn new(name: &str, value: &str) -> Self { Self { name: name.into(), value: value.into(), attributes: HashMap::new(), } } /// Creates a new property with attributes pub fn new_with_attributes(name: &str, value: &str, attribs: Vec<(&str, &str)>) -> Self { let mut attributes = HashMap::new(); for (k, v) in attribs { attributes.insert(k.into(), v.into()); } Self { name: name.into(), value: value.into(), attributes, } } /// Parses the given input to a Property instance. pub fn parse(input: &str) -> Result { // Find position of the first colon (separation between name and value) that is not // enclosed in `"`. let mut name = String::new(); let mut value = String::new(); let mut read_value = false; let mut ignore_colon = false; for c in input.chars() { if c == '"' { ignore_colon = !ignore_colon; } else if c == ':' && !ignore_colon && !read_value { read_value = true; continue; } if read_value { value.push(c); } else { name.push(c); } } let mut parts = name.split(';'); if let Some(next) = parts.next() { let mut property = Property::new(next.trim(), &value); for part in parts { if let Some((k, v)) = part.split_once('=') { property.attributes.insert(k.into(), v.into()); } } Ok(property) } else { Err(Error::new(format!( "The property [{:?}, {:?}] did not contain any text after split(';')", name, value ))) } } /// Checks whether this property has the given name and if so, returns its value. pub fn is(&self, name: &str) -> Option<&String> { if self.name == name { Some(&self.value) } else { None } } /// Serialized the property as ICAL formatted string. pub fn serialize(&self) -> String { if !self.attributes.is_empty() { format!( "{name};{attributes}:{{value}}", name = self.name, attributes = self.attributes .iter() .map(|(k, v)| format!( ``` ```Rust k, v))) .collect::>() .join(";"), value = self.value ) } else { format!("{name}:{value}", name = self.name, value = self.value) } } } impl From<(String, String)> for Property { fn from((name, value): (String, String)) -> Self { Self { name, value, attributes: HashMap::new(), } } } ``` -------------------------------- ### TryFrom Implementation - try_from Source: https://docs.rs/minicaldav/latest/minicaldav/struct.Calendar.html Performs the conversion from another type U into Calendar. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### iCalendar with Properties Source: https://docs.rs/minicaldav/latest/src/minicaldav/ical.rs.html Parses a basic iCalendar string containing only calendar properties. ```rust fn test_ical_calendar_with_properties() { let ical = r#"BEGIN:VCALENDAR VERSION:2.0 PRODID:-//ZContent.net//Zap Calendar 1.0//EN CALSCALE:GREGORIAN METHOD:PUBLISH END:VCALENDAR"#; assert_eq!( Ical::parse(&LineIterator::new(ical)), Ok(Ical { name: "VCALENDAR".to_string(), properties: vec![ Property::new("VERSION", "2.0"), Property::new("PRODID", "-//ZContent.net//Zap Calendar 1.0//EN"), Property::new("CALSCALE", "GREGORIAN"), Property::new("METHOD", "PUBLISH"), ], children: vec![] }) ); } ``` -------------------------------- ### iCalendar with Max Line Length and Linebreaks Test Source: https://docs.rs/minicaldav/latest/src/minicaldav/ical.rs.html A test case demonstrating parsing of a complex iCalendar string with long lines and line continuations, including VTIMEZONE and VEVENT with various properties and attendees. ```rust let ical = r#"BEGIN:VCALENDAR VERSION:2.0 PRODID:asdf BEGIN:VTIMEZONE TZID:Europe/Berlin LAST-MODIFIED:20220317T223602Z TZURL:http://tzurl.org/zoneinfo-outlook/Europe/Berlin X-LIC-LOCATION:Europe/Berlin BEGIN:DAYLIGHT TZNAME:CEST TZOFFSETFROM:+0100 TZOFFSETTO:+0200 DTSTART:19700329T020000 RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU END:DAYLIGHT BEGIN:STANDARD TZNAME:CET TZOFFSETFROM:+0200 TZOFFSETTO:+0100 DTSTART:19701025T030000 RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU END:STANDARD END:VTIMEZONE BEGIN:VEVENT DTSTAMP:20220611T081002Z ATTACH;FILENAME=arrow_up.svg;FMTTYPE=image/svg+xml;SIZE=2516;MANAGED-ID=1:h ttps://caldab.caldav.org/attachments/123456789012345/test.svg ATTENDEE;CN=Fooo;PARTSTAT=NEEDS-ACTION;CUTYPE=INDIVIDUAL;EMAIL=foooooo.baaa aaar@fobar.com;X-CALENDARSERVER-DTSTAMP=20220611T081002Z:mailto:foooooo.ba aaaaar@fobar.com ATTENDEE;CN=Foooooo Baaar;PARTSTAT=ACCEPTED;CUTYPE=INDIVIDUAL;EMAIL=foooo@b aaaaar.org;X-CALENDARSERVER-DTSTAMP=20220611T080833Z:mailto:foooo@baaaaar. org CLASS:CONFIDENTIAL CREATED:20220611T080833Z DESCRIPTION:Lorem ipsum dolor sit amet\, consectetur adipiscing elit\, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam\, quis nostrud exercitation ullamco laboris nisi ut aliquip e x ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptat e velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaec at cupidatat non proident\, sunt in culpa qui officia deserunt mollit anim id est laborum. DTSTART;TZID="(UTC-08:00) Pacific Time (US & Canada)";VALUE=DATE-TIME:2019 1209T140000 DTEND;TZID="(UTC-08:00) Pacific Time (US & Canada)";VALUE=DATE-TIME:201912 09T150000 LAST-MODIFIED:20220611T081002Z ORGANIZER;CN=Foooooo Baaar;EMAIL=foooo@baaaaar.org:mailto:foooo@baaaaar.org RRULE:FREQ=DAILY;COUNT=1 SEQUENCE:1 SUMMARY:Kaputtest TRANSP:TRANSPARENT UID:11111111-1111-1111-1111-111111111111 BEGIN:VALARM TRIGGER;RELATED=START:-PT15M UID:11111111-1111-1111-1111-111111111112 ACTION:DISPLAY DESCRIPTION:reminder END:VALARM END:VEVENT END:VCALENDAR"#; let parsed = Ical::parse(&LineIterator::new(ical)); assert!(parsed.is_ok()); let cal = parsed.unwrap(); assert_eq!( cal.children[1].properties[0].serialize(), "DTSTAMP:20220611T081002Z" ); let p1 = cal.children[1].properties[1].serialize(); assert!( p1.starts_with("ATTACH") && p1.ends_with("https://caldab.caldav.org/attachments/123456789012345/test.svg") ); let p2 = cal.children[1].properties[2].serialize(); assert!(p2.starts_with("ATTENDEE") && p2.ends_with(":mailto:foooooo.baaaaaar@fobar.com")); let p6 = cal.children[1].properties[6].serialize(); assert_eq!( ``` -------------------------------- ### Ical::serialize function Source: https://docs.rs/minicaldav/latest/src/minicaldav/ical.rs.html Generates an ICAL formatted string representation of the container. ```rust /// Get ICAL formatted string of this container. pub fn serialize(&self) -> String { let mut string = String::new(); let _ = writeln!(string, "BEGIN:{}", self.name); for prop in &self.properties { ``` -------------------------------- ### TryInto Implementation - try_into Source: https://docs.rs/minicaldav/latest/minicaldav/struct.Calendar.html Performs the conversion from Calendar into another type U. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Calendar URL Method Source: https://docs.rs/minicaldav/latest/minicaldav/struct.Calendar.html Returns the URL of the CalDAV calendar. ```rust pub fn url(&self) -> &Url ``` -------------------------------- ### iCalendar with Long Description and Line Break Source: https://docs.rs/minicaldav/latest/src/minicaldav/ical.rs.html Parses an iCalendar event with a multi-line description, demonstrating how line breaks within the DESCRIPTION property are handled. ```rust fn test_ical_calendar_with_event_with_long_description_and_linebreak() { let ical = r#"BEGIN:VCALENDAR VERSION:2.0 PRODID:-//ZContent.net//Zap Calendar 1.0//EN CALSCALE:GREGORIAN METHOD:PUBLISH BEGIN:VEVENT SUMMARY:Abraham Lincoln UID:c7614cff-3549-4a00-9152-d25cc1fe077d SEQUENCE:0 STATUS:CONFIRMED TRANSP:TRANSPARENT RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12 DTSTART:20080212 DTEND:20080213 DTSTAMP:20150421T141403 CATEGORIES:U.S. Presidents,Civil War People LOCATION:Hodgenville\, Kentucky GEO:37.5739497;-85.7399606 DESCRIPTION:Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua URL:http://americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincoln END:VEVENT END:VCALENDAR "#; let parsed = Ical::parse(&LineIterator::new(ical)); // println!({"`{:#?}`"}, parsed); assert_eq!( parsed, Ok(Ical { name: "VCALENDAR".into(), properties: vec![ Property::new("VERSION", "2.0"), Property::new("PRODID", "-//ZContent.net//Zap Calendar 1.0//EN"), ```