diff --git a/evernote2onenote/src/MainFrm.cs b/evernote2onenote/src/MainFrm.cs index dc03f73..217da48 100644 --- a/evernote2onenote/src/MainFrm.cs +++ b/evernote2onenote/src/MainFrm.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Net.Mail; using System.Text; using System.Text.RegularExpressions; using System.Threading; @@ -516,7 +517,8 @@ private void ImportNotesToOnenote(List notesEvernote, string exportFile) tempfiles.Add(tempfilepath); var rx = new Regex(@"]*?hash=""" + attachment.Hash + @"""[^>]*/>", RegexOptions.IgnoreCase); - if ((attachment.ContentType != null) && (attachment.ContentType.Contains("image") && rx.Match(htmlBody).Success)) + var rxMatch = rx.Match(htmlBody); + if ((attachment.ContentType != null) && (attachment.ContentType.Contains("image") && rxMatch.Success)) { // replace the tag with an tag htmlBody = rx.Replace(htmlBody, @""); @@ -558,6 +560,17 @@ private void ImportNotesToOnenote(List notesEvernote, string exportFile) htmlBody = htmlBody.Trim(); htmlBody = @"" + htmlBody; + // Evernote does not escape < and > chars in
 sections!
+                            // do that here so we don't get malformed xml
+                            var rxPre = new Regex(@"]*?>(.+)
", RegexOptions.IgnoreCase|RegexOptions.Singleline); + foreach (Match match in rxPre.Matches(htmlBody)) + { + var fullPreSection = match.ToString(); + var innerSection = match.Groups[1].ToString(); + var innserSectionCorrect = innerSection.Replace("<", "<").Replace(">", ">"); + fullPreSection = fullPreSection.Replace(innerSection, innserSectionCorrect); + htmlBody = rxPre.Replace(htmlBody, fullPreSection); + } var emailBody = htmlBody; emailBody = _rxDate.Replace(emailBody, "Date: " + note.Date.ToString("ddd, dd MMM yyyy HH:mm:ss K")); emailBody = emailBody.Replace("'", "'"); @@ -591,7 +604,12 @@ private void ImportNotesToOnenote(List notesEvernote, string exportFile) { var sectionId = _useUnfiledSection ? _newnbId : GetSection("not specified"); _onApp.CreateNewPage(sectionId, out pageId, OneNote.NewPageStyle.npsBlankPageWithTitle); - //_onApp.GetPageContent(pageId, out _); + //string pages = string.Empty; + //_onApp.GetHierarchy(sectionId, OneNote.HierarchyScope.hsPages, out pages); + //string pageContent = string.Empty; + //string testPageId = pageId; + //_onApp.GetPageContent(testPageId, out pageContent); + //OneNote uses HTML for the xml string to pass to the UpdatePageContent, so use the //Outlook HTMLBody property. It coerces rtf and plain text to HTML. var outlineId = new Random().Next();