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

GetMailTips implementation for EWS #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Core/EwsHttpWebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public async Task<IEwsHttpWebResponse> GetResponse(CancellationToken token)
{
var message = new HttpRequestMessage(new HttpMethod(Method), RequestUri);
message.Content = new StringContent(Content);
//if (!string.IsNullOrEmpty(ContentType))
// message.Content.Headers.ContentType = new MediaTypeHeaderValue(ContentType);
if (!string.IsNullOrEmpty(ContentType))
message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(ContentType);

if (!string.IsNullOrEmpty(UserAgent))
{
Expand Down
19 changes: 19 additions & 0 deletions Core/ExchangeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2900,6 +2900,25 @@ public Task<GetUserAvailabilityResults> GetUserAvailability(
}
#endregion

#region MailTips operations
/// <summary>
/// Gets MailTips for given users. Calling this method results in a call to EWS.
/// </summary>
/// <param name="sendingAs">E-mail address that a user is trying to send as.</param>
/// <param name="recipients">Collection of recipients that would receive a copy of the message.</param>
/// <param name="requested">Mail tips requested from the service.</param>
/// <returns>List of GetMailTips results.</returns>
public Task<GetMailTipsResults> GetMailTips(string sendingAs, Mailbox[] recipients, MailTipsRequested requested, CancellationToken token = default(CancellationToken))
{
GetMailTipsRequest request = new GetMailTipsRequest(this);
request.SendingAs = sendingAs;
request.Recipients = recipients;
request.MailTipsRequested = requested;

return request.Execute(token);
}
#endregion

#region Conversation
/// <summary>
/// Retrieves a collection of all Conversations in the specified Folder.
Expand Down
146 changes: 146 additions & 0 deletions Core/Requests/GetMailTipsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.Exchange.WebServices.Data
{
/// <summary>
/// Represents a GetMailTips request.
/// </summary>
internal sealed class GetMailTipsRequest : SimpleServiceRequestBase
{
//https://msdn.microsoft.com/en-us/library/office/dd877060(v=exchg.140).aspx [GetMailTips Operation][2010]
//https://msdn.microsoft.com/en-us/library/office/dd877060(v=exchg.150).aspx [GetMailTips Operation][2013]
private MailTipsRequested requestedMailTips;

/// <summary>
/// Initializes a new instance of the <see cref="GetMailTipsRequest"/> class.
/// </summary>
/// <param name="service">The service.</param>
internal GetMailTipsRequest(ExchangeService service)
: base(service)
{
}

/// <summary>
/// Gets the name of the XML element.
/// </summary>
/// <returns>XML element name</returns>
internal override string GetXmlElementName() { return XmlElementNames.GetMailTips; }

/// <summary>Writes XML elements.</summary>
/// <param name="writer">The writer.</param>
internal override void WriteElementsToXml(EwsServiceXmlWriter writer)
{
SendingAs.WriteToXml(writer, XmlNamespace.Messages, XmlElementNames.SendingAs);

writer.WriteStartElement(XmlNamespace.Messages, XmlElementNames.Recipients);
foreach (var mbox in Recipients)
{
mbox.WriteToXml(writer, XmlNamespace.Types, XmlElementNames.Mailbox);
}
writer.WriteEndElement(); // </Recipients>

writer.WriteElementValue(XmlNamespace.Messages, XmlElementNames.MailTipsRequested, requestedMailTips);
}

/// <summary>Gets the name of the response XML element.</summary>
/// <returns>XML element name</returns>
internal override string GetResponseXmlElementName() { return XmlElementNames.GetMailTipsResponse; }

/// <summary>Parses the response.</summary>
/// <param name="reader">The reader.</param>
/// <returns>Response object.</returns>
internal override object ParseResponse(EwsServiceXmlReader reader)
{
GetMailTipsResults serviceResponse = new GetMailTipsResults();
serviceResponse.LoadFromXml(reader, XmlElementNames.GetMailTipsResponse);
//if (serviceResponse.ErrorCode != ServiceError.NoError)
return serviceResponse;
}

/// <summary>Gets the request version.</summary>
/// <returns>Earliest Exchange version in which this request is supported.</returns>
internal override ExchangeVersion GetMinimumRequiredServerVersion()
{
return ExchangeVersion.Exchange2010;
}

/// <summary>Executes this request.</summary>
/// <returns>Service response.</returns>
internal async Task<GetMailTipsResults> Execute(CancellationToken token)
{
return (GetMailTipsResults)(await this.InternalExecuteAsync(token).ConfigureAwait(false));
}

/// <summary>Gets or sets the attendees.</summary>
public EmailAddress SendingAs { get; set; }

/// <summary>Gets or sets the requested MailTips.</summary>
public MailTipsRequested MailTipsRequested
{
get { return this.requestedMailTips; }
set { this.requestedMailTips = value; }
}

/// <summary>
/// Gets or sets who are the recipients/targets whose MailTips we are interested in.
/// </summary>
public Mailbox[] Recipients { get; set; }
}

/// <summary>
/// Defines the types of requested mail tips.
/// </summary>
public enum MailTipsRequested
{
/// <summary>
/// Represents all available mail tips.
/// </summary>
All,

/// <summary>
/// Represents the Out of Office (OOF) message.
/// </summary>
OutOfOfficeMessage,

/// <summary>
/// Represents the status for a mailbox that is full.
/// </summary>
MailboxFullStatus,

/// <summary>
/// Represents a custom mail tip.
/// </summary>
CustomMailTip,

/// <summary>
/// Represents the count of external members.
/// </summary>
ExternalMemberCount,

/// <summary>
/// Represents the count of all members.
/// </summary>
TotalMemberCount,

/// <summary>
/// Represents the maximum message size a recipient can accept.
/// </summary>
MaxMessageSize,

/// <summary>
/// Indicates whether delivery restrictions will prevent the sender's message from reaching the recipient.
/// </summary>
DeliveryRestriction,

/// <summary>
/// Indicates whether the sender's message will be reviewed by a moderator.
/// </summary>
ModerationStatus,

/// <summary>
/// Indicates whether the recipient is invalid.
/// </summary>
InvalidRecipient
}
}
51 changes: 51 additions & 0 deletions Core/Responses/GetMailTipsResults.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

namespace Microsoft.Exchange.WebServices.Data
{
/// <summary>
/// Represents the results of a GetMailTips operation.
/// </summary>
public sealed class GetMailTipsResults : ServiceResponse
{
private ServiceResponseCollection<MailTipsResponseMessage> responseCollection;

/// <summary>
/// Initializes a new instance of the <see cref="GetMailTipsResults"/> class.
/// </summary>
internal GetMailTipsResults():base() { }

/// <summary>
/// Reads response elements from XML.
/// </summary>
/// <param name="reader">The reader.</param>
internal override void ReadElementsFromXml(EwsServiceXmlReader reader)
{
responseCollection = new ServiceResponseCollection<MailTipsResponseMessage>();
base.ReadElementsFromXml(reader);
reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

if (!reader.IsEmptyElement)
{
// Because we don't have count of returned objects
// test the element to determine if it is return object or EndElement
reader.Read();
while (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.MailTipsResponseMessageType))
{
MailTipsResponseMessage mrm = new MailTipsResponseMessage();
mrm.LoadFromXml(reader, XmlElementNames.MailTipsResponseMessageType);
this.responseCollection.Add(mrm);
reader.Read();
}
reader.EnsureCurrentNodeIsEndElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages);
}
}

/// <summary>
/// Gets a collection of MailTips responses for the requested recipients
/// </summary>
public ServiceResponseCollection<MailTipsResponseMessage> MailTipsResponses
{
get { return responseCollection; }
internal set { responseCollection = value; }
}
}
}
Loading