Skip to content

Commit

Permalink
Adding the TrackLinks property to the Postmark Message class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Theken committed Apr 19, 2017
1 parent 39c6f95 commit 1ea20dd
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 14 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ environment:
WRITE_ACCOUNT_TOKEN:
secure: 8WHfQJv+ZjUJp8pd5KcG0MjOelyEskSA9c/o0QnbIIQaV5hA3BqprE2cnorsCtnR
WRITE_TEST_SERVER_TOKEN:
secure: 4Pt2zMfFltMLSxpvud43AYFTlZWqXRurVBZgCajtzXk3hZpOV1wPPXvUPIUYcw1D
secure: 7b+JCrYYad3qDnzp8+ugDy2QkRI4DIhnOGgHKTaQr6bW4Po9JM8v0F2Ik6kEGN9l
WRITE_TEST_SENDER_EMAIL_ADDRESS:
secure: Ke83sTbZc/+9/mokIvL8BxtPl6yA9tyjjs5kWTI06ZNodxd5gfXpm6Ns+6l0jMLZ
WRITE_TEST_SENDER_SIGNATURE_PROTOTYPE:
secure: dfbWIBndqE2MTj/qyJVP2I13XJlMKA64mI9/jcx1Fa1bZqPqW/tAfxeMViEMjQU836IYWflAG2h4IjARH+K+2uvhTz5y2rb9DzpLvzohKs8=
secure: XQWpiA4jiibMvLdkbiiCNtH2kngGoFtFsx9LWGy7Qvo91oFGx35yOQrUFOhJrvU+OhCHL01n4eCM7I8HTHkjog==
WRITE_TEST_EMAIL_RECIPIENT_ADDRESS:
secure: Ke83sTbZc/+9/mokIvL8BxtPl6yA9tyjjs5kWTI06ZNodxd5gfXpm6Ns+6l0jMLZ
WRITE_TEST_DOMAIN_NAME:
Expand Down
3 changes: 3 additions & 0 deletions src/Postmark.Net20/Postmark.Net20.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<Compile Include="..\Postmark\Model\InboundMessageStatus.cs">
<Link>Model\InboundMessageStatus.cs</Link>
</Compile>
<Compile Include="..\Postmark\Model\LinkTrackingOptions.cs">
<Link>Model\LinkTrackingOptions.cs</Link>
</Compile>
<Compile Include="..\Postmark\Model\OutboundMessageStatus.cs">
<Link>Model\OutboundMessageStatus.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions src/Postmark.Net35/Postmark.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
<Compile Include="..\Postmark\Model\InboundMessageStatus.cs">
<Link>Model\InboundMessageStatus.cs</Link>
</Compile>
<Compile Include="..\Postmark\Model\LinkTrackingOptions.cs">
<Link>Model\LinkTrackingOptions.cs</Link>
</Compile>
<Compile Include="..\Postmark\Model\OutboundMessageStatus.cs">
<Link>Model\OutboundMessageStatus.cs</Link>
</Compile>
Expand Down
1 change: 1 addition & 0 deletions src/Postmark.PCL.Tests/ClientSendingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private PostmarkMessage ConstructMessage(string inboundAddress, int number = 0)
HtmlBody = String.Format("Testing the Postmark .net client, <b>{0}</b>", TESTING_DATE),
TextBody = "This is plain text.",
TrackOpens = true,
TrackLinks = LinkTrackingOptions.HtmlAndText,
Headers = new HeaderCollection(){
{ "X-Integration-Testing-Postmark-Type-Message" , TESTING_DATE.ToString("o")}
},
Expand Down
6 changes: 4 additions & 2 deletions src/Postmark.PCL.Tests/ClientServerInformationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async void Client_CanGetEditAServerInformation()
!existingServer.RawEmailEnabled, !existingServer.SmtpApiActivated,
_inboundHookUrl + updatedAffix, _bounceHookUrl + updatedAffix,
_openHookUrl + updatedAffix, !existingServer.PostFirstOpenOnly,
!existingServer.TrackOpens, null, 10);
!existingServer.TrackOpens, null, 10, LinkTrackingOptions.HtmlOnly);

//go get a fresh copy from the API.
var retrievedServer = await _client.GetServerAsync();
Expand All @@ -68,7 +68,8 @@ await _client.EditServerAsync(
existingServer.InboundHookUrl, existingServer.BounceHookUrl,
existingServer.OpenHookUrl, existingServer.PostFirstOpenOnly,
existingServer.TrackOpens, null,
existingServer.InboundSpamThreshold);
existingServer.InboundSpamThreshold,
LinkTrackingOptions.None);

Assert.AreEqual(_name + updatedAffix, retrievedServer.Name);
Assert.AreEqual(ServerColors.Purple, retrievedServer.Color);
Expand All @@ -82,6 +83,7 @@ await _client.EditServerAsync(
Assert.AreNotEqual(existingServer.TrackOpens, retrievedServer.TrackOpens);
Assert.AreEqual(10, retrievedServer.InboundSpamThreshold);
Assert.AreNotEqual(existingServer.InboundSpamThreshold, retrievedServer.InboundSpamThreshold);
Assert.AreEqual(LinkTrackingOptions.HtmlOnly, retrievedServer.TrackLinks);
}


Expand Down
4 changes: 0 additions & 4 deletions src/Postmark.PCL/Model/PostmarkMessage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using PostmarkDotNet.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace PostmarkDotNet
{
Expand Down
4 changes: 3 additions & 1 deletion src/Postmark.PCL/Model/PostmarkMessageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;

namespace PostmarkDotNet
{
Expand All @@ -18,6 +17,7 @@ public PostmarkMessageBase()
{
Headers = new HeaderCollection();
Attachments = new List<PostmarkMessageAttachment>(0);
TrackLinks = LinkTrackingOptions.None;
}

/// <summary>
Expand Down Expand Up @@ -62,6 +62,8 @@ public PostmarkMessageBase()
/// </remarks>
public bool? TrackOpens { get; set; }

public LinkTrackingOptions TrackLinks { get; set; }

/// <summary>
/// A collection of optional message headers.
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion src/Postmark.PCL/Model/TemplatedPostmarkMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class TemplatedPostmarkMessage : PostmarkMessageBase
public TemplatedPostmarkMessage()
: base()
{

}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Postmark.PCL/Postmark.PCL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Compile Include="..\Postmark\Model\InboundMessageStatus.cs">
<Link>Model\InboundMessageStatus.cs</Link>
</Compile>
<Compile Include="..\Postmark\Model\LinkTrackingOptions.cs">
<Link>Model\LinkTrackingOptions.cs</Link>
</Compile>
<Compile Include="..\Postmark\Model\OutboundMessageStatus.cs">
<Link>Model\OutboundMessageStatus.cs</Link>
</Compile>
Expand Down
4 changes: 3 additions & 1 deletion src/Postmark.PCL/PostmarkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ public async Task<PostmarkServer> GetServerAsync()
public async Task<PostmarkServer> EditServerAsync(String name = null, string color = null,
bool? rawEmailEnabled = null, bool? smtpApiActivated = null, string inboundHookUrl = null,
string bounceHookUrl = null, string openHookUrl = null, bool? postFirstOpenOnly = null,
bool? trackOpens = null, string inboundDomain = null, int? inboundSpamThreshold = null)
bool? trackOpens = null, string inboundDomain = null, int? inboundSpamThreshold = null,
LinkTrackingOptions? trackLinks = null)
{
var body = new Dictionary<string, object>();
body["Name"] = name;
Expand All @@ -305,6 +306,7 @@ public async Task<PostmarkServer> EditServerAsync(String name = null, string col
body["TrackOpens"] = trackOpens;
body["InboundDomain"] = inboundDomain;
body["InboundSpamThreshold"] = inboundSpamThreshold;
body["TrackLinks"] = trackLinks;

body = body.Where(kv => kv.Value != null).ToDictionary(k => k.Key, v => v.Value);

Expand Down
2 changes: 1 addition & 1 deletion src/Postmark.PCL/PostmarkClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected async Task<TResponse> ProcessRequestAsync<TRequestBody, TResponse>(str
var content = new JsonContent<TRequestBody>(message);
request.Content = content;
}

request.Headers.Add("Accept", "application/json");
request.Headers.Add(AuthHeaderName, _authToken);
request.Headers.Add("User-Agent", _agent);
Expand Down
14 changes: 14 additions & 0 deletions src/Postmark/Model/LinkTrackingOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace PostmarkDotNet
{
[JsonConverter(typeof(StringEnumConverter))]
public enum LinkTrackingOptions
{
None = 0,
HtmlAndText = 1,
HtmlOnly = 2,
TextOnly = 3,
}
}
8 changes: 6 additions & 2 deletions src/Postmark/Model/PostmarkMessage.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using PostmarkDotNet.Validation;

#if !WINDOWS_PHONE
Expand All @@ -11,7 +10,6 @@
using System.Net.Mail;
using System.Net.Mime;
using System.Text;
using System.Diagnostics.CodeAnalysis;
#else
using Hammock.Silverlight.Compat;
#endif
Expand Down Expand Up @@ -166,6 +164,7 @@ public PostmarkMessageBase()
{
Headers = new NameValueCollection(0);
Attachments = new List<PostmarkMessageAttachment>(0);
TrackLinks = LinkTrackingOptions.None;
}

#if !WINDOWS_PHONE
Expand Down Expand Up @@ -290,6 +289,11 @@ protected static Encoding resolveViewEncoding(AttachmentBase view, Encoding fall
/// </summary>
public bool TrackOpens { get; set; }

/// <summary>
/// Setting determining whether to track links, default is "None"
/// </summary>
public LinkTrackingOptions TrackLinks { get; set; }

/// <summary>
/// A collection of optional message headers.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Postmark/Model/PostmarkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ public PostmarkServer()
/// </summary>
public bool TrackOpens { get; set; }

/// <summary>
/// The link tracking setting for this server.
/// </summary>
public LinkTrackingOptions TrackLinks { get; set; }

/// <summary>
/// Inbound domain for MX setup
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/Postmark/Postmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="IPostmarkClient.Async.cs" />
<Compile Include="IPostmarkClient.cs" />
<Compile Include="Model\InboundMessageStatus.cs" />
<Compile Include="Model\LinkTrackingOptions.cs" />
<Compile Include="Model\OutboundMessageStatus.cs" />
<Compile Include="Model\PostmarkCompleteSenderSignature.cs" />
<Compile Include="Model\PostmarkBaseSenderSignature.cs" />
Expand Down

0 comments on commit 1ea20dd

Please sign in to comment.