internal static void Detect() { if (!Settings.DetectOwnerEmail) { return; } IEMsgStore defStore = OutlookSession.GetDefaultMsgStore(); if (defStore == null) { return; } string folderId = defStore.GetBinProp(MAPIConst.PR_IPM_SENTMAIL_ENTRYID); if (folderId == null) { return; } string storeID = defStore.GetBinProp(MAPIConst.PR_ENTRYID); if (storeID == null) { return; } IEFolder folder = OutlookSession.OpenFolder(folderId, storeID); if (folder == null) { return; } using ( folder ) { ProcessFolder(folder); } }
public static IEMsgStore OpenMsgStore(string storeId) { if (OutlookSession.OutlookProcessor != null && OutlookSession.OutlookProcessor.ShuttingDown) { return(null); } HashMap.Entry entry = _msgStores.GetEntry(storeId); if (entry != null) { return((IEMsgStore)entry.Value); } IEMsgStore msgStore = null; try { msgStore = _eSession.OpenMsgStore(storeId); } catch (COMException exc) { if (!Trapped(exc)) { throw exc; } _tracer.TraceException(exc); } finally { _msgStores[storeId] = msgStore; } return(msgStore); }
private static void DeleteMessageImpl(string storeId, string entryId, bool DeletedItems) { Guard.EmptyStringArgument(storeId, "storeId"); Guard.EmptyStringArgument(entryId, "entryId"); IEMsgStore msgStore = OutlookSession.OpenMsgStore(storeId); if (msgStore != null) { try { msgStore.DeleteMessage(entryId, DeletedItems); } catch (System.ArgumentException exception) { //there is bug in parameteres for IFolder.DeleteMessages. Try to find it _tracer.Trace("There is problem with parameter while deleting message. EntryId = " + entryId); _tracer.Trace("StoreId = " + storeId); _tracer.TraceException(exception); Core.ReportException(exception, ExceptionReportFlags.AttachLog); } catch (COMException exception) { _tracer.TraceException(exception); StandartJobs.MessageBox("Cannot complete deleting mail. Reason: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public FolderDescriptorEnumerator(IEMsgStore msgStore, string storeID, string storeName, IFolderDescriptorEnumeratorEvent enumListener) { Guard.NullArgument(msgStore, "msgStore"); Guard.NullArgument(enumListener, "enumListener"); _msgStore = msgStore; _storeID = storeID; _storeName = storeName; _enumListener = enumListener; }
private static void DeleteFolderImpl(PairIDs folderIDs, bool DeletedItems) { IEMsgStore msgStore = OutlookSession.OpenMsgStore(folderIDs.StoreId); if (msgStore != null) { msgStore.DeleteFolder(folderIDs.EntryId, DeletedItems); } }
[Test] public void OpenTasksFolderTest() { IEMsgStore msgStore = OutlookSession.GetDefaultMsgStore(); Assert.IsNotNull(msgStore); IEFolder folder = msgStore.OpenTasksFolder(); Assert.IsNotNull(folder); folder.Dispose(); }
public static MAPIIDs GetInboxIDs() { IEMsgStore msgStore = GetDefaultMsgStore(); if (msgStore != null) { return(msgStore.GetInboxIDs()); } return(null); }
public override AbstractJob GetNextJob() { IEMsgStore msgStore = null; while ((_index < _msgStores.Count) && msgStore == null) { msgStore = _msgStores.GetMsgStore(_index++); } if (msgStore == null) { return(null); } return(new FolderEnumeratorJob(msgStore.GetRootFolder())); }
public static IEFolder OpenDefaultTaskFolder() { IEMsgStore defaultMsgStore = GetDefaultMsgStore(); if (defaultMsgStore != null) { IEFolder folder = defaultMsgStore.OpenTasksFolder(); if (folder != null) { return(folder); } } return(FindTaskFolderFromResourceStore()); }
public void LoadTest() { //MessageBox.Show( "LoadTest" ); for (int i = 0; i < 10; ++i) { Tracer._Trace("Test: " + i); OutlookSession.Initialize( ); IEMsgStore msgStore = OutlookSession.GetDefaultMsgStore(); Assert.IsNotNull(msgStore); FolderEnum folderEnum = FolderEnum.SearchForFolders(new string[] { "TasksTest" }); folderEnum.GetFolderDescriptor("TasksTest"); OutlookSession.Uninitialize(); } }
public override bool DisplayMessage(string EntryID, string StoreID) { try { IEMsgStore msgStore = OutlookSession.OpenMsgStore(StoreID); if (msgStore != null) { return(msgStore.DisplayMessage(EntryID, OutlookSession.GetDefaultMsgStore())); } } catch (Exception exception) { ReportProblem(exception); } return(false); }
private bool CreateNewMessage(string subject, string body, EmailBodyFormat bodyFormat, ArrayList recipients, ArrayList attachments, bool useTemplatesInBody) { try { MailBodyFormat mailBodyFormat = MailBodyFormat.HTML; if (bodyFormat == EmailBodyFormat.PlainText) { if (useTemplatesInBody && Settings.UseSignature) { body += "\r\n"; body += Settings.Signature; } mailBodyFormat = MailBodyFormat.PlainText; } else if (bodyFormat == EmailBodyFormat.Html) { body = _rxHtmlComment.Replace(body, ""); body = "<HTML><BODY>" + body; if (useTemplatesInBody && Settings.UseSignature) { body += "\r\n"; body += Settings.Signature; } body += "</BODY></HTML>"; Trace.WriteLine("HTML body for Outlook: \r\n" + body); } IEMsgStore msgStore = OutlookSession.GetDefaultMsgStore(); if (msgStore != null) { return(msgStore.CreateNewMessage(subject, body, mailBodyFormat, recipients, attachments, OutlookSession.GetOutlookDefaultEncodingOut())); } else { throw new ApplicationException("There are no default message store for outlook"); } } catch (Exception exception) { ReportProblem(exception); } return(false); }
public static void Do(IEMsgStore msgStore, string storeID, string storeName, IFolderDescriptorEnumeratorEvent enumListener) { FolderDescriptorEnumerator enumerator = new FolderDescriptorEnumerator(msgStore, storeID, storeName, enumListener); try { enumerator.Enumerate(); } catch (Exception exception) { if (!(exception is ThreadAbortException)) { Core.ReportException(exception, false); } } }
public override bool ReplyMessage(IResource mail, string EntryID, string StoreID) { try { OutlookSession.EMAPISession.SetQuoter(new ReplyQuoter(mail)); IEMsgStore msgStore = OutlookSession.OpenMsgStore(StoreID); if (msgStore != null) { return(msgStore.ReplyMessage(EntryID, OutlookSession.GetDefaultMsgStore())); } return(true); } catch (Exception exception) { ReportProblem(exception); } return(false); }
public static bool IsStorageSupported(IEMsgStore msgStore) { if (Settings.SupportIMAP) { return(true); } IEFolder root = msgStore.GetRootFolder(); if (root == null) { return(true); } using ( root ) { IEFolders folders = OutlookSession.GetFolders(root); if (folders == null) { return(true); } using ( folders ) { int count = folders.GetCount(); for (int i = 0; i < count; ++i) { IEFolder folder = OpenFolder(folders, i); if (folder == null) { continue; } using ( folder ) { string containerClass = folder.GetStringProp(MAPIConst.PR_CONTAINER_CLASS); if (FolderType.IMAP == containerClass) { return(false); } } } } } return(true); }
public static IEMessage OpenMessage(string entryId, string storeId) { IEMsgStore msgStore = OpenMsgStore(storeId); if (msgStore == null) { return(null); } try { return(msgStore.OpenMessage(entryId)); } catch (COMException exc) { if (!Trapped(exc)) { throw exc; } _tracer.TraceException(exc); } return(null); }
public static void Uninitialize() { foreach (HashMap.Entry entry in _msgStores) { IEMsgStore msgStore = (IEMsgStore)entry.Value; if (msgStore != null) { msgStore.Unadvise(); msgStore.Dispose(); } } if (_defaultMsgStore != null) { _defaultMsgStore.Dispose(); } if (_addressBook != null) { _addressBook.Dispose(); } _msgStores.Clear(); _eSession.Uninitialize(); //_eSession.Dispose(); // TODO:Convert: call dtor!!! _eSession = null; }
internal static bool IsIgnoredInfoStore(IEMsgStore msgStore) { Trace.WriteLine("IsIgnoredInfoStore -- checking infostore: "); string entryId = msgStore.GetBinProp(MAPIConst.PR_ENTRYID); if (entryId != null) { IResource infoStore = Core.ResourceStore.FindUniqueResource(STR.MAPIInfoStore, PROP.EntryID, entryId); if (infoStore != null) { if (infoStore.HasProp(Core.Props.Name)) { Trace.WriteLine(" IsIgnoredInfoStore -- with name [" + infoStore.GetStringProp(Core.Props.Name) + "]"); } int prop = infoStore.GetIntProp(PROP.IgnoredFolder); if (prop != 0) { Trace.WriteLine(" IsIgnoredInfoStore -- FLAG IgnoredFolder is set!"); } return(infoStore.GetIntProp(PROP.IgnoredFolder) != 0); } else { Trace.WriteLine(" IsIgnoredInfoStore -- No InfoStore resource found."); } } Trace.WriteLine("IsIgnoredInfoStore -- It has no PR_ENTRYID, trying DeletedItemsEntryID"); string deletedItemsEntryId = msgStore.GetBinProp(MAPIConst.PR_IPM_WASTEBASKET_ENTRYID); if (deletedItemsEntryId != null) { IResource infoStore = Core.ResourceStore.FindUniqueResource(STR.MAPIInfoStore, PROP.DeletedItemsEntryID, deletedItemsEntryId); if (infoStore != null) { if (infoStore.HasProp(Core.Props.Name)) { Trace.WriteLine("IsIgnoredInfoStore -- with name [" + infoStore.GetStringProp(Core.Props.Name) + "]"); } int prop = infoStore.GetIntProp(PROP.IgnoredFolder); if (prop != 0) { Trace.WriteLine("IsIgnoredInfoStore -- FLAG IgnoredFolder is set!"); } return(infoStore.GetIntProp(PROP.IgnoredFolder) != 0); } else { Trace.WriteLine(" IsIgnoredInfoStore -- No InfoStore resource found."); } } Trace.WriteLine("IsIgnoredInfoStore -- It has no PR_IPM_WASTEBASKET_ENTRYID"); return(false); }
public static void Initialize() { try { _outlookVersion = GetOutlookVersionFromRegistry(); } catch (Exception ex) { Core.AddExceptionReportData("\nError getting Outlook version from registry: " + ex.Message); Trace.WriteLine("Error getting Outlook version from registry: " + ex.Message); _outlookVersion = 0; } ReportOutlookAddins(); ReportOutlookExtensions(); _eSession = new EMAPISession(0); _eSession.CheckDependencies(); try { if (!_eSession.Initialize(IsPickLogonProfile(), _libManager)) { throw new Exception("MAPI logon failed"); } } catch (COMException exception) { _tracer.TraceException(exception); Core.ReportBackgroundException(exception); throw new Exception("MAPI logon failed: " + exception.Message); } _addressBook = _eSession.OpenAddrBook(); IEMsgStores stores = _eSession.GetMsgStores(); if (stores != null) { using ( stores ) { int count = stores.GetCount(); Trace.WriteLine("*********************************************************"); Trace.WriteLine("* " + count + " MAPI stores detected"); for (int i = 0; i < count; ++i) { IEMsgStore store = null; try { store = stores.GetMsgStore(i); } catch (EMAPILib.ProblemWhenOpenStorage ex) { Trace.WriteLine("* " + i + "th store caused problem while getting the IEMsgStore resource"); ProblemWithOpeningStorage(ex); } if (store == null) { continue; } string storeID = stores.GetStorageID(i); _msgStores.Add(storeID, store); Trace.WriteLine("* " + i + "th store has StoreID [" + storeID + "]"); if (Settings.UseOutlookListeners) { try { MAPIListenerStub mapiListener = new MAPIListenerStub(new MAPIListener(storeID)); store.Advise(mapiListener); } catch (Exception exception) { _tracer.TraceException(exception); //SetLastException( exception ); } } if (stores.IsDefaultStore(i)) { Trace.WriteLine("* " + i + "th store is a default store"); _defaultMsgStore = store; string delEntryID = _defaultMsgStore.GetBinProp(MAPIConst.PR_IPM_WASTEBASKET_ENTRYID); _deletedFolderIDs = new PairIDs(delEntryID, storeID); } } Trace.WriteLine("*********************************************************"); } } if (_defaultMsgStore == null) { throw new ApplicationException("There is no default storage"); } }
public MAPIInfoStoreDescriptor(IEMsgStore msgStore) { _name = msgStore.GetStringProp(MAPIConst.PR_DISPLAY_NAME); _entryId = msgStore.GetBinProp(MAPIConst.PR_ENTRYID); _deletedItemsId = msgStore.GetBinProp(MAPIConst.PR_IPM_WASTEBASKET_ENTRYID); MAPIIDs mapiIds = msgStore.GetInboxIDs(); if (mapiIds != null) { AddDefaultFolderEntryID(mapiIds.EntryID); } AddDefaultFolderEntryID(_deletedItemsId); AddDefaultFolderEntryID(msgStore.GetBinProp(MAPIConst.PR_IPM_SENTMAIL_ENTRYID)); AddDefaultFolderEntryID(msgStore.GetBinProp(MAPIConst.PR_IPM_OUTBOX_ENTRYID)); IEFolder rootFolder = msgStore.GetRootFolder(); if (rootFolder != null) { using ( rootFolder ) { string parentEntryId = rootFolder.GetBinProp(MAPIConst.PR_PARENT_ENTRYID); if (parentEntryId != null) { IEFolder parentFolder = msgStore.OpenFolder(parentEntryId); if (parentFolder != null) { using ( parentFolder ) { AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_APPOINTMENT_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_CONTACT_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_DRAFTS_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_JOURNAL_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_NOTE_ENTRYID)); AddDefaultFolderEntryID(parentFolder.GetBinProp(MAPIConst.PR_IPM_TASK_ENTRYID)); ArrayList additionalRenEntryIDs = parentFolder.GetBinArray(MAPIConst.PR_ADDITIONAL_REN_ENTRYIDS); if (additionalRenEntryIDs != null && additionalRenEntryIDs.Count > 4) { _junkEmailId = additionalRenEntryIDs[4] as string; } if (additionalRenEntryIDs != null) { foreach (string id in additionalRenEntryIDs) { AddDefaultFolderEntryID(id); } } } } } } } _supportMask = msgStore.GetLongProp(MAPIConst.PR_STORE_SUPPORT_MASK); _resource = Core.ResourceStore.FindUniqueResource(STR.MAPIInfoStore, PROP.EntryID, _entryId); _storeTypeChecked = _resource == null?false:_resource.HasProp(PROP.StoreTypeChecked); if (_resource == null || !_storeTypeChecked) { try { _supported = OutlookSession.IsStorageSupported(msgStore); _storeTypeChecked = true; } catch (COMException exception) { Tracer._TraceException(exception); } } else { _supported = _resource.HasProp(PROP.StoreSupported); } }