Skip to content

Commit

Permalink
(GH-391) Change BypassListManagement to a Boolean value
Browse files Browse the repository at this point in the history
Also add BypassSpamManagement, BypassBounceManagement and BypassUnsubscribeManagement.
  • Loading branch information
Jericho committed May 8, 2021
1 parent 91b05cd commit 4de8c00
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 71 deletions.
9 changes: 1 addition & 8 deletions Source/StrongGrid.IntegrationTests/Tests/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,7 @@ public async Task RunAsync(IBaseClient client, TextWriter log, CancellationToken
};
var mailSettings = new MailSettings
{
SandboxMode = new SandboxModeSettings
{
Enabled = true
},
BypassListManagement = new BypassListManagementSettings
{
Enabled = false
},
SandboxModeEnabled = true,
Footer = new FooterSettings
{
Enabled = true,
Expand Down
22 changes: 0 additions & 22 deletions Source/StrongGrid/Models/BypassListManagementSettings.cs

This file was deleted.

6 changes: 3 additions & 3 deletions Source/StrongGrid/Models/EmailAddressSetting.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace StrongGrid.Models
{
Expand All @@ -13,7 +13,7 @@ public class EmailAddressSetting
/// <value>
/// <c>true</c> if enabled; otherwise, <c>false</c>.
/// </value>
[JsonProperty("enabled", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("enabled")]
public bool Enabled { get; set; }

/// <summary>
Expand All @@ -22,7 +22,7 @@ public class EmailAddressSetting
/// <value>
/// The email address.
/// </value>
[JsonProperty("email", NullValueHandling = NullValueHandling.Ignore)]
[JsonProperty("email")]
public string EmailAddress { get; set; }
}
}
54 changes: 36 additions & 18 deletions Source/StrongGrid/Models/MailSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Newtonsoft.Json;

namespace StrongGrid.Models
{
/// <summary>
Expand All @@ -8,30 +6,50 @@ namespace StrongGrid.Models
public class MailSettings
{
/// <summary>
/// Gets or sets the bypass list management.
/// Gets or sets a value indicating whether to bypass all unsubscribe groups and suppressions to ensure that the email is delivered to every single recipient.
/// This should only be used in emergencies when it is absolutely necessary that every recipient receives your email.
/// </summary>
/// <remarks>
/// This filter cannot be combined with any other bypass filters.
/// </remarks>
public bool BypassListManagement { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether to bypass the spam report list to ensure that the email is delivered to recipients.
/// Bounce and unsubscribe lists will still be checked; addresses on these other lists will not receive the message.
/// </summary>
/// <remarks>
/// This filter cannot be combined with the <see cref="BypassListManagement">bypass_list_management filter</see>.
/// </remarks>
public bool BypassSpamManagement { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether to bypass the bounce list to ensure that the email is delivered to recipients.
/// Spam report and unsubscribe lists will still be checked; addresses on these other lists will not receive the message.
/// </summary>
/// <remarks>
/// This filter cannot be combined with the <see cref="BypassListManagement">bypass_list_management filter</see>.
/// </remarks>
public bool BypassBounceManagement { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether to bypass the global unsubscribe list to ensure that the email is delivered to recipients.
/// Bounce and spam report lists will still be checked; addresses on these other lists will not receive the message.
/// This filter applies only to global unsubscribes and will not bypass group unsubscribes.
/// </summary>
/// <value>
/// The bypass list management.
/// </value>
[JsonProperty("bypass_list_management", NullValueHandling = NullValueHandling.Ignore)]
public BypassListManagementSettings BypassListManagement { get; set; }
/// <remarks>
/// This filter cannot be combined with the <see cref="BypassListManagement">bypass_list_management filter</see>.
/// </remarks>
public bool BypassUnsubscribeManagement { get; set; } = false;

/// <summary>
/// Gets or sets the footer.
/// </summary>
/// <value>
/// The footer.
/// </value>
[JsonProperty("footer", NullValueHandling = NullValueHandling.Ignore)]
public FooterSettings Footer { get; set; }

/// <summary>
/// Gets or sets the sandbox mode.
/// Gets or sets a value indicating whether the sandbox mode is enabled or not.
/// </summary>
/// <value>
/// The sandbox mode.
/// </value>
[JsonProperty("sandbox_mode", NullValueHandling = NullValueHandling.Ignore)]
public SandboxModeSettings SandboxMode { get; set; }
public bool SandboxModeEnabled { get; set; } = false;
}
}
19 changes: 0 additions & 19 deletions Source/StrongGrid/Models/SandboxModeSettings.cs

This file was deleted.

2 changes: 2 additions & 0 deletions Source/StrongGrid/Resources/ISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public interface ISettings
/// <returns>
/// The <see cref="SpamCheckingSettings" />.
/// </returns>
[Obsolete("As of august 2020, SendGrid has retired Spam Check mail settings.")]
Task<SpamCheckSettings> GetSpamCheckMailSettingsAsync(string onBehalfOf = null, CancellationToken cancellationToken = default);

/// <summary>
Expand All @@ -323,6 +324,7 @@ public interface ISettings
/// <returns>
/// The <see cref="SpamCheckingSettings" />.
/// </returns>
[Obsolete("As of august 2020, SendGrid has retired Spam Check mail settings.")]
Task<SpamCheckSettings> UpdateSpamCheckMailSettingsAsync(bool enabled, string postToUrl, int threshold, string onBehalfOf = null, CancellationToken cancellationToken = default);

/// <summary>
Expand Down
12 changes: 11 additions & 1 deletion Source/StrongGrid/Resources/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ public async Task<string> SendAsync(
var isDynamicTemplate = Template.IsDynamic(templateId);
var personalizationConverter = new MailPersonalizationConverter(isDynamicTemplate);

// Manually serialize the MailSettings object because the shape of the C# class does not match the shape of the desired JSON.
// The C# class was intentionaly simplified to improve developers experience.
var mailSettingsJsonObject = new JObject();
mailSettingsJsonObject.AddPropertyIfValue("bypass_list_management/enable", mailSettings.BypassListManagement);
mailSettingsJsonObject.AddPropertyIfValue("bypass_spam_management/enable", mailSettings.BypassSpamManagement);
mailSettingsJsonObject.AddPropertyIfValue("bypass_bounce_management/enable", mailSettings.BypassBounceManagement);
mailSettingsJsonObject.AddPropertyIfValue("bypass_unsubscribe_management/enable", mailSettings.BypassUnsubscribeManagement);
mailSettingsJsonObject.AddPropertyIfValue("footer", mailSettings.Footer);
mailSettingsJsonObject.AddPropertyIfValue("sandbox_mode/enable", mailSettings.SandboxModeEnabled);

var data = new JObject();
data.AddPropertyIfValue("from", from);
data.AddPropertyIfValue("reply_to", replyTo);
Expand All @@ -203,7 +213,7 @@ public async Task<string> SendAsync(
data.AddPropertyIfValue("batch_id", batchId);
data.AddPropertyIfValue("asm", unsubscribeOptions);
data.AddPropertyIfValue("ip_pool_name", ipPoolName);
data.AddPropertyIfValue("mail_settings", mailSettings);
data.AddPropertyIfValue("mail_settings", mailSettingsJsonObject);
data.AddPropertyIfValue("tracking_settings", trackingSettings);
data.AddPropertyIfValue("personalizations", personalizationsCopy, personalizationConverter);

Expand Down

0 comments on commit 4de8c00

Please sign in to comment.