-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created UpdateItem and added necessary trait implementations
- Loading branch information
1 parent
c080aad
commit 416442d
Showing
3 changed files
with
273 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
use crate::types::common::{BaseItemId, Updates, ItemChange, ItemChanges, ConflictResolution, MessageDisposition, PathToElement, Importance}; | ||
use crate::{ | ||
types::sealed::EnvelopeBodyContents, Items, Operation, | ||
OperationResponse, ResponseClass, ResponseCode, | ||
}; | ||
use serde::Deserialize; | ||
use xml_struct::XmlSerialize; | ||
|
||
/// Represents the UpdateItem operation for interacting with the EWS server. | ||
#[derive(Debug, Deserialize, XmlSerialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct UpdateItem { | ||
/// Describes how the item will be handled after it is updated. | ||
/// The MessageDisposition attribute is required for message items, including meeting | ||
/// messages such as meeting cancellations, meeting requests, and meeting responses. | ||
/// | ||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemshape> | ||
pub message_disposition: MessageDisposition, | ||
|
||
/// Identifies the type of conflict resolution to try during an update. | ||
/// The default value is AutoResolve. | ||
/// | ||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitem#conflictresolution-attribute> | ||
pub conflict_resolution: ConflictResolution, | ||
|
||
/// Contains an array of ItemChange elements that identify items and | ||
/// the updates to apply to the items. | ||
/// | ||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemchanges> | ||
pub item_changes: ItemChanges, // Represents the list of item changes to be included in the request. | ||
} | ||
|
||
impl UpdateItem { | ||
/// Creates a new UpdateItem instance for marking a message as read/unread. | ||
pub fn new_is_read(item_id: BaseItemId, is_read: bool) -> Self { | ||
let item_change = ItemChange { | ||
item_id, | ||
updates: Updates::new_is_read(is_read), | ||
}; | ||
|
||
UpdateItem { | ||
message_disposition: MessageDisposition::SaveOnly, | ||
conflict_resolution: ConflictResolution::AutoResolve, | ||
item_changes: ItemChanges { item_changes: vec![item_change] }, | ||
} | ||
} | ||
|
||
/// Creates a new UpdateItem instance for changing the importance of a message. | ||
pub fn new_importance(item_id: BaseItemId, importance: Importance) -> Self { | ||
let item_change = ItemChange { | ||
item_id, | ||
updates: Updates::new_importance(importance), | ||
}; | ||
|
||
UpdateItem { | ||
message_disposition: MessageDisposition::SaveOnly, | ||
conflict_resolution: ConflictResolution::AutoResolve, | ||
item_changes: ItemChanges { item_changes: vec![item_change] }, | ||
} | ||
} | ||
|
||
/// Adds another `ItemChange` to the `UpdateItem` request. | ||
pub fn add_item_change(&mut self, item_change: ItemChange) { | ||
self.item_changes.item_changes.push(item_change); | ||
} | ||
} | ||
|
||
impl Updates { | ||
/// Creates a new `Updates` instance for marking a message as read/unread. | ||
pub fn new_is_read(is_read: bool) -> Self { | ||
Updates { | ||
set_item_field: crate::types::common::SetItemField { | ||
field_uri: PathToElement::FieldURI { | ||
field_URI: "message:IsRead".to_string(), | ||
}, | ||
message: crate::types::common::Message { | ||
is_read: Some(is_read), | ||
..Default::default() | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
/// Creates a new `Updates` instance for changing the importance of a message. | ||
pub fn new_importance(importance: Importance) -> Self { | ||
Updates { | ||
set_item_field: crate::types::common::SetItemField { | ||
field_uri: PathToElement::FieldURI { | ||
field_URI: "message:Importance".to_string(), | ||
}, | ||
message: crate::types::common::Message { | ||
importance: Some(importance), | ||
..Default::default() | ||
}, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
impl Operation for UpdateItem { | ||
type Response = UpdateItemResponse; // Define the appropriate response type if needed. | ||
} | ||
|
||
impl EnvelopeBodyContents for UpdateItem { | ||
fn name() -> &'static str { | ||
"UpdateItem" | ||
} | ||
} | ||
|
||
/// A response to an [`UpdateItem`] request. | ||
/// | ||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitem> | ||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct UpdateItemResponse { | ||
pub response_messages: ResponseMessages, | ||
} | ||
|
||
|
||
impl OperationResponse for UpdateItemResponse {} | ||
|
||
impl EnvelopeBodyContents for UpdateItemResponse { | ||
fn name() -> &'static str { | ||
"UpdateItemResponse" | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct ResponseMessages { | ||
pub update_item_response_message: Vec<UpdateItemResponseMessage>, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct UpdateItemResponseMessage { | ||
/// 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 items: Items, | ||
} |