From 9c2659fec48be15ec790fd2b5b528b198d6f084f Mon Sep 17 00:00:00 2001 From: "Tim B." Date: Mon, 16 Dec 2024 16:25:01 +0100 Subject: [PATCH] Update HtmlPreviewVisitor to handle text/calender scheduling events (#1119) * Update HtmlPreviewVisitor to handle text/calender scheduling events * Fix text/calendar handling in HtmlPreviewVisitor --------- Co-authored-by: Jeffrey Stedfast --- FAQ.md | 15 +++++++++++++++ .../MessageReader.Android/HtmlPreviewVisitor.cs | 15 +++++++++++++++ .../MessageReader.iOS/HtmlPreviewVisitor.cs | 17 ++++++++++++++++- .../MessageReader/HtmlPreviewVisitor.cs | 15 +++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/FAQ.md b/FAQ.md index 91102c9874..2ab07d65e9 100644 --- a/FAQ.md +++ b/FAQ.md @@ -264,6 +264,8 @@ class HtmlPreviewVisitor : MimeVisitor { List stack = new List (); List attachments = new List (); + List calenderAttachments = new List (); + readonly string tempDir; string body; @@ -283,6 +285,13 @@ class HtmlPreviewVisitor : MimeVisitor get { return attachments; } } + /// + /// The list of text/calender entries that were in the MimeMessage. + /// + public IList CalenderAttachments { + get { return calenderAttachments; } + } + /// /// The HTML string that can be set on the BrowserControl. /// @@ -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); diff --git a/samples/MessageReader.Android/MessageReader.Android/HtmlPreviewVisitor.cs b/samples/MessageReader.Android/MessageReader.Android/HtmlPreviewVisitor.cs index 790e23a17e..a52b1553cd 100644 --- a/samples/MessageReader.Android/MessageReader.Android/HtmlPreviewVisitor.cs +++ b/samples/MessageReader.Android/MessageReader.Android/HtmlPreviewVisitor.cs @@ -42,6 +42,8 @@ class HtmlPreviewVisitor : MimeVisitor { readonly List stack = new List (); readonly List attachments = new List (); + readonly List calenderAttachments = new List (); + readonly WebView webView; bool renderedBody; @@ -60,6 +62,13 @@ public IList Attachments { get { return attachments; } } + /// + /// The list of text/calender entries that were in the MimeMessage. + /// + public IList 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 @@ -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); diff --git a/samples/MessageReader.iOS/MessageReader.iOS/HtmlPreviewVisitor.cs b/samples/MessageReader.iOS/MessageReader.iOS/HtmlPreviewVisitor.cs index 9812e088f8..34b3a8d9d3 100644 --- a/samples/MessageReader.iOS/MessageReader.iOS/HtmlPreviewVisitor.cs +++ b/samples/MessageReader.iOS/MessageReader.iOS/HtmlPreviewVisitor.cs @@ -1,4 +1,4 @@ -// +// // HtmlPreviewVisitor.cs // // Author: Jeffrey Stedfast @@ -42,6 +42,8 @@ class HtmlPreviewVisitor : MimeVisitor { readonly List stack = new List (); readonly List attachments = new List (); + readonly List calenderAttachments = new List (); + readonly UIWebView webView; bool renderedBody; @@ -60,6 +62,13 @@ public IList Attachments { get { return attachments; } } + /// + /// The list of text/calender entries that were in the MimeMessage. + /// + public IList 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 @@ -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); diff --git a/samples/MessageReader/MessageReader/HtmlPreviewVisitor.cs b/samples/MessageReader/MessageReader/HtmlPreviewVisitor.cs index 3d469d7e8b..656013c613 100644 --- a/samples/MessageReader/MessageReader/HtmlPreviewVisitor.cs +++ b/samples/MessageReader/MessageReader/HtmlPreviewVisitor.cs @@ -41,6 +41,8 @@ class HtmlPreviewVisitor : MimeVisitor { readonly List stack = new List (); readonly List attachments = new List (); + readonly List calenderAttachments = new List (); + string body; /// @@ -57,6 +59,13 @@ public IList Attachments { get { return attachments; } } + /// + /// The list of text/calender entries that were in the MimeMessage. + /// + public IList CalenderAttachments { + get { return calenderAttachments; } + } + /// /// The HTML string that can be set on the BrowserControl. /// @@ -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);