Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ public SendResponse RunExample()

message.CustomHeaders.Add("x-mycustomheader", "I am a message header");

var metadata = new List<IMetadata>()
{
new Metadata("example-type", "basic-send-complex"),
new Metadata()
{
Key = "message-contains",
Value = "attachments, headers"
}
};
message.Metadata.Add(metadata);
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");
message.Metadata.Add(new Metadata("testMessageHeader", "I am metadata"));

message.Tags.Add("Basic-Complex-Example");
message.Tags.Add("c#-Example");

var attachment = message.Attachments.Add("bus.png", MimeType.PNG, @".\examples\img\bus.png");
attachment.ContentId = "Bus";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using SocketLabs.InjectionApi;
using SocketLabs.InjectionApi.Message;
Expand Down Expand Up @@ -41,7 +42,23 @@ public SendResponse RunExample()
message.From.Set("from@example.com", "FromMe");
message.ReplyTo.Email = "replyto@example.com";

message.CustomHeaders.Add(new CustomHeader("testMessageHeader", "I am a message header"));
var metadata = new List<IMetadata>()
{
new Metadata("example-type", "bulk-send-complex"),
new Metadata()
{
Key = "message-contains",
Value = "attachments, headers"
}
};
message.Metadata.Add(metadata);
message.Metadata.Add("x-mycustommetadata", "I am custom metadata");
message.Metadata.Add(new Metadata("testMessageHeader", "I am metadata"));

message.Metadata.Add("x-mycustommetadata", "I am custom metadata");

message.Tags.Add("Bulk-Complex-Example");
message.Tags.Add("c#-Example");

// Build the Content (Note the %% symbols used to denote the data to be merged)
var html = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Copyright>Copyright © 2018-2022 SocketLabs Acquisition LLC</Copyright>
<Copyright>Copyright © 2018-2023 SocketLabs Acquisition LLC</Copyright>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ PM> Install-Package SocketLabs.EmailDelivery
Adding a Package Reference to your project:

```
<PackageReference Include="SocketLabs.EmailDelivery" Version="1.2.3" />
<PackageReference Include="SocketLabs.EmailDelivery" Version="1.4.0" />
```

.NET CLI users can also use the following command:
Expand Down
10 changes: 9 additions & 1 deletion docs/release-notes/latest.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.3.4
* Bump Castle.Core from 5.0.0 to 5.1.0
* Bump Moq from 4.18.1 to 4.18.2
* Bump Moq from 4.18.1 to 4.18.2

## 1.4.0
* Adding Metadata and Tags
* Bump coverlet.collector from 3.1.2 to 3.2.0
* Bump Newtonsoft.Json from 13.0.1 to 13.0.2
* Bump Microsoft.NET.Test.Sdk from 17.2.0 to 17.4.1
* Bump MSTest.TestFramework from 2.2.10 to 3.0.2
* Bump Moq from 4.18.2 to 4.18.4
27 changes: 26 additions & 1 deletion src/SocketLabs/InjectionApi/Core/InjectionRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ internal virtual MessageJson GenerateBaseMessageJson(IMessageBase message)
CharSet = message.CharSet,
CustomHeaders = PopulateCustomHeaders(message.CustomHeaders),
From = new AddressJson(message.From.Email, message.From.FriendlyName),
Attachments = PopulateList(message.Attachments)
Attachments = PopulateList(message.Attachments),
Metadata = PopulateMetadata(message.Metadata),
Tags = PopulateTags(message.Tags)
};

if (message.ReplyTo != null)
Expand Down Expand Up @@ -192,5 +194,28 @@ internal virtual List<MergeFieldJson> PopulateMergeData(IDictionary<string, stri
var result = mergeData?.Select(item => new MergeFieldJson(item.Key, item.Value));
return result?.ToList();
}


/// <summary>
/// Converting a <c><![CDATA[ IList<IMetadata> ]]></c> to a <c><![CDATA[ List<MetadataHeaderJson> ]]></c>
/// </summary>
/// <param name="metadata">A <c><![CDATA[ IList<IMetadata> ]]></c> from the message</param>
/// <returns>A <c><![CDATA[ List<MetadataHeaderJson> ]]></c> used in generating an InjectionRequest</returns>
internal virtual List<MetadataHeaderJson> PopulateMetadata(IList<IMetadata> metadata)
{
var result = metadata?.Select(item => new MetadataHeaderJson(item.Key, item.Value));
return result?.ToList();
}

/// <summary>
/// Converting a <c><![CDATA[ IList<ICustomHeader> ]]></c> to a <c><![CDATA[ List<CustomHeadersJson> ]]></c>
/// </summary>
/// <param name="tags">A <c><![CDATA[ IList<ICustomHeader> ]]></c> from the message</param>
/// <returns>A <c><![CDATA[ List<CustomHeadersJson> ]]></c> used in generating an InjectionRequest</returns>
internal virtual List<string> PopulateTags(IList<string> tags)
{
var result = tags.ToList();
return result?.ToList();
}
}
}
14 changes: 14 additions & 0 deletions src/SocketLabs/InjectionApi/Core/SendValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ internal virtual SendResult ValidateIMessageBase(IMessageBase message)
if (message.CustomHeaders != null && message.CustomHeaders.Any())
if (!HasValidCustomHeaders(message.CustomHeaders)) return SendResult.MessageValidationInvalidCustomHeaders;

if (message.Metadata != null && message.Metadata.Any())
if (!HasValidMetadata(message.Metadata)) return SendResult.MessageValidationInvalidMetadata;

return SendResult.Success;
}

Expand Down Expand Up @@ -334,5 +337,16 @@ internal virtual bool HasValidCustomHeaders(IList<ICustomHeader> customHeaders)
var result = customHeaders?.Where(item => !item.IsValid);
return result == null || !result.Any();
}

/// <summary>
/// Check if <c>IMetadata</c> in List are valid
/// </summary>
/// <param name="metadata"><c><![CDATA[ IList<IMetadata> ]]></c> to validate</param>
/// <returns><c>bool</c> result</returns>
internal virtual bool HasValidMetadata(IList<IMetadata> metadata)
{
var result = metadata?.Where(item => !item.IsValid);
return result == null || !result.Any();
}
}
}
13 changes: 13 additions & 0 deletions src/SocketLabs/InjectionApi/Core/Serialization/MessageJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public MessageJson()
Bcc = new List<AddressJson>();
MergeData = new MergeDataJson();
Attachments = new List<AttachmentJson>();
Metadata = new List<MetadataHeaderJson>();
Tags = new List<string>();
}

/// <summary>
Expand Down Expand Up @@ -101,6 +103,16 @@ public MessageJson()
/// Gets or sets the list of merge data.
/// </summary>
public MergeDataJson MergeData { get; set; }

/// <summary>
/// A list of metadata headers added to the message.
/// </summary>
public List<MetadataHeaderJson> Metadata { get; set; }

/// <summary>
/// A list of tag headers added to the message.
/// </summary>
public List<string> Tags { get; set; }

#region Conditional Property Serialization

Expand Down Expand Up @@ -170,5 +182,6 @@ public bool ShouldSerializeAttachment()
}

#endregion

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace SocketLabs.InjectionApi.Core.Serialization
{
/// <summary>
/// Represents a metadata item as a key and value pair.
/// To be serialized into JSON string before sending to the Injection Api.
/// </summary>
internal class MetadataHeaderJson
{
/// <summary>
/// Creates a new instance of the MetadataHeaderJson class and sets the key and value pair.
/// </summary>
/// <param name="key">The key of your custom header.</param>
/// <param name="value">The value for your custom header.</param>
public MetadataHeaderJson(string key, string value)
{
Key = key;
Value = value;
}

/// <summary>
/// Gets or sets the metadata key.
/// </summary>
public string Key { get; set; }

/// <summary>
/// Gets or sets the metadata value.
/// </summary>
public string Value { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/SocketLabs/InjectionApi/Message/BasicMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,22 @@ public class BasicMessage : IBasicMessage
/// </remarks>
public IList<ICustomHeader> CustomHeaders { get; set; } = new List<ICustomHeader>();

/// <summary>
/// A list of metadata headers added to the message.
/// </summary>
/// <remarks>
/// (Optional)
/// </remarks>
public IList<IMetadata> Metadata { get; set; } = new List<IMetadata>();

/// <summary>
/// A list of tag headers added to the message.
/// </summary>
/// <remarks>
/// (Optional)
/// </remarks>
public IList<string> Tags { get; set; } = new List<string>();

/// <summary>
/// Returns the number of recipients and subject for the message, useful for debugging.
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions src/SocketLabs/InjectionApi/Message/BulkMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ public class BulkMessage : IBulkMessage
/// </remarks>
public IList<ICustomHeader> CustomHeaders { get; set; } = new List<ICustomHeader>();

/// <summary>
/// A list of metadata headers added to the message.
/// </summary>
/// <remarks>
/// (Optional)
/// </remarks>
public IList<IMetadata> Metadata { get; set; } = new List<IMetadata>();

/// <summary>
/// A list of tag headers added to the message.
/// </summary>
/// <remarks>
/// (Optional)
/// </remarks>
public IList<string> Tags { get; set; } = new List<string>();

/// <summary>
/// Returns the number of recipients and subject for the message, useful for debugging.
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions src/SocketLabs/InjectionApi/Message/IMessageBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,22 @@ public interface IMessageBase
/// (Optional)
/// </remarks>
IList<ICustomHeader> CustomHeaders { get; set; }


/// <summary>
/// A list of metadata headers added to the message.
/// </summary>
/// <remarks>
/// (Optional)
/// </remarks>
IList<IMetadata> Metadata { get; set; }

/// <summary>
/// A list of tag headers added to the message.
/// </summary>
/// <remarks>
/// (Optional)
/// </remarks>
IList<string> Tags { get; set; }
}
}
35 changes: 35 additions & 0 deletions src/SocketLabs/InjectionApi/Message/IMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace SocketLabs.InjectionApi.Message
{

/// <summary>
/// Represents a metadata item as a key and value pair.
/// </summary>
/// <example>
/// Using extension methods
/// <code>
/// var metadata = new <![CDATA[ List<IMetadata> ]]>();
/// metadata.Add("key1", "value1");
/// metadata.Add("key2", "value2");
/// </code>
/// </example>
/// <seealso cref="Metadata"/>
/// <seealso cref="SocketLabsExtensions"/>
public interface IMetadata
{
/// <summary>
/// Gets or sets the metadata key.
/// </summary>
string Key { get; set; }

/// <summary>
/// Gets or sets the metadata value.
/// </summary>
string Value { get; set; }

/// <summary>
/// A quick check to ensure that the metadata item is valid.
/// </summary>
bool IsValid { get; }
}

}
Loading