-
Notifications
You must be signed in to change notification settings - Fork 2
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
Created UpdateItem and added necessary trait implementations #18
Changes from 11 commits
188d3da
f784450
468a45a
4277779
9cfb448
b1c4485
aaf24c1
475bd39
8d77946
ccae29c
423b52b
483be7c
d3e2e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,18 @@ pub enum DistinguishedPropertySet { | |
UnifiedMessaging, | ||
} | ||
|
||
/// The action an Exchange server will take upon creating a `Message` item. | ||
/// | ||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/createitem#messagedisposition-attribute> | ||
/// and <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitem#messagedisposition-attribute> | ||
#[derive(Clone, Copy, Debug, 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> | ||
|
@@ -315,7 +327,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)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: |
||
pub struct ItemId { | ||
#[xml_struct(attribute)] | ||
#[serde(rename = "@Id")] | ||
|
@@ -458,7 +470,7 @@ impl XmlSerialize for DateTime { | |
/// An email message. | ||
/// | ||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/message-ex15websvcsotherref> | ||
#[derive(Clone, Debug, Deserialize)] | ||
#[derive(Clone, Debug, Default, Deserialize, XmlSerialize)] | ||
leftmostcat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[serde(rename_all = "PascalCase")] | ||
pub struct Message { | ||
/// The MIME content of the item. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,142 @@ | ||||||
/* 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, Message, MessageDisposition, PathToElement}; | ||||||
use crate::{ | ||||||
types::sealed::EnvelopeBodyContents, Items, Operation, OperationResponse, ResponseClass, | ||||||
ResponseCode, | ||||||
}; | ||||||
use serde::Deserialize; | ||||||
use xml_struct::XmlSerialize; | ||||||
|
||||||
/// The method used by the Exchange server to resolve conflicts between item | ||||||
/// updates. | ||||||
/// | ||||||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updateitem#conflictresolution-attribute> | ||||||
#[derive(Clone, Copy, Debug, Default, XmlSerialize)] | ||||||
#[xml_struct(text)] | ||||||
pub enum ConflictResolution { | ||||||
NeverOverwrite, | ||||||
|
||||||
#[default] | ||||||
AutoResolve, | ||||||
|
||||||
AlwaysOverwrite, | ||||||
} | ||||||
|
||||||
/// Represents a change to an individual item, including the item ID and updates. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: This and the other struct comments throughout the file should follow the noun phrase convention. |
||||||
/// | ||||||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/itemchange> | ||||||
#[derive(Clone, Debug, XmlSerialize)] | ||||||
pub struct ItemChange { | ||||||
pub item_id: BaseItemId, // Represents the <t:ItemId> element with Id and ChangeKey. | ||||||
|
||||||
pub updates: Updates, // Represents the <t:Updates> element containing the changes. | ||||||
tobypilling marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
/// 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(Clone, Debug, XmlSerialize)] | ||||||
pub struct ItemChanges { | ||||||
pub item_changes: Vec<ItemChange>, | ||||||
} | ||||||
|
||||||
/// Struct representing the field update operation. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: As below, "Struct representing" doesn't add much here, and the second paragraph could easily be folded into this one to give a more complete description, but as below, this needs additional revision. |
||||||
/// | ||||||
/// 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(Clone, Debug, XmlSerialize)] | ||||||
pub struct SetItemField { | ||||||
pub field_uri: PathToElement, // Reference to the field being updated. | ||||||
pub message: Message, // The new value for the specified field. | ||||||
} | ||||||
|
||||||
/// Struct representing updates to be applied to an item. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: "Struct representing" is implicit in the declaration already and doesn't really add anything here.
Suggested change
|
||||||
/// | ||||||
/// This struct is used to create an UpdateItem request. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: This doesn't really add anything not implied by the type hierarchy. |
||||||
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/updates-item> | ||||||
#[derive(Clone, Debug, XmlSerialize)] | ||||||
pub struct Updates { | ||||||
pub set_item_field: SetItemField, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: A couple problems here. First is that this only allows for a single field to be changed per update and it should instead be a |
||||||
} | ||||||
|
||||||
/// Represents the UpdateItem operation for interacting with the EWS server. | ||||||
#[derive(Clone, Debug, XmlSerialize)] | ||||||
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); | ||||||
} | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: There's still not really cause to have this be a separate function. The field to be changed is public, so while this provides a slight shortcut to accessing that field, it also provides limited means of interacting with it. In particular, since we generally create these operation structs all at once, |
||||||
|
||||||
impl Operation for UpdateItem { | ||||||
type Response = UpdateItemResponse; | ||||||
} | ||||||
|
||||||
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(Clone, 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(Clone, Debug, Deserialize)] | ||||||
#[serde(rename_all = "PascalCase")] | ||||||
pub struct ResponseMessages { | ||||||
pub update_item_response_message: Vec<UpdateItemResponseMessage>, | ||||||
} | ||||||
|
||||||
#[derive(Clone, 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. | ||||||
pub response_class: ResponseClass, | ||||||
|
||||||
pub response_code: Option<ResponseCode>, | ||||||
|
||||||
pub message_text: Option<String>, | ||||||
|
||||||
pub items: Items, | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: I have generally kept the actual definition of the operations at the beginning of the file with operation-specific types declared below. I don't have solid reasoning for this, but it's consistent and puts the named part of the file up front. Even nitpickier but reflected in that tendency is that, in Rust, I tend to prefer to declare a type and then declare additional types on which it depends below them, e.g.: struct Foo {
bar: Bar,
}
struct Bar {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.