public static IEMessage OpenEmailFile(IResource resource) { string strName = resource.GetStringProp("Name"); if (strName != null && strName.Length > 0) { string path = Path.Combine(resource.GetStringProp("Directory"), strName); return(EMAPISession.LoadFromMSG(path)); } 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; }
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"); } }