예제 #1
0
        private void SynchronizeOutlookAddressBooksImpl()
        {
            _tracer.Trace("Start SynchronizeOutlookAddressBooksImpl");

            IEAddrBook addrBook = OutlookSession.GetAddrBook();

            if (addrBook != null)
            {
                int count = addrBook.GetCount();
                for (int i = 0; i < count; i++)
                {
                    if (ShuttingDown)
                    {
                        return;
                    }
                    OutlookSession.ProcessJobs();
                    IEABContainer abCont = addrBook.OpenAB(i);
                    if (abCont == null)
                    {
                        continue;
                    }
                    using ( abCont )
                    {
                        int displayType = abCont.GetLongProp(MAPIConst.PR_DISPLAY_TYPE);
                        if (displayType != ABType.DT_GLOBAL)
                        {
                            continue;
                        }
                        string entryID = abCont.GetBinProp(MAPIConst.PR_ENTRYID);
                        Core.ResourceAP.RunJob(new OutlookABDescriptor(abCont.GetStringProp(MAPIConst.PR_DISPLAY_NAME), entryID));
                    }
                }
            }
            _tracer.Trace("Start SynchronizeOutlookAddressBooksImpl");
        }
예제 #2
0
        private ArrayList GetEmailAddresses(/*string entryId*/)
        {
            IEAddrBook ab       = OutlookSession.GetAddrBook();
            IEMailUser mailUser = ab.OpenMailUser(_entryID);

            if (mailUser != null)
            {
                using ( mailUser )
                {
                    ArrayList addresses = mailUser.GetStringArray(MAPIConst.PR_EMS_AB_PROXY_ADDRESSES);
                    if (addresses != null && addresses.Count > 0)
                    {
                        ArrayList emailAddresses = new ArrayList(addresses.Count);
                        foreach (string str in addresses)
                        {
                            string newAddress = ExtractAddress(str);
                            if (newAddress != null)
                            {
                                emailAddresses.Add(newAddress);
                            }
                        }
                        return(emailAddresses);
                    }
                }
            }
            return(null);
        }
예제 #3
0
 internal static IEMAPIProp OpenMessage(IEFolder folder, IResource contact,
                                        bool create, bool forceCreate, bool trace,
                                        out bool newCreated, out bool createdAsMailUser)
 {
     createdAsMailUser = false;
     newCreated        = false;
     using ( folder )
     {
         IEMAPIProp message = null;
         if (!create)
         {
             string mesEntryId = contact.GetPropText(PROP.EntryID);
             if (mesEntryId.Length > 0)
             {
                 message = OutlookSession.OpenMessage(folder, mesEntryId);
                 if (message == null)
                 {
                     Contact.RemoveFromSync(contact, true);
                 }
             }
             if (!forceCreate)
             {
                 return(message);
             }
         }
         if (message == null)
         {
             string folderId = folder.GetBinProp(MAPIConst.PR_ENTRYID);
             _tracer.Trace(folderId);
             IEAddrBook ab = OutlookSession.GetAddrBook();
             if (ab != null)
             {
                 for (int i = 0; i < ab.GetCount(); ++i)
                 {
                     string abEntryId = ab.FindBinProp(i, MAPIConst.PR_ENTRYID_ASSOCIATED_WITH_AB);
                     if (abEntryId == folderId)
                     {
                         IEABContainer abContainer = ab.OpenAB(i);
                         if (abContainer != null)
                         {
                             using ( abContainer )
                             {
                                 message = abContainer.CreateMailUser( );
                                 if (message != null)
                                 {
                                     createdAsMailUser = true;
                                     return(message);
                                 }
                             }
                         }
                         break;
                     }
                 }
             }
             message    = folder.CreateMessage("IPM.Contact");
             newCreated = true;
         }
         return(message);
     }
 }
예제 #4
0
        [Test] public void OpenAddressBookTest()
        {
            IEAddrBook addrBook = OutlookSession.GetAddrBook();

            Assert.IsNotNull(addrBook);
            int count = addrBook.GetCount();

            for (int i = 0; i < count; ++i)
            {
                IEABContainer ab = addrBook.OpenAB(i);
                Assert.IsNotNull(ab);
                using ( ab )
                {
                }
            }
        }
예제 #5
0
        private void SynchronizeContactsImpl()
        {
            _tracer.Trace("Start SynchronizeContactsImpl");

            Settings.UpdateProgress(0, "Computing Address Books count...", "");
            int totalABs     = Folder.GetFolders(FolderType.Contact).Count;
            int processedABs = 0;

            IEAddrBook addrBook = OutlookSession.GetAddrBook();

            if (addrBook != null)
            {
                int count = addrBook.GetCount();
                totalABs += count;
                for (int i = 0; i < count; ++i)
                {
                    if (ShuttingDown)
                    {
                        return;
                    }
                    OutlookSession.ProcessJobs();
                    ++processedABs;
                    int percentage = (processedABs * 100) / totalABs;
                    Settings.UpdateProgress(percentage, "Synchronizing Address Books", processedABs.ToString());
                    IEABContainer abContainer = addrBook.OpenAB(i);
                    if (abContainer == null)
                    {
                        continue;
                    }
                    using ( abContainer )
                    {
                        ProcessGlobalAddressBook(abContainer);
                    }
                }
            }
            ProcessContactFolders(processedABs, totalABs);
            _tracer.Trace("Finish SynchronizeContactsImpl");

            Settings.UpdateProgress(100, "Synchronizing Address Books", totalABs.ToString());
        }
예제 #6
0
        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");
            }
        }