Skip to content

Commit

Permalink
Fixed TextToHtml and FlowedToHtml's OutputHtmlFragment property to work
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Apr 27, 2017
1 parent 1e361d8 commit 61d8e5a
Show file tree
Hide file tree
Showing 101 changed files with 124 additions and 108 deletions.
13 changes: 10 additions & 3 deletions MimeKit/Text/FlowedToHtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public FlowedToHtml ()
/// Get or set whether or not the converter should only output an HTML fragment.
/// </summary>
/// <remarks>
/// Gets or sets whether or not the converter should only output an HTML fragment.
/// Gets or sets whether or not the converter should only output an entire
/// HTML document or just a fragment of the HTML body content.
/// </remarks>
/// <value><c>true</c> if the converter should only output an HTML fragment; otherwise, <c>false</c>.</value>
public bool OutputHtmlFragment {
Expand Down Expand Up @@ -359,9 +360,12 @@ public override void Convert (TextReader reader, TextWriter writer)
if (writer == null)
throw new ArgumentNullException (nameof (writer));

if (!OutputHtmlFragment)
writer.Write ("<html><body>");

if (!string.IsNullOrEmpty (Header)) {
if (HeaderFormat == HeaderFooterFormat.Text) {
var converter = new TextToHtml ();
var converter = new TextToHtml { OutputHtmlFragment = true };

using (var sr = new StringReader (Header))
converter.Convert (sr, writer);
Expand Down Expand Up @@ -427,14 +431,17 @@ public override void Convert (TextReader reader, TextWriter writer)

if (!string.IsNullOrEmpty (Footer)) {
if (FooterFormat == HeaderFooterFormat.Text) {
var converter = new TextToHtml ();
var converter = new TextToHtml { OutputHtmlFragment = true };

using (var sr = new StringReader (Footer))
converter.Convert (sr, writer);
} else {
writer.Write (Footer);
}
}

if (!OutputHtmlFragment)
writer.Write ("</body></html>");
}
}
}
13 changes: 10 additions & 3 deletions MimeKit/Text/TextToHtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public TextToHtml ()
/// Get or set whether or not the converter should only output an HTML fragment.
/// </summary>
/// <remarks>
/// Gets or sets whether or not the converter should only output an HTML fragment.
/// Gets or sets whether or not the converter should only output an entire
/// HTML document or just a fragment of the HTML body content.
/// </remarks>
/// <value><c>true</c> if the converter should only output an HTML fragment; otherwise, <c>false</c>.</value>
public bool OutputHtmlFragment {
Expand Down Expand Up @@ -287,9 +288,12 @@ public override void Convert (TextReader reader, TextWriter writer)
if (writer == null)
throw new ArgumentNullException (nameof (writer));

if (!OutputHtmlFragment)
writer.Write ("<html><body>");

if (!string.IsNullOrEmpty (Header)) {
if (HeaderFormat == HeaderFooterFormat.Text) {
var converter = new TextToHtml ();
var converter = new TextToHtml { OutputHtmlFragment = true };

using (var sr = new StringReader (Header))
converter.Convert (sr, writer);
Expand Down Expand Up @@ -356,14 +360,17 @@ public override void Convert (TextReader reader, TextWriter writer)

if (!string.IsNullOrEmpty (Footer)) {
if (FooterFormat == HeaderFooterFormat.Text) {
var converter = new TextToHtml ();
var converter = new TextToHtml { OutputHtmlFragment = true };

using (var sr = new StringReader (Footer))
converter.Convert (sr, writer);
} else {
writer.Write (Footer);
}
}

if (!OutputHtmlFragment)
writer.Write ("</body></html>");
}
}
}
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.0.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
You are invited to a <br/><br/>*** STAR TREK 25TH ANNIVERSARY PARTY ***<br/><br/>When: September 28, 1991, 4:30 PM until whenever<br/>What: For those interested, we&#39;ll have a rerun of last year&#39;s season-ending <br/> cliffhanger, and then we&#39;ll tune in the season opener and the 25th <br/> anniversary TV special. Prior to that, if you bring some food <br/> we&#39;ll have a pot-luck meal, and general merriment before and after.<br/>Who: You and your family, including kids of course.<br/>Where: 25 Washington Avenue, Morristown. <br/> (See Nathaniel if you need directions.)<br/>RSVP: 993-8586<br/><br/>What follows is some Star Trek related multimedia mail, the last of which will give you a chance to RSVP on line. <br/><br/>Live Long and Prosper! -- Nathaniel &amp; Trina<br/>
<html><body>You are invited to a <br/><br/>*** STAR TREK 25TH ANNIVERSARY PARTY ***<br/><br/>When: September 28, 1991, 4:30 PM until whenever<br/>What: For those interested, we&#39;ll have a rerun of last year&#39;s season-ending <br/> cliffhanger, and then we&#39;ll tune in the season opener and the 25th <br/> anniversary TV special. Prior to that, if you bring some food <br/> we&#39;ll have a pot-luck meal, and general merriment before and after.<br/>Who: You and your family, including kids of course.<br/>Where: 25 Washington Avenue, Morristown. <br/> (See Nathaniel if you need directions.)<br/>RSVP: 993-8586<br/><br/>What follows is some Star Trek related multimedia mail, the last of which will give you a chance to RSVP on line. <br/><br/>Live Long and Prosper! -- Nathaniel &amp; Trina<br/></body></html>
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.100.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
I&#39;m sending a copy of this message to the author of richlex.c,<br/>wishing my small change to richlex.c may be adopted. <br/><br/>In message &lt;<a href="mailto:ceDpgPa0M2Yt8Gvww6@thumper.bellcore.com">ceDpgPa0M2Yt8Gvww6@thumper.bellcore.com</a>&gt; on 06/18/92(00:32:43)<br/>you Nathaniel Borenstein &lt;<a href="mailto:nsb@thumper.bellcore.com">nsb@thumper.bellcore.com</a>&gt; wrote:<br/> |Can you<br/> |possibly send me an example of multibyte richtext that works with your<br/> |modified code (as well as one that doesn&#39;t) so that I can try it out and<br/> |see? <br/><br/>Ok, I enclosed a picture which shows how the old and new version of <br/>richtext process a sample data in Japanese (JIS).<br/>
<html><body>I&#39;m sending a copy of this message to the author of richlex.c,<br/>wishing my small change to richlex.c may be adopted. <br/><br/>In message &lt;<a href="mailto:ceDpgPa0M2Yt8Gvww6@thumper.bellcore.com">ceDpgPa0M2Yt8Gvww6@thumper.bellcore.com</a>&gt; on 06/18/92(00:32:43)<br/>you Nathaniel Borenstein &lt;<a href="mailto:nsb@thumper.bellcore.com">nsb@thumper.bellcore.com</a>&gt; wrote:<br/> |Can you<br/> |possibly send me an example of multibyte richtext that works with your<br/> |modified code (as well as one that doesn&#39;t) so that I can try it out and<br/> |see? <br/><br/>Ok, I enclosed a picture which shows how the old and new version of <br/>richtext process a sample data in Japanese (JIS).<br/></body></html>
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.101.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Dear S/MIME developers,<br/><br/> I believe that this is a valid S/MIME multipart/signed message. The<br/>implementation is still quite experimental, so as yet I have no way of<br/>verifying that it is, in fact valid. The code is quite similar to my<br/>PGP/MIME and MOSS multipart/signed implementations, so there&#39;s reason<br/>to believe it works, but, then again, a lot can go wrong.<br/><br/> If anyone can verify this message or tell me where I went wrong, it<br/>would be much appreciated.<br/><br/> By the way, there&#39;s a minor nit to pick in the S/MIME message<br/>format document. After clearly (and correctly) calling out the fact<br/>that MIME parameters including slashes need to be quoted, the example<br/>of the multipart/signed at the end of the document is lacking quotes.<br/><br/> Also, when the spec is finalized, it would be nice if the examples<br/>had valid PKCS data :-)<br/><br/>Raph (who really needs to get some sleep after staying up past 4am)<br/>
<html><body>Dear S/MIME developers,<br/><br/> I believe that this is a valid S/MIME multipart/signed message. The<br/>implementation is still quite experimental, so as yet I have no way of<br/>verifying that it is, in fact valid. The code is quite similar to my<br/>PGP/MIME and MOSS multipart/signed implementations, so there&#39;s reason<br/>to believe it works, but, then again, a lot can go wrong.<br/><br/> If anyone can verify this message or tell me where I went wrong, it<br/>would be much appreciated.<br/><br/> By the way, there&#39;s a minor nit to pick in the S/MIME message<br/>format document. After clearly (and correctly) calling out the fact<br/>that MIME parameters including slashes need to be quoted, the example<br/>of the multipart/signed at the end of the document is lacking quotes.<br/><br/> Also, when the spec is finalized, it would be nice if the examples<br/>had valid PKCS data :-)<br/><br/>Raph (who really needs to get some sleep after staying up past 4am)<br/></body></html>
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.102.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Netscape: here&#39;s my encryption certificate for S/MIME testing<br/>purposes. Beware that this is an Entrust certificate rather than<br/>Verisign. Among other things, this means that I have a separate<br/>key pair for signing and encryption, so you&#39;ll have to use this<br/>one to encrypt for me and use the certif included with signed<br/>messages (rather than this one) to verify signatures.<br/><br/>Eric<br/>---------------------------------------------------------------------<br/>Eric Rosenquist, Strata Software Limited <a href="http://www.strataware.com/">http://www.strataware.com/</a><br/><a href="mailto:rosenqui@strataware.com">mailto:rosenqui@strataware.com</a> Tel: 613-591-1922 Fax: 613-591-3485<br/>Quote: I discovered a meal between breakfast and brunch!<br/> -- Homer Simpson<br/>---------------------------------------------------------------------<br/>
<html><body>Netscape: here&#39;s my encryption certificate for S/MIME testing<br/>purposes. Beware that this is an Entrust certificate rather than<br/>Verisign. Among other things, this means that I have a separate<br/>key pair for signing and encryption, so you&#39;ll have to use this<br/>one to encrypt for me and use the certif included with signed<br/>messages (rather than this one) to verify signatures.<br/><br/>Eric<br/>---------------------------------------------------------------------<br/>Eric Rosenquist, Strata Software Limited <a href="http://www.strataware.com/">http://www.strataware.com/</a><br/><a href="mailto:rosenqui@strataware.com">mailto:rosenqui@strataware.com</a> Tel: 613-591-1922 Fax: 613-591-3485<br/>Quote: I discovered a meal between breakfast and brunch!<br/> -- Homer Simpson<br/>---------------------------------------------------------------------<br/></body></html>
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.103.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hi everyone. I&#39;m a consultant working with Nortel on their S/MIME products.<br/>I&#39;ve already completed basic interop testing against Deming&#39;s Secure<br/>Messenger and at Blake&#39;s suggestion I am about to post a signed message to<br/>this list for others to use in interop testing. If you have questions about<br/>Entrust in general, please visit their web site &lt;<a href="http://www.entrust.com">http://www.entrust.com</a>&gt;. If<br/>you have questions about the forthcoming S/MIME toolkit for Entrust please<br/>email Michel Ranger &lt;<a href="mailto:rangerm@entrust.com">mailto:rangerm@entrust.com</a>&gt; or Ron Vandergeest<br/>&lt;<a href="mailto:rvander@entrust.com">mailto:rvander@entrust.com</a>&gt;. E-mail any technical interop-related questions<br/>directly to me &lt;<a href="mailto:rosenqui@strataware.com">mailto:rosenqui@strataware.com</a>&gt;.<br/><br/>One big thing you should be aware of with Entrust is that it uses separate<br/>key pairs for signing and encryption, so you must be careful to distinguish<br/>between my verification certificate and my signature certificate. You<br/>should import *this* certificate into your local database if you want to be<br/>able to encrypt for me. For now, signed S/MIME messages created with the<br/>Entrust toolkit will include both certificates for the originator as well<br/>as the originator&#39;s CA certificate. Eventually this will be under the<br/>programmatic control of whatever app is using the toolkit, so it&#39;s<br/>important that you look at the certificate you&#39;re importing to make sure<br/>it&#39;s the one you want. You can tell which one you&#39;ve got by looking at the<br/>keyUsage V3 cert extension (object identifier 2.5.29.15). The encryption<br/>certificate has the keyEncipherment bit set (bit number 2 or 0x20) and the<br/>verification certificate has the digitalSignature bit set (bit number 0 or<br/>0x80).<br/><br/>One other thing that some of you may not have encountered before is that my<br/>CA is not Verisign. Included in the P7C (as well as my signed S/MIME<br/>messages) is my CA&#39;s certificate - a self-signed certificate. You can<br/>distinguish this form of certificate (a self-signed CA) from a self-signed<br/>user certificate by looking for the keyCertSign (bit 5) or cRLSign (bit 6)<br/>bits in the keyUsage extension. Failing that, you can look for the<br/>basicConstraints extension to see if the &#39;cA&#39; BOOLEAN field is present and<br/>TRUE.<br/><br/>Without further ado, here is my encryption certificate and my CA&#39;s<br/>signature verification certificate. I&#39;m away all of next week, so if you<br/>have questions or discover any problems please e-mail me ASAP. If you<br/>don&#39;t get a reply by the end of Friday I&#39;ll try to get back to you as soon<br/>as possible after Dec. 2nd.<br/><br/>Eric<br/>---------------------------------------------------------------------<br/>Eric Rosenquist, Strata Software Limited <a href="http://www.strataware.com/">http://www.strataware.com/</a><br/><a href="mailto:rosenqui@strataware.com">mailto:rosenqui@strataware.com</a> Tel: 613-591-1922 Fax: 613-591-3485<br/>Quote: I discovered a meal between breakfast and brunch!<br/> -- Homer Simpson<br/>---------------------------------------------------------------------<br/>
<html><body>Hi everyone. I&#39;m a consultant working with Nortel on their S/MIME products.<br/>I&#39;ve already completed basic interop testing against Deming&#39;s Secure<br/>Messenger and at Blake&#39;s suggestion I am about to post a signed message to<br/>this list for others to use in interop testing. If you have questions about<br/>Entrust in general, please visit their web site &lt;<a href="http://www.entrust.com">http://www.entrust.com</a>&gt;. If<br/>you have questions about the forthcoming S/MIME toolkit for Entrust please<br/>email Michel Ranger &lt;<a href="mailto:rangerm@entrust.com">mailto:rangerm@entrust.com</a>&gt; or Ron Vandergeest<br/>&lt;<a href="mailto:rvander@entrust.com">mailto:rvander@entrust.com</a>&gt;. E-mail any technical interop-related questions<br/>directly to me &lt;<a href="mailto:rosenqui@strataware.com">mailto:rosenqui@strataware.com</a>&gt;.<br/><br/>One big thing you should be aware of with Entrust is that it uses separate<br/>key pairs for signing and encryption, so you must be careful to distinguish<br/>between my verification certificate and my signature certificate. You<br/>should import *this* certificate into your local database if you want to be<br/>able to encrypt for me. For now, signed S/MIME messages created with the<br/>Entrust toolkit will include both certificates for the originator as well<br/>as the originator&#39;s CA certificate. Eventually this will be under the<br/>programmatic control of whatever app is using the toolkit, so it&#39;s<br/>important that you look at the certificate you&#39;re importing to make sure<br/>it&#39;s the one you want. You can tell which one you&#39;ve got by looking at the<br/>keyUsage V3 cert extension (object identifier 2.5.29.15). The encryption<br/>certificate has the keyEncipherment bit set (bit number 2 or 0x20) and the<br/>verification certificate has the digitalSignature bit set (bit number 0 or<br/>0x80).<br/><br/>One other thing that some of you may not have encountered before is that my<br/>CA is not Verisign. Included in the P7C (as well as my signed S/MIME<br/>messages) is my CA&#39;s certificate - a self-signed certificate. You can<br/>distinguish this form of certificate (a self-signed CA) from a self-signed<br/>user certificate by looking for the keyCertSign (bit 5) or cRLSign (bit 6)<br/>bits in the keyUsage extension. Failing that, you can look for the<br/>basicConstraints extension to see if the &#39;cA&#39; BOOLEAN field is present and<br/>TRUE.<br/><br/>Without further ado, here is my encryption certificate and my CA&#39;s<br/>signature verification certificate. I&#39;m away all of next week, so if you<br/>have questions or discover any problems please e-mail me ASAP. If you<br/>don&#39;t get a reply by the end of Friday I&#39;ll try to get back to you as soon<br/>as possible after Dec. 2nd.<br/><br/>Eric<br/>---------------------------------------------------------------------<br/>Eric Rosenquist, Strata Software Limited <a href="http://www.strataware.com/">http://www.strataware.com/</a><br/><a href="mailto:rosenqui@strataware.com">mailto:rosenqui@strataware.com</a> Tel: 613-591-1922 Fax: 613-591-3485<br/>Quote: I discovered a meal between breakfast and brunch!<br/> -- Homer Simpson<br/>---------------------------------------------------------------------<br/></body></html>
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.11.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BOY, was that stupid. As you can probably tell from the picture, I forgot to <br/>put the bold, underlined, and centered environments in place. This should <br/>work better:&lt;nl&gt;&lt;nl&gt;&lt;center&gt;&lt;bold&gt;Boldly&lt;/bold&gt; I shall say&lt;nl&gt;That your bug <br/>has gone away&lt;nl&gt;But I wish to &lt;underline&gt;underline&lt;/underline&gt;&lt;nl&gt;that if the <br/>bug remains, it&#39;s mine.&lt;nl&gt;&lt;/center&gt;&lt;nl&gt;Now, did that look better? To me it <br/>looked like this:&lt;nl&gt;<br/>&lt;nl&gt; <br/>
<html><body>BOY, was that stupid. As you can probably tell from the picture, I forgot to <br/>put the bold, underlined, and centered environments in place. This should <br/>work better:&lt;nl&gt;&lt;nl&gt;&lt;center&gt;&lt;bold&gt;Boldly&lt;/bold&gt; I shall say&lt;nl&gt;That your bug <br/>has gone away&lt;nl&gt;But I wish to &lt;underline&gt;underline&lt;/underline&gt;&lt;nl&gt;that if the <br/>bug remains, it&#39;s mine.&lt;nl&gt;&lt;/center&gt;&lt;nl&gt;Now, did that look better? To me it <br/>looked like this:&lt;nl&gt;<br/>&lt;nl&gt; <br/></body></html>
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.111.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
I sent you an encrypted message that was triple-DES. Let me know if you<br/>had any problems with it...<br/><br/>Blake<br/>
<html><body>I sent you an encrypted message that was triple-DES. Let me know if you<br/>had any problems with it...<br/><br/>Blake<br/></body></html>
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.116.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
blah blah blah<br/>
<html><body>blah blah blah<br/></body></html>
2 changes: 1 addition & 1 deletion UnitTests/TestData/mbox/jwz.body.117.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
I signed this. It is signed by me. <br/>-dh<br/>
<html><body>I signed this. It is signed by me. <br/>-dh<br/></body></html>
Loading

0 comments on commit 61d8e5a

Please sign in to comment.