Skip to content

Commit

Permalink
Update HtmlPreviewVisitor to handle text/calender scheduling events (#…
Browse files Browse the repository at this point in the history
…1119)

* Update HtmlPreviewVisitor to handle text/calender scheduling events

* Fix text/calendar handling in HtmlPreviewVisitor

---------

Co-authored-by: Jeffrey Stedfast <jestedfa@microsoft.com>
  • Loading branch information
TimBo93 and jstedfast authored Dec 16, 2024
1 parent 2b375b9 commit 9c2659f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
15 changes: 15 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ class HtmlPreviewVisitor : MimeVisitor
{
List<MultipartRelated> stack = new List<MultipartRelated> ();
List<MimeEntity> attachments = new List<MimeEntity> ();
List<MimeEntity> calenderAttachments = new List<MimeEntity> ();

readonly string tempDir;
string body;

Expand All @@ -283,6 +285,13 @@ class HtmlPreviewVisitor : MimeVisitor
get { return attachments; }
}

/// <summary>
/// The list of text/calender entries that were in the MimeMessage.
/// </summary>
public IList<MimeEntity> CalenderAttachments {
get { return calenderAttachments; }
}

/// <summary>
/// The HTML string that can be set on the BrowserControl.
/// </summary>
Expand Down Expand Up @@ -459,6 +468,12 @@ class HtmlPreviewVisitor : MimeVisitor
{
TextConverter converter;

// treat text/calendar parts as attachments rather than message bodies
if (entity.ContentType.IsMimeType ("text", "calendar")) {
calendarAattachments.Add (entity);
return;
}

if (body != null) {
// since we've already found the body, treat this as an attachment
attachments.Add (entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class HtmlPreviewVisitor : MimeVisitor
{
readonly List<MultipartRelated> stack = new List<MultipartRelated> ();
readonly List<MimeEntity> attachments = new List<MimeEntity> ();
readonly List<MimeEntity> calenderAttachments = new List<MimeEntity> ();

readonly WebView webView;
bool renderedBody;

Expand All @@ -60,6 +62,13 @@ public IList<MimeEntity> Attachments {
get { return attachments; }
}

/// <summary>
/// The list of text/calender entries that were in the MimeMessage.
/// </summary>
public IList<MimeEntity> CalenderAttachments {
get { return calenderAttachments; }
}

protected override void VisitMultipartAlternative (MultipartAlternative alternative)
{
// walk the multipart/alternative children backwards from greatest level of faithfulness to the least faithful
Expand Down Expand Up @@ -127,6 +136,12 @@ protected override void VisitTextPart (TextPart entity)
{
TextConverter converter;

// treat text/calendar parts as attachments rather than message bodies
if (entity.ContentType.IsMimeType ("text", "calendar")) {
calenderAttachments.Add (entity);
return;
}

if (renderedBody) {
// since we've already found the body, treat this as an attachment
attachments.Add (entity);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// HtmlPreviewVisitor.cs
//
// Author: Jeffrey Stedfast <jestedfa@microsoft.com>
Expand Down Expand Up @@ -42,6 +42,8 @@ class HtmlPreviewVisitor : MimeVisitor
{
readonly List<MultipartRelated> stack = new List<MultipartRelated> ();
readonly List<MimeEntity> attachments = new List<MimeEntity> ();
readonly List<MimeEntity> calenderAttachments = new List<MimeEntity> ();

readonly UIWebView webView;
bool renderedBody;

Expand All @@ -60,6 +62,13 @@ public IList<MimeEntity> Attachments {
get { return attachments; }
}

/// <summary>
/// The list of text/calender entries that were in the MimeMessage.
/// </summary>
public IList<MimeEntity> CalenderAttachments {
get { return calenderAttachments; }
}

protected override void VisitMultipartAlternative (MultipartAlternative alternative)
{
// walk the multipart/alternative children backwards from greatest level of faithfulness to the least faithful
Expand Down Expand Up @@ -127,6 +136,12 @@ protected override void VisitTextPart (TextPart entity)
{
TextConverter converter;

// treat text/calendar parts as attachments rather than message bodies
if (entity.ContentType.IsMimeType ("text", "calendar")) {
calenderAttachments.Add (entity);
return;
}

if (renderedBody) {
// since we've already found the body, treat this as an attachment
attachments.Add (entity);
Expand Down
15 changes: 15 additions & 0 deletions samples/MessageReader/MessageReader/HtmlPreviewVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class HtmlPreviewVisitor : MimeVisitor
{
readonly List<MultipartRelated> stack = new List<MultipartRelated> ();
readonly List<MimeEntity> attachments = new List<MimeEntity> ();
readonly List<MimeEntity> calenderAttachments = new List<MimeEntity> ();

string body;

/// <summary>
Expand All @@ -57,6 +59,13 @@ public IList<MimeEntity> Attachments {
get { return attachments; }
}

/// <summary>
/// The list of text/calender entries that were in the MimeMessage.
/// </summary>
public IList<MimeEntity> CalenderAttachments {
get { return calenderAttachments; }
}

/// <summary>
/// The HTML string that can be set on the BrowserControl.
/// </summary>
Expand Down Expand Up @@ -206,6 +215,12 @@ protected override void VisitTextPart (TextPart entity)
{
TextConverter converter;

// treat text/calendar parts as attachments rather than message bodies
if (entity.ContentType.IsMimeType ("text", "calendar")) {
calenderAttachments.Add (entity);
return;
}

if (body != null) {
// since we've already found the body, treat this as an attachment
attachments.Add (entity);
Expand Down

0 comments on commit 9c2659f

Please sign in to comment.