Skip to content

Commit

Permalink
Support XML serialization for UpdateItem (#27)
Browse files Browse the repository at this point in the history
* Changes to support XML serialization

* Formatting changes to make linter happy

* Adjust ItemChange to be struct instead of enum
  • Loading branch information
tobypilling authored Nov 13, 2024
1 parent 89a9614 commit a801098
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
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,
},
}

0 comments on commit a801098

Please sign in to comment.