Skip to content

Commit

Permalink
Add CreateFolder operation (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
leftmostcat authored and hellsworth committed Dec 2, 2024
1 parent 35b308d commit 890dcd9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 13 additions & 8 deletions src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,45 +814,48 @@ 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 <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/calendarfolder>
#[serde(rename_all = "PascalCase")]
CalendarFolder {
folder_id: FolderId,
folder_id: Option<FolderId>,
parent_folder_id: Option<FolderId>,
folder_class: Option<String>,
display_name: Option<String>,
total_count: Option<u32>,
child_folder_count: Option<u32>,
extended_property: Option<Vec<ExtendedProperty>>,
},

/// A contacts folder in a mailbox.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/contactsfolder>
#[serde(rename_all = "PascalCase")]
ContactsFolder {
folder_id: FolderId,
folder_id: Option<FolderId>,
parent_folder_id: Option<FolderId>,
folder_class: Option<String>,
display_name: Option<String>,
total_count: Option<u32>,
child_folder_count: Option<u32>,
extended_property: Option<Vec<ExtendedProperty>>,
},

/// A folder in a mailbox.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/folder>
#[serde(rename_all = "PascalCase")]
Folder {
folder_id: FolderId,
folder_id: Option<FolderId>,
parent_folder_id: Option<FolderId>,
folder_class: Option<String>,
display_name: Option<String>,
total_count: Option<u32>,
child_folder_count: Option<u32>,
extended_property: Option<Vec<ExtendedProperty>>,
unread_count: Option<u32>,
},

Expand All @@ -861,25 +864,27 @@ pub enum Folder {
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/searchfolder>
#[serde(rename_all = "PascalCase")]
SearchFolder {
folder_id: FolderId,
folder_id: Option<FolderId>,
parent_folder_id: Option<FolderId>,
folder_class: Option<String>,
display_name: Option<String>,
total_count: Option<u32>,
child_folder_count: Option<u32>,
extended_property: Option<Vec<ExtendedProperty>>,
},

/// A task folder in a mailbox.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/tasksfolder>
#[serde(rename_all = "PascalCase")]
TasksFolder {
folder_id: FolderId,
folder_id: Option<FolderId>,
parent_folder_id: Option<FolderId>,
folder_class: Option<String>,
display_name: Option<String>,
total_count: Option<u32>,
child_folder_count: Option<u32>,
extended_property: Option<Vec<ExtendedProperty>>,
},
}

Expand Down Expand Up @@ -996,7 +1001,7 @@ pub struct Message {
#[xml_struct(ns_prefix = "t")]
pub categories: Option<Vec<StringElement>>,

// Extended MAPI properties to set on the message.
// Extended MAPI properties of the message.
#[xml_struct(ns_prefix = "t")]
pub extended_property: Option<Vec<ExtendedProperty>>,

Expand Down Expand Up @@ -1109,7 +1114,7 @@ pub struct Message {
pub conversation_id: Option<ItemId>,
}

/// An extended MAPI property to set on the message.
/// An extended MAPI property of an Exchange item or folder.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/extendedproperty>
#[allow(non_snake_case)]
Expand Down
69 changes: 69 additions & 0 deletions src/types/create_folder.rs
Original file line number Diff line number Diff line change
@@ -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 <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/createfolder>
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(default_ns = MESSAGES_NS_URI)]
pub struct CreateFolder {
pub parent_folder_id: BaseFolderId,
pub folders: Vec<Folder>,
}

impl Operation for CreateFolder {
type Response = CreateFolderResponse;
}

impl EnvelopeBodyContents for CreateFolder {
fn name() -> &'static str {
"CreateFolder"
}
}

/// A response to a [`CreateFolder`] request.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/createfolderresponse>
#[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<CreateFolderResponseMessage>,
}

#[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<ResponseCode>,

pub message_text: Option<String>,

pub folders: Vec<Folder>,
}

0 comments on commit 890dcd9

Please sign in to comment.