From c31e1e0e4db1e061fe5112481d5f8400348caecf Mon Sep 17 00:00:00 2001 From: SrivastavaPraveen Date: Thu, 28 Feb 2019 12:48:24 -0800 Subject: [PATCH 1/5] Support for Content Location Header as per https://tools.ietf.org/html/rfc2557#page-6 --- OpenPop/Mime/Header/MessageHeader.cs | 11 +++++++-- OpenPop/Mime/MessagePart.cs | 28 +++++++++++++++-------- OpenPopUnitTests/Mime/MessagePartTests.cs | 16 ++++++++++++- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/OpenPop/Mime/Header/MessageHeader.cs b/OpenPop/Mime/Header/MessageHeader.cs index 438e9d8..7c02a46 100644 --- a/OpenPop/Mime/Header/MessageHeader.cs +++ b/OpenPop/Mime/Header/MessageHeader.cs @@ -40,8 +40,15 @@ public sealed class MessageHeader /// public string ContentDescription { get; private set; } - /// - /// ID of the content part (like an attached image). Used with MultiPart messages.
+ /// + /// The Content location.
+ ///
+ /// if no Content-Location header was present in the message. + ///
+ public string ContentLocation { get; private set; } + + /// + /// ID of the content part (like an attached image). Used with MultiPart messages.
///
/// if no Content-ID header field was present in the message. ///
diff --git a/OpenPop/Mime/MessagePart.cs b/OpenPop/Mime/MessagePart.cs index 78c480f..28e6dde 100644 --- a/OpenPop/Mime/MessagePart.cs +++ b/OpenPop/Mime/MessagePart.cs @@ -100,15 +100,22 @@ public class MessagePart /// if no Content-Description header was present in the message.
///
public string ContentDescription { get; private set; } - - /// - /// This header describes the Content encoding during transfer.
- ///
- /// If no Content-Transfer-Encoding header was present in the message, it is set - /// to the default of SevenBit in accordance to the RFC. - ///
- /// See RFC 2045 section 6 for details - public ContentTransferEncoding ContentTransferEncoding { get; private set; } + + /// + /// his header describes the Content location.
+ ///
+ /// if no Content-Location header was present in the message.
+ ///
+ public string ContentLocation { get; private set; } + + /// + /// This header describes the Content encoding during transfer.
+ ///
+ /// If no Content-Transfer-Encoding header was present in the message, it is set + /// to the default of SevenBit in accordance to the RFC. + ///
+ /// See RFC 2045 section 6 for details + public ContentTransferEncoding ContentTransferEncoding { get; private set; } /// /// ID of the content part (like an attached image). Used with MultiPart messages.
@@ -226,8 +233,9 @@ internal MessagePart(byte[] rawBody, MessageHeader headers, IParsingErrorHandler ContentTransferEncoding = headers.ContentTransferEncoding; ContentId = headers.ContentId; ContentDisposition = headers.ContentDisposition; + ContentLocation = headers.ContentLocation; - FileName = FindFileName(ContentType, ContentDisposition, "(no name)"); + FileName = FindFileName(ContentType, ContentDisposition, "(no name)"); try { BodyEncoding = ParseBodyEncoding(ContentType.CharSet); diff --git a/OpenPopUnitTests/Mime/MessagePartTests.cs b/OpenPopUnitTests/Mime/MessagePartTests.cs index 19188bb..752f6c4 100644 --- a/OpenPopUnitTests/Mime/MessagePartTests.cs +++ b/OpenPopUnitTests/Mime/MessagePartTests.cs @@ -180,7 +180,21 @@ public void TestContentDescription() Assert.AreEqual(expectedDescription, actualDescription); } - [Test] + [Test] + public void TestContentLocation() + { + const string messagePartContent = + "Content-Location: Mime-Location\r\n" + + "\r\n"; // End of message headers + + MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart; + + const string expectedLocation = "Mime-Location"; + string actualLocation = messagePart.ContentLocation; + Assert.AreEqual(expectedLocation, actualLocation); + } + + [Test] public void TestContentDescriptionTwo() { const string messagePartContent = From f59dd9f825bb3cd69db7012cab0066eb7ea7aa9f Mon Sep 17 00:00:00 2001 From: SrivastavaPraveen <48104188+SrivastavaPraveen@users.noreply.github.com> Date: Thu, 28 Feb 2019 13:07:45 -0800 Subject: [PATCH 2/5] upated indentation --- OpenPop/Mime/Header/MessageHeader.cs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/OpenPop/Mime/Header/MessageHeader.cs b/OpenPop/Mime/Header/MessageHeader.cs index 7c02a46..e761360 100644 --- a/OpenPop/Mime/Header/MessageHeader.cs +++ b/OpenPop/Mime/Header/MessageHeader.cs @@ -40,15 +40,15 @@ public sealed class MessageHeader ///
public string ContentDescription { get; private set; } - /// - /// The Content location.
- ///
- /// if no Content-Location header was present in the message. - ///
- public string ContentLocation { get; private set; } - - /// - /// ID of the content part (like an attached image). Used with MultiPart messages.
+ /// + /// The Content location.
+ ///
+ /// if no Content-Location header was present in the message. + ///
+ public string ContentLocation { get; private set; } + + /// + /// ID of the content part (like an attached image). Used with MultiPart messages.
///
/// if no Content-ID header field was present in the message. ///
@@ -447,7 +447,12 @@ private void ParseHeader(string headerName, string headerValue) // Human description of for example a file. Can be encoded ContentDescription = EncodedWord.Decode(headerValue.Trim()); break; - + + // See https://tools.ietf.org/html/rfc2557#page-6 + case "CONTENT-LOCATION": + ContentLocation = headerValue.Trim(); + break; + // See http://tools.ietf.org/html/rfc2045#section-5.1 // Example: Content-type: text/plain; charset="us-ascii" case "CONTENT-TYPE": @@ -480,4 +485,4 @@ private void ParseHeader(string headerName, string headerValue) } #endregion } -} \ No newline at end of file +} From 336195a0f3d17d1a595065b56587d27645c88ec8 Mon Sep 17 00:00:00 2001 From: SrivastavaPraveen <48104188+SrivastavaPraveen@users.noreply.github.com> Date: Thu, 28 Feb 2019 13:08:50 -0800 Subject: [PATCH 3/5] Update MessagePart.cs --- OpenPop/Mime/MessagePart.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OpenPop/Mime/MessagePart.cs b/OpenPop/Mime/MessagePart.cs index 28e6dde..824d262 100644 --- a/OpenPop/Mime/MessagePart.cs +++ b/OpenPop/Mime/MessagePart.cs @@ -233,9 +233,8 @@ internal MessagePart(byte[] rawBody, MessageHeader headers, IParsingErrorHandler ContentTransferEncoding = headers.ContentTransferEncoding; ContentId = headers.ContentId; ContentDisposition = headers.ContentDisposition; - ContentLocation = headers.ContentLocation; - - FileName = FindFileName(ContentType, ContentDisposition, "(no name)"); + ContentLocation = headers.ContentLocation; + FileName = FindFileName(ContentType, ContentDisposition, "(no name)"); try { BodyEncoding = ParseBodyEncoding(ContentType.CharSet); @@ -553,4 +552,4 @@ public void Save(Stream messageStream) } #endregion } -} \ No newline at end of file +} From 93814d5d923a860ac5aac8e4e50c55384e90ba2c Mon Sep 17 00:00:00 2001 From: SrivastavaPraveen <48104188+SrivastavaPraveen@users.noreply.github.com> Date: Thu, 28 Feb 2019 13:09:36 -0800 Subject: [PATCH 4/5] Update MessagePart.cs --- OpenPop/Mime/MessagePart.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/OpenPop/Mime/MessagePart.cs b/OpenPop/Mime/MessagePart.cs index 824d262..5eedd4d 100644 --- a/OpenPop/Mime/MessagePart.cs +++ b/OpenPop/Mime/MessagePart.cs @@ -101,21 +101,21 @@ public class MessagePart ///
public string ContentDescription { get; private set; } - /// - /// his header describes the Content location.
- ///
- /// if no Content-Location header was present in the message.
- ///
- public string ContentLocation { get; private set; } - - /// - /// This header describes the Content encoding during transfer.
- ///
- /// If no Content-Transfer-Encoding header was present in the message, it is set - /// to the default of SevenBit in accordance to the RFC. - ///
- /// See RFC 2045 section 6 for details - public ContentTransferEncoding ContentTransferEncoding { get; private set; } + /// + /// his header describes the Content location.
+ ///
+ /// if no Content-Location header was present in the message.
+ ///
+ public string ContentLocation { get; private set; } + + /// + /// This header describes the Content encoding during transfer.
+ ///
+ /// If no Content-Transfer-Encoding header was present in the message, it is set + /// to the default of SevenBit in accordance to the RFC. + ///
+ /// See RFC 2045 section 6 for details + public ContentTransferEncoding ContentTransferEncoding { get; private set; } /// /// ID of the content part (like an attached image). Used with MultiPart messages.
From c24316b4b87ccc023bcfba270c39b0238c2690d6 Mon Sep 17 00:00:00 2001 From: SrivastavaPraveen <48104188+SrivastavaPraveen@users.noreply.github.com> Date: Thu, 28 Feb 2019 13:10:17 -0800 Subject: [PATCH 5/5] Update MessagePartTests.cs --- OpenPopUnitTests/Mime/MessagePartTests.cs | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/OpenPopUnitTests/Mime/MessagePartTests.cs b/OpenPopUnitTests/Mime/MessagePartTests.cs index 752f6c4..ebef099 100644 --- a/OpenPopUnitTests/Mime/MessagePartTests.cs +++ b/OpenPopUnitTests/Mime/MessagePartTests.cs @@ -179,22 +179,22 @@ public void TestContentDescription() string actualDescription = messagePart.ContentDescription; Assert.AreEqual(expectedDescription, actualDescription); } + + [Test] + public void TestContentLocation() + { + const string messagePartContent = + "Content-Location: Mime-Location\r\n" + + "\r\n"; // End of message headers - [Test] - public void TestContentLocation() - { - const string messagePartContent = - "Content-Location: Mime-Location\r\n" + - "\r\n"; // End of message headers - - MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart; + MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart; - const string expectedLocation = "Mime-Location"; - string actualLocation = messagePart.ContentLocation; - Assert.AreEqual(expectedLocation, actualLocation); - } + const string expectedLocation = "Mime-Location"; + string actualLocation = messagePart.ContentLocation; + Assert.AreEqual(expectedLocation, actualLocation); + } - [Test] + [Test] public void TestContentDescriptionTwo() { const string messagePartContent =