Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support XML serialization for UpdateItem #27

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ pub struct Message {
pub conversation_topic: Option<String>,
pub from: Option<Recipient>,
pub internet_message_id: Option<String>,
#[xml_struct(ns_prefix = "t")]
pub is_read: Option<bool>,
pub is_response_requested: Option<bool>,
pub reply_to: Option<Recipient>,
Expand Down
25 changes: 15 additions & 10 deletions src/types/update_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use crate::types::common::{BaseItemId, Message, MessageDisposition, PathToElement};
use crate::{
types::sealed::EnvelopeBodyContents, Items, Operation, OperationResponse, ResponseClass,
ResponseCode,
ResponseCode, MESSAGES_NS_URI,
};
use serde::Deserialize;
use xml_struct::XmlSerialize;
Expand All @@ -14,14 +14,15 @@ use xml_struct::XmlSerialize;
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitem>
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(default_ns = MESSAGES_NS_URI)]
pub struct UpdateItem {
/// The action the Exchange server will take upon updating this item.
///
/// This field is required for and only applicable to [`Message`] items.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitem#messagedisposition-attribute>
#[xml_struct(attribute)]
pub message_disposition: Option<MessageDisposition>,
pub message_disposition: MessageDisposition,

/// The method the Exchange server will use to resolve conflicts between
/// updates.
Expand All @@ -37,7 +38,7 @@ pub struct UpdateItem {
/// A list of items and their corresponding updates.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemchanges>
pub item_changes: ItemChanges,
pub item_changes: Vec<ItemChange>,
}

impl Operation for UpdateItem {
Expand Down Expand Up @@ -78,6 +79,7 @@ pub struct ResponseMessages {
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>,
Expand Down Expand Up @@ -105,24 +107,24 @@ pub enum ConflictResolution {
AlwaysOverwrite,
}

/// A list of updates to items, with each element representing a single item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemchanges>
#[derive(Clone, Debug, XmlSerialize)]
pub struct ItemChanges {
pub item_changes: Vec<ItemChange>,
pub struct ItemChange {
#[xml_struct(ns_prefix = "t")]
pub item_change: ItemChangeInner,
}

/// One or more updates to a single item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemchange>
#[derive(Clone, Debug, XmlSerialize)]
pub struct ItemChange {
pub struct ItemChangeInner {
/// The ID of the item to be updated.
#[xml_struct(flatten, ns_prefix = "t")]
pub item_id: BaseItemId,

/// The changes to make to the item, including appending, setting, or
/// deleting fields.
#[xml_struct(ns_prefix = "t")]
pub updates: Updates,
}

Expand All @@ -131,21 +133,24 @@ pub struct ItemChange {
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updates-item>
#[derive(Clone, Debug, XmlSerialize)]
pub struct Updates {
#[xml_struct(flatten)]
#[xml_struct(flatten, ns_prefix = "t")]
pub inner: Vec<ItemChangeDescription>,
}

/// An individual change to a single field.
#[derive(Clone, Debug, XmlSerialize)]
#[xml_struct(variant_ns_prefix = "t")]
pub enum ItemChangeDescription {
/// An update setting the value of a single field.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/setitemfield>
SetItemField {
/// The field to be updated.
#[xml_struct(flatten, ns_prefix = "t")]
field_uri: PathToElement,

/// The new value of the specified field.
#[xml_struct(ns_prefix = "t")]
message: Message,
},
}
Loading