Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Content Location Header as per https://tools.ietf.org/htm… #81

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 16 additions & 4 deletions OpenPop/Mime/Header/MessageHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ public sealed class MessageHeader
/// </summary>
public string ContentDescription { get; private set; }

/// <summary>
/// ID of the content part (like an attached image). Used with MultiPart messages.<br/>
/// <summary>
/// The Content location.<br/>
/// <br/>
/// <see langword="null"/> if no Content-Location header was present in the message.
/// </summary>
public string ContentLocation { get; private set; }

/// <summary>
/// ID of the content part (like an attached image). Used with MultiPart messages.<br/>
/// <br/>
/// <see langword="null"/> if no Content-ID header field was present in the message.
/// </summary>
Expand Down Expand Up @@ -440,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":
Expand Down Expand Up @@ -473,4 +485,4 @@ private void ParseHeader(string headerName, string headerValue)
}
#endregion
}
}
}
13 changes: 10 additions & 3 deletions OpenPop/Mime/MessagePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ public class MessagePart
/// <see langword="null"/> if no Content-Description header was present in the message.<br/>
/// </summary>
public string ContentDescription { get; private set; }

/// <summary>
/// his header describes the Content location.<br/>
/// <br/>
/// <see langword="null"/> if no Content-Location header was present in the message.<br/>
/// </summary>
public string ContentLocation { get; private set; }

/// <summary>
/// This header describes the Content encoding during transfer.<br/>
Expand All @@ -108,7 +115,7 @@ public class MessagePart
/// to the default of <see cref="Header.ContentTransferEncoding.SevenBit">SevenBit</see> in accordance to the RFC.
/// </summary>
/// <remarks>See <a href="http://tools.ietf.org/html/rfc2045#section-6">RFC 2045 section 6</a> for details</remarks>
public ContentTransferEncoding ContentTransferEncoding { get; private set; }
public ContentTransferEncoding ContentTransferEncoding { get; private set; }

/// <summary>
/// ID of the content part (like an attached image). Used with MultiPart messages.<br/>
Expand Down Expand Up @@ -226,7 +233,7 @@ 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)");
try
{
Expand Down Expand Up @@ -545,4 +552,4 @@ public void Save(Stream messageStream)
}
#endregion
}
}
}
14 changes: 14 additions & 0 deletions OpenPopUnitTests/Mime/MessagePartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ 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

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()
Expand Down