Skip to content

Commit

Permalink
Add DeleteFolder operation (#25)
Browse files Browse the repository at this point in the history
Co-authored-by: Heather Ellsworth <[email protected]>
Co-authored-by: Sean Burke <[email protected]>
  • Loading branch information
3 people authored Dec 6, 2024
1 parent dc5b9e0 commit f3eaab3
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

This rust crate holds types that represent data structures and operations for
the Exchange Web Services API, as well as the necessary infrastructure to
serialize and deserialize them to/from XML.
serialize and deserialize them to/from XML.

1 change: 1 addition & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod soap;

pub mod create_folder;
pub mod create_item;
pub mod delete_folder;
pub mod delete_item;
pub mod get_folder;
pub mod get_item;
Expand Down
11 changes: 11 additions & 0 deletions src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,17 @@ pub struct FolderId {
pub change_key: Option<String>,
}

/// The manner in which items or folders are deleted.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/deletetype>
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(text)]
pub enum DeleteType {
HardDelete,
MoveToDeletedItems,
SoftDelete,
}

/// An identifier for an Exchange item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemids>
Expand Down
75 changes: 75 additions & 0 deletions src/types/delete_folder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* 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, DeleteType, Operation, OperationResponse,
ResponseClass, ResponseCode, MESSAGES_NS_URI,
};

/// A request to delete one or more folders.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/deletefolder>
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(default_ns = MESSAGES_NS_URI)]
pub struct DeleteFolder {
/// The method the EWS server will use to perform the deletion.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/deletefolder#deletetype-attribute>
#[xml_struct(attribute)]
pub delete_type: DeleteType,

/// A list of folders to delete.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/folderids>
pub folder_ids: Vec<BaseFolderId>,
}

impl Operation for DeleteFolder {
type Response = DeleteFolderResponse;
}

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

/// A response to a [`DeleteFolder`] request.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/deletefolderresponse>
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeleteFolderResponse {
pub response_messages: ResponseMessages,
}

impl OperationResponse for DeleteFolderResponse {}

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

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct ResponseMessages {
pub delete_folder_response_message: Vec<DeleteFolderResponseMessage>,
}

#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct DeleteFolderResponseMessage {
/// 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>,
}
14 changes: 2 additions & 12 deletions src/types/delete_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,10 @@ use xml_struct::XmlSerialize;

use crate::types::sealed::EnvelopeBodyContents;
use crate::{
BaseItemId, Operation, OperationResponse, ResponseClass, ResponseCode, MESSAGES_NS_URI,
BaseItemId, DeleteType, Operation, OperationResponse, ResponseClass, ResponseCode,
MESSAGES_NS_URI,
};

/// The manner in which the item or items are deleted.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/deleteitem#deletetype-attribute>
#[derive(Debug, XmlSerialize)]
#[xml_struct(text)]
pub enum DeleteType {
HardDelete,
SoftDelete,
MoveToDeletedItems,
}

/// Whether to send meeting cancellations when deleting a calendar item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/deleteitem#sendmeetingcancellations-attribute>
Expand Down

0 comments on commit f3eaab3

Please sign in to comment.