From 890dcd9a8d66a0aae7791978ce1e5c92615cf46d Mon Sep 17 00:00:00 2001 From: Sean Burke Date: Mon, 2 Dec 2024 09:24:41 -0800 Subject: [PATCH] Add CreateFolder operation (#26) --- src/types.rs | 1 + src/types/common.rs | 21 +++++++----- src/types/create_folder.rs | 69 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 src/types/create_folder.rs diff --git a/src/types.rs b/src/types.rs index 954adc9..3740a12 100644 --- a/src/types.rs +++ b/src/types.rs @@ -9,6 +9,7 @@ pub use common::*; pub use operations::*; pub mod soap; +pub mod create_folder; pub mod create_item; pub mod delete_item; pub mod delete_folder; diff --git a/src/types/common.rs b/src/types/common.rs index 4a56f94..0dad7b8 100644 --- a/src/types/common.rs +++ b/src/types/common.rs @@ -814,19 +814,20 @@ pub struct ItemId { } /// The representation of a folder in an EWS operation. -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize, XmlSerialize)] pub enum Folder { /// A calendar folder in a mailbox. /// /// See #[serde(rename_all = "PascalCase")] CalendarFolder { - folder_id: FolderId, + folder_id: Option, parent_folder_id: Option, folder_class: Option, display_name: Option, total_count: Option, child_folder_count: Option, + extended_property: Option>, }, /// A contacts folder in a mailbox. @@ -834,12 +835,13 @@ pub enum Folder { /// See #[serde(rename_all = "PascalCase")] ContactsFolder { - folder_id: FolderId, + folder_id: Option, parent_folder_id: Option, folder_class: Option, display_name: Option, total_count: Option, child_folder_count: Option, + extended_property: Option>, }, /// A folder in a mailbox. @@ -847,12 +849,13 @@ pub enum Folder { /// See #[serde(rename_all = "PascalCase")] Folder { - folder_id: FolderId, + folder_id: Option, parent_folder_id: Option, folder_class: Option, display_name: Option, total_count: Option, child_folder_count: Option, + extended_property: Option>, unread_count: Option, }, @@ -861,12 +864,13 @@ pub enum Folder { /// See #[serde(rename_all = "PascalCase")] SearchFolder { - folder_id: FolderId, + folder_id: Option, parent_folder_id: Option, folder_class: Option, display_name: Option, total_count: Option, child_folder_count: Option, + extended_property: Option>, }, /// A task folder in a mailbox. @@ -874,12 +878,13 @@ pub enum Folder { /// See #[serde(rename_all = "PascalCase")] TasksFolder { - folder_id: FolderId, + folder_id: Option, parent_folder_id: Option, folder_class: Option, display_name: Option, total_count: Option, child_folder_count: Option, + extended_property: Option>, }, } @@ -996,7 +1001,7 @@ pub struct Message { #[xml_struct(ns_prefix = "t")] pub categories: Option>, - // Extended MAPI properties to set on the message. + // Extended MAPI properties of the message. #[xml_struct(ns_prefix = "t")] pub extended_property: Option>, @@ -1109,7 +1114,7 @@ pub struct Message { pub conversation_id: Option, } -/// An extended MAPI property to set on the message. +/// An extended MAPI property of an Exchange item or folder. /// /// See #[allow(non_snake_case)] diff --git a/src/types/create_folder.rs b/src/types/create_folder.rs new file mode 100644 index 0000000..5dec79b --- /dev/null +++ b/src/types/create_folder.rs @@ -0,0 +1,69 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use serde::Deserialize; +use xml_struct::XmlSerialize; + +use crate::{ + types::sealed::EnvelopeBodyContents, BaseFolderId, Folder, Operation, OperationResponse, + ResponseClass, ResponseCode, MESSAGES_NS_URI, +}; + +/// A request to create a new folder. +/// +/// See +#[derive(Clone, Debug, XmlSerialize)] +#[xml_struct(default_ns = MESSAGES_NS_URI)] +pub struct CreateFolder { + pub parent_folder_id: BaseFolderId, + pub folders: Vec, +} + +impl Operation for CreateFolder { + type Response = CreateFolderResponse; +} + +impl EnvelopeBodyContents for CreateFolder { + fn name() -> &'static str { + "CreateFolder" + } +} + +/// A response to a [`CreateFolder`] request. +/// +/// See +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct CreateFolderResponse { + pub response_messages: ResponseMessages, +} + +impl OperationResponse for CreateFolderResponse {} + +impl EnvelopeBodyContents for CreateFolderResponse { + fn name() -> &'static str { + "CreateFolderResponse" + } +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct ResponseMessages { + pub create_folder_response_message: Vec, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct CreateFolderResponseMessage { + /// The status of the corresponding request, i.e. whether it succeeded or + /// resulted in an error. + #[serde(rename = "@ResponseClass")] + pub response_class: ResponseClass, + + pub response_code: Option, + + pub message_text: Option, + + pub folders: Vec, +}