static bool ProcessResourceTextImpl(IResource res, IResourceTextConsumer consumer) { OutlookProcessor.CheckState(); try { OutlookProcessor processor = OutlookSession.OutlookProcessor; if (processor != null) { MailBodyDescriptorDelegate myDelegate = CreateMailBodyDescriptor; MailBodyDescriptor mailBody = (MailBodyDescriptor)processor.RunUniqueJob(myDelegate, res); if (mailBody != null && Core.State != CoreState.ShuttingDown) { // Order of sections: Source, Subject, Body. IResource resPerson = res.GetLinkProp(Core.ContactManager.Props.LinkFrom); IResource resAccount = res.GetLinkProp(PROP.EmailAccountFrom); if (resPerson != null) { // Construct [From] section out of contact name and its account string fromText = resPerson.DisplayName; if (resAccount != null) { fromText += " " + resAccount.DisplayName; } consumer.AddDocumentFragment(res.Id, fromText, DocumentSection.SourceSection); } consumer.AddDocumentHeading(res.Id, mailBody.Subject); consumer.RestartOffsetCounting(); if (mailBody.IsHTML) { HtmlIndexer.IndexHtml(res, mailBody.Body, consumer, DocumentSection.BodySection); } else { consumer.AddDocumentFragment(res.Id, mailBody.Body.Replace("\r\n", "\n")); } } } } catch (OutlookThreadTimeoutException) { if (consumer.Purpose == TextRequestPurpose.Indexing) { // retry indexing of the email later Guard.QueryIndexingWithCheckId(res); } return(false); } return(true); }
bool IResourceTextProvider.ProcessResourceText(IResource res, IResourceTextConsumer consumer) { if (res != null) { int id = res.Id; // if (res.Type == NntpPlugin._newsArticle || res.Type == NntpPlugin._newsLocalArticle) if (NntpPlugin.IsNntpType(res.Type)) { string text = res.GetPropText(Core.Props.LongBody); if (text.Trim().Length > 0) { consumer.AddDocumentFragment(id, text); } else { HtmlIndexer.IndexHtml(res, res.GetPropText(NntpPlugin._propHtmlContent), consumer, DocumentSection.BodySection); } consumer.RestartOffsetCounting(); consumer.AddDocumentHeading(id, res.GetPropText(Core.Props.Subject)); IResource author = res.GetLinkProp(Core.ContactManager.Props.LinkFrom); IResource account = res.GetLinkProp(Core.ContactManager.Props.LinkEmailAcctFrom); if (author != null) { // Construct [From] section out of contact name and its account string fromText = author.DisplayName; if (account != null) { fromText += " " + account.DisplayName; } consumer.AddDocumentFragment(id, fromText + " ", DocumentSection.SourceSection); } IResourceList groups = res.GetLinksOfType(NntpPlugin._newsGroup, NntpPlugin._propTo); foreach (IResource group in groups) { consumer.AddDocumentFragment(id, group.GetPropText(Core.Props.Name) + " ", DocumentSection.SourceSection); } } else { IResource article = res.GetLinkProp(NntpPlugin._propAttachment); if (article != null && NntpPlugin.IsNntpType(article.Type)) { consumer.AddDocumentHeading(id, res.GetPropText(Core.Props.Name)); } } } return(true); }
public void CheckOffsetsTags() { string sBody = "<html>Welcome</br>to <b>hell</b> </html>"; HtmlIndexer.IndexHtml(0xCD, sBody, this, null); Assert.AreEqual(_sFragments.Count, 4); Assert.AreEqual(_sFragments[0], "Welcome"); Assert.AreEqual(_sFragments[1], "to "); Assert.AreEqual(_sFragments[2], "hell"); Assert.AreEqual(_sFragments[3], " "); Assert.AreEqual(_nOffsets[0], sBody.IndexOf("Welcome")); Assert.AreEqual(_nOffsets[1], sBody.IndexOf("to")); Assert.AreEqual(_nOffsets[2], sBody.IndexOf("hell")); Assert.AreEqual(_nOffsets[3], sBody.IndexOf(" ")); }
public void CheckOffsetsSimple() { string sBody = "Here comes the <nite>!"; HtmlIndexer.IndexHtml(0xCD, sBody, this, null); Assert.AreEqual(_sFragments.Count, 4); Assert.AreEqual(_sFragments[0], "Here "); Assert.AreEqual(_sFragments[1], "comes "); Assert.AreEqual(_sFragments[2], "the <"); Assert.AreEqual(_sFragments[3], "nite>!"); Assert.AreEqual(_nOffsets[0], sBody.IndexOf("Here")); Assert.AreEqual(_nOffsets[1], sBody.IndexOf("comes")); Assert.AreEqual(_nOffsets[2], sBody.IndexOf("the")); Assert.AreEqual(_nOffsets[3], sBody.IndexOf("nite")); }
internal static void RunConverter(string fileName, IResourceTextConsumer consumer, IResource res) { Process process = CreateConverterProcess(fileName, true); try { if (!process.Start()) { throw new Exception(); } } catch { return; } try { Encoding utf8 = new UTF8Encoding(false, false); StreamReader outputReader = new StreamReader(process.StandardOutput.BaseStream, utf8); string content = Utils.StreamReaderReadToEnd(outputReader); consumer.RestartOffsetCounting(); // Just in case ;) HtmlIndexer.IndexHtml(res, content, consumer, DocumentSection.BodySection); } finally { string stderr = Utils.StreamReaderReadToEnd(process.StandardError); process.WaitForExit(); if (process.ExitCode != 0) { throw new Exception(_converterName + " (Excel-to-HTML) has performed an invalid operation while converting \"" + fileName + "\". " + stderr); } } return; }
private static void ProcessHTMLFragment(IResource res, IResourceTextConsumer consumer) { HtmlIndexer.IndexHtml(res, res.GetPropText(Core.Props.LongBody), consumer, null); }