public void ScanInbox() { MsOutlook.NameSpace ns = null; MsOutlook.MAPIFolder inbox = null; MsOutlook.Items items = null; try { if (!Global.IsReadyRedlineEnabled) { Logger.LogInfo(string.Format("Ready Redline, is turned off in the options.")); return; } ns = Global.ApplicationProvider.Host.GetNamespace("MAPI"); if (ns != null) { inbox = ns.GetDefaultFolder(MsOutlook.OlDefaultFolders.olFolderInbox); if (inbox != null) { string filter = "@SQL=%today(\"urn:schemas:httpmail:datereceived\")%"; var inboxItems = inbox.Items; items = inboxItems.Restrict(filter); Marshal.ReleaseComObject(inboxItems); foreach (dynamic item in items) { if (item is MsOutlook.MailItem) { Logger.LogInfo(string.Format("Ready Redline - scanning inbox item {0}", (item as MsOutlook.MailItem).Subject)); IContentSource source = new OutlookNewMailSource(Global.ApplicationProvider, item as MsOutlook.MailItem); IStrategyResult results = source.ApplyStrategy(new ContentChangedStrategy(null)); ApplyCategory(results); } Marshal.ReleaseComObject(item); } } } } catch (System.Exception e) { Logger.LogError(e); } finally { if (items != null) Marshal.ReleaseComObject(items); if (inbox != null) Marshal.ReleaseComObject(inbox); if (ns != null) Marshal.ReleaseComObject(ns); } }
public void NewMailArrived(string entryIdCollection) { if (!Global.IsReadyRedlineEnabled) { Logger.LogInfo(string.Format("Ready Redline, is turned off in the options.")); return; } IContentSource source = new OutlookNewMailSource(Global.ApplicationProvider, entryIdCollection); IStrategyResult results = source.ApplyStrategy(new ContentChangedStrategy(null)); ApplyCategory(results); }