diff --git a/Source/StrongGrid/Models/Webhooks/InboundEmailAttachment.cs b/Source/StrongGrid/Models/Webhooks/InboundEmailAttachment.cs
index 01430250..105a38d2 100644
--- a/Source/StrongGrid/Models/Webhooks/InboundEmailAttachment.cs
+++ b/Source/StrongGrid/Models/Webhooks/InboundEmailAttachment.cs
@@ -22,6 +22,7 @@ public class InboundEmailAttachment
///
/// The content-type.
///
+ [JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
public string ContentType { get; set; }
///
diff --git a/Source/StrongGrid/Utilities/DiagnosticHandler.cs b/Source/StrongGrid/Utilities/DiagnosticHandler.cs
index 88c8ccc9..4ba0717b 100644
--- a/Source/StrongGrid/Utilities/DiagnosticHandler.cs
+++ b/Source/StrongGrid/Utilities/DiagnosticHandler.cs
@@ -18,7 +18,7 @@ internal class DiagnosticHandler : IHttpFilter
{
#region FIELDS
- private const string DIAGNOSTIC_ID_HEADER_NAME = "StrongGridDiagnosticId";
+ private const string DIAGNOSTIC_ID_HEADER_NAME = "StrongGrid-DiagnosticId";
private static readonly ILog _logger = LogProvider.For();
private readonly IDictionary, Tuple> _diagnostics = new Dictionary, Tuple>();
diff --git a/Source/StrongGrid/WebhookParser.cs b/Source/StrongGrid/WebhookParser.cs
index 6fa24dc1..b7cff1a5 100644
--- a/Source/StrongGrid/WebhookParser.cs
+++ b/Source/StrongGrid/WebhookParser.cs
@@ -57,6 +57,20 @@ public Event[] ParseWebhookEvents(string requestBody)
/// The .
public InboundEmail ParseInboundEmailWebhook(Stream stream)
{
+ // We need to be able to rewind the stream.
+ // Therefore, we must make a copy of the stream if it doesn't allow changing the position
+ if (!stream.CanSeek)
+ {
+ using (var ms = new MemoryStream())
+ {
+ stream.CopyTo(ms);
+ return ParseInboundEmailWebhook(ms);
+ }
+ }
+
+ // It's important to rewind the stream
+ stream.Position = 0;
+
// Parse the multipart content received from SendGrid
var parser = new MultipartFormDataParser(stream, Encoding.UTF8);
@@ -85,8 +99,9 @@ public InboundEmail ParseInboundEmailWebhook(Stream stream)
var file = parser.Files.FirstOrDefault(f => f.Name == prop.Name);
if (file != null)
{
- attachment.ContentType = file.ContentType;
attachment.Data = file.Data;
+ if (string.IsNullOrEmpty(attachment.ContentType)) attachment.ContentType = file.ContentType;
+ if (string.IsNullOrEmpty(attachment.FileName)) attachment.FileName = file.FileName;
}
return attachment;
@@ -116,7 +131,7 @@ public InboundEmail ParseInboundEmailWebhook(Stream stream)
.Distinct()
.Select(encoding =>
{
- stream.Position = 0;
+ stream.Position = 0; // It's important to rewind the stream
return new
{
Encoding = encoding,