Skip to content

Commit

Permalink
Allow specifying extended MAPI properties when creating a message (#15)
Browse files Browse the repository at this point in the history
There's more code duplication than I'm comfortable with in there, but I don't really see a way out of it - see thunderbird/xml-struct-rs#9 which describes the issue in more details.

I have also made `message_disposition` not an `Option`, since as far as I'm aware this is a required field.
  • Loading branch information
babolivier authored Sep 26, 2024
1 parent 1dbda0f commit c080aad
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/types/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,41 @@ pub enum PathToElement {
},
}

/// The identifier for an extended MAPI property.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/extendedfielduri>
// N.B.: This is copied from `PathToElement::ExtendedFieldURI`,
// which follows the same structure. However, xml-struct doesn't currently
// support using a nested structure to define an element's attributes, see
// https://github.com/thunderbird/xml-struct-rs/issues/9
#[derive(Debug, XmlSerialize)]
pub struct ExtendedFieldURI {
/// A well-known identifier for a property set.
#[xml_struct(attribute)]
pub distinguished_property_set_id: Option<DistinguishedPropertySet>,

/// A GUID representing a property set.
// TODO: This could use a strong type for representing a GUID.
#[xml_struct(attribute)]
pub property_set_id: Option<String>,

/// Specifies a property by integer tag.
#[xml_struct(attribute)]
pub property_tag: Option<String>,

/// The name of a property within a specified property set.
#[xml_struct(attribute)]
pub property_name: Option<String>,

/// The dispatch ID of a property within a specified property set.
#[xml_struct(attribute)]
pub property_id: Option<String>,

/// The value type of the desired property.
#[xml_struct(attribute)]
pub property_type: PropertyType,
}

/// A well-known MAPI property set identifier.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/extendedfielduri#distinguishedpropertysetid-attribute>
Expand Down
26 changes: 23 additions & 3 deletions src/types/create_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use serde::Deserialize;
use xml_struct::XmlSerialize;

use crate::{
types::sealed::EnvelopeBodyContents, ArrayOfRecipients, BaseFolderId, Items, MimeContent,
Operation, OperationResponse, ResponseClass, ResponseCode, MESSAGES_NS_URI,
types::sealed::EnvelopeBodyContents, ArrayOfRecipients, BaseFolderId, ExtendedFieldURI, Items,
MimeContent, Operation, OperationResponse, ResponseClass, ResponseCode, MESSAGES_NS_URI,
};

/// The action an Exchange server will take upon creating a `Message` item.
Expand Down Expand Up @@ -35,7 +35,7 @@ pub struct CreateItem {
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/createitem#messagedisposition-attribute>
#[xml_struct(attribute)]
pub message_disposition: Option<MessageDisposition>,
pub message_disposition: MessageDisposition,

/// The folder in which to store an item once it has been created.
///
Expand Down Expand Up @@ -84,16 +84,36 @@ pub struct Message {
/// The MIME content of the item.
#[xml_struct(ns_prefix = "t")]
pub mime_content: Option<MimeContent>,

// Whether to request a delivery receipt.
#[xml_struct(ns_prefix = "t")]
pub is_delivery_receipt_requested: Option<bool>,

// The message ID for the message, semantically identical to the Message-ID
// header.
#[xml_struct(ns_prefix = "t")]
pub internet_message_id: Option<String>,

// Recipients to include as Bcc, who won't be included in the MIME content.
#[xml_struct(ns_prefix = "t")]
pub bcc_recipients: Option<ArrayOfRecipients>,

// Extended MAPI properties to set on the message.
#[xml_struct(ns_prefix = "t")]
pub extended_property: Option<Vec<ExtendedProperty>>,
}

/// An extended MAPI property to set on the message.
///
/// See <https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/extendedproperty>
#[allow(non_snake_case)]
#[derive(Debug, XmlSerialize)]
pub struct ExtendedProperty {
#[xml_struct(ns_prefix = "t")]
pub extended_field_URI: ExtendedFieldURI,

#[xml_struct(ns_prefix = "t")]
pub value: String,
}

impl Operation for CreateItem {
Expand Down

0 comments on commit c080aad

Please sign in to comment.