Skip to content

Commit

Permalink
Created UpdateItem and added necessary trait implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
tobypilling committed Oct 23, 2024
1 parent c080aad commit 188d3da
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pub mod get_folder;
pub mod get_item;
pub mod sync_folder_hierarchy;
pub mod sync_folder_items;
pub mod update_item;
23 changes: 17 additions & 6 deletions src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct ItemShape {
}

/// An identifier for a property on an Exchange entity.
#[derive(Debug, XmlSerialize)]
#[derive(Debug, Deserialize, XmlSerialize)]
#[xml_struct(variant_ns_prefix = "t")]
pub enum PathToElement {
/// An identifier for an extended MAPI property.
Expand Down Expand Up @@ -162,7 +162,7 @@ pub struct ExtendedFieldURI {
/// A well-known MAPI property set identifier.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/extendedfielduri#distinguishedpropertysetid-attribute>
#[derive(Clone, Copy, Debug, XmlSerialize)]
#[derive(Clone, Copy, Debug, Deserialize, XmlSerialize)]
#[xml_struct(text)]
pub enum DistinguishedPropertySet {
Address,
Expand All @@ -177,10 +177,21 @@ pub enum DistinguishedPropertySet {
UnifiedMessaging,
}

/// The action an Exchange server will take upon creating or updating a `Message` item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/createitem#messagedisposition-attribute>
#[derive(Clone, Copy, Debug, Deserialize, XmlSerialize)]
#[xml_struct(text)]
pub enum MessageDisposition {
SaveOnly,
SendOnly,
SendAndSaveCopy,
}

/// The type of the value of a MAPI property.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/extendedfielduri#propertytype-attribute>
#[derive(Clone, Copy, Debug, XmlSerialize)]
#[derive(Clone, Copy, Debug, Deserialize, XmlSerialize)]
#[xml_struct(text)]
pub enum PropertyType {
ApplicationTime,
Expand Down Expand Up @@ -297,7 +308,7 @@ pub struct FolderId {
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemids>
// N.B.: Commented-out variants are not yet implemented.
#[derive(Debug, XmlSerialize)]
#[derive(Debug, Deserialize, XmlSerialize)]
#[xml_struct(variant_ns_prefix = "t")]
pub enum BaseItemId {
/// An identifier for a standard Exchange item.
Expand All @@ -315,7 +326,7 @@ pub enum BaseItemId {
/// The unique identifier of an item.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemid>
#[derive(Clone, Debug, Deserialize, XmlSerialize, PartialEq)]
#[derive(Clone, Default, Debug, Deserialize, XmlSerialize, PartialEq)]
pub struct ItemId {
#[xml_struct(attribute)]
#[serde(rename = "@Id")]
Expand Down Expand Up @@ -458,7 +469,7 @@ impl XmlSerialize for DateTime {
/// An email message.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/message-ex15websvcsotherref>
#[derive(Debug, Deserialize)]
#[derive(Debug, Default, Deserialize, XmlSerialize)]
#[serde(rename_all = "PascalCase")]
pub struct Message {
/// The MIME content of the item.
Expand Down
148 changes: 148 additions & 0 deletions src/types/update_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/* 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 crate::types::common::{BaseItemId, PathToElement, Message, MessageDisposition};
use crate::{
types::sealed::EnvelopeBodyContents, Items, Operation,
OperationResponse, ResponseClass, ResponseCode,
};
use serde::Deserialize;
use xml_struct::XmlSerialize;

/// 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>
#[derive(Clone, Copy, Debug, Deserialize, XmlSerialize)]
#[xml_struct(text)]
pub enum ConflictResolution {
NeverOverwrite,
AutoResolve,
AlwaysOverwrite,
}

/// Represents a change to an individual item, including the item ID and updates.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemchange>
#[derive(Debug, Deserialize, XmlSerialize)]
pub struct ItemChange {
#[serde(rename = "t:ItemId")]
pub item_id: BaseItemId, // Represents the <t:ItemId> element with Id and ChangeKey.

#[serde(rename = "t:Updates")]
pub updates: Updates, // Represents the <t:Updates> element containing the changes.
}

/// Represents a list of item changes without an explicit container tag.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemchanges>
#[derive(Debug, Deserialize, XmlSerialize)]
pub struct ItemChanges {
#[serde(rename = "t:ItemChange")]
pub item_changes: Vec<ItemChange>,
}

/// Struct representing the field update operation.
///
/// This struct contains details of the field that needs to be updated.
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/setitemfield>
#[derive(Debug, Deserialize, XmlSerialize)]
pub struct SetItemField {
#[serde(rename = "t:FieldURI")]
pub field_uri: PathToElement, // Reference to the field being updated.
#[serde(rename = "t:Message")]
pub message: Message, // The new value for the specified field.
}

/// Struct representing updates to be applied to an item.
///
/// This struct is used to create an UpdateItem request.
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updates-item>
#[derive(Debug, Deserialize, XmlSerialize)]
pub struct Updates {
#[serde(rename = "t:SetItemField")]
pub set_item_field: SetItemField,
}

/// 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/updateitem#messagedisposition-attribute>
#[xml_struct(attribute)]
pub message_disposition: Option<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>
#[xml_struct(attribute)]
pub conflict_resolution: Option<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 {

/// 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 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/updateitemresponse>
#[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,
}

0 comments on commit 188d3da

Please sign in to comment.