private string ProcessRow(IERowSet row, FolderDescriptor folder, IEFolder mapiFolder, ref int indexed) { string entryID = row.GetBinProp(1); if (entryID == null) { entryID = row.GetBinProp(0); } string messageClass = row.GetStringProp(3); if (messageClass == null) { messageClass = string.Empty; } IResource email = Core.ResourceStore.FindUniqueResource(STR.Email, PROP.EntryID, entryID); if (email != null) { _mailsInOldIndex.TestID(email.Id); UpdateMail(row, email, messageClass, entryID, folder, mapiFolder); indexed++; } else { AddMail(messageClass, entryID, folder, mapiFolder, row.GetStringProp(7)); indexed++; } OutlookSession.ProcessJobs(); return(entryID); }
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"); }
private void EnumerateInternal(IEFolder folder, FolderDescriptor parentTag) { IEFolders folders = OutlookSession.GetFolders(folder); if (folders == null) { return; } using ( folders ) { for (int i = 0; i < folders.GetCount(); ++i) { OutlookSession.ProcessJobs(); IEFolder subFolder = OutlookSession.OpenFolder(folders, i); if (subFolder == null) { continue; } using ( subFolder ) { FolderDescriptor tag = null; FolderDescriptor folderDescriptor = FolderDescriptor.Get(_storeID, subFolder); bool continueEnumerate = _enumListener.FolderFetched(parentTag, folderDescriptor, out tag); if (continueEnumerate) { EnumerateInternal(subFolder, tag); } } } } }
protected override void Execute() { IResource resFolder; if (!IsDataCorrect(out resFolder, _folder)) { return; } IStatusWriter statusWriter = Core.UIManager.GetStatusWriter(this, StatusPane.Network); statusWriter.ShowStatus("Synchronizing folder " + _folder.Name + "..."); OutlookSession.ProcessJobs(); try { MailSync mailSync = new MailSync(false, _dateRestriction); mailSync.AddMailResources(Folder.GetMessageList(resFolder)); mailSync.EnumerateMessageItems(_folder); mailSync.RemoveDeletedMailsFromIndex(); } finally { statusWriter.ClearStatus(); } }
private void ProcessContactFolder(PairIDs folderIDs, string abName) { IEFolder folder = null; try { folder = OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId); } catch (System.Threading.ThreadAbortException) { } catch (Exception exception) { if (exception is COMException && ((COMException)exception).ErrorCode != (unchecked ((int)0x80040111))) //ClassFactory cannot supply requested class { return; } Core.ReportException(exception, ExceptionReportFlags.AttachLog); return; } if (folder == null) { return; } using ( folder ) { OutlookAddressBook AB = new OutlookAddressBook(abName, folderIDs, true); AB.RunAB(); IEMessages messages = folder.GetMessages(); if (messages == null) { return; } using ( messages ) { int mesCount = messages.GetCount(); for (int i = 0; i < mesCount; i++) { if (ShuttingDown) { break; } OutlookSession.ProcessJobs(); IEMessage message = messages.OpenMessage(i); if (message == null) { continue; } using ( message ) { string mesEntryID = OutlookSession.GetMessageID(message); Core.ResourceAP.QueueJob(new ContactDescriptor(message, mesEntryID, mesEntryID, AB)); } } } } }
private void ProcessGlobalAddressBook(IEABContainer abContainer) { IERowSet rowSet = abContainer.GetRowSet(); if (rowSet == null) { return; } using ( rowSet ) { string entryID = abContainer.GetBinProp(MAPIConst.PR_ENTRYID); IResource outlookAB = Core.ResourceStore.FindUniqueResource(STR.OutlookABDescriptor, PROP.EntryID, entryID); if (outlookAB == null) { return; } if (!Folder.IsIgnoreImport(outlookAB)) { string curName = abContainer.GetStringProp(MAPIConst.PR_DISPLAY_NAME); string abName = OutlookAddressBook.GetProposedName(curName, entryID); OutlookAddressBook AB = new OutlookAddressBook(abName, entryID, false); AB.RunAB(); int count = rowSet.GetRowCount(); for (int i = 0; i < count; i++) { if (ShuttingDown) { return; } OutlookSession.ProcessJobs(); string ABentryID = rowSet.GetBinProp(0, i /*MAPIConst.PR_ENTRYID*/); if (ABentryID == null) { continue; } Core.ResourceAP.QueueJob(new ContactDescriptor(rowSet, i, ABentryID, AB)); } } else { IResource AB = Core.ResourceStore.FindUniqueResource(STR.AddressBook, PROP.EntryID, entryID); if (AB != null) { new ResourceProxy(AB).DeleteAsync(); } } } }
private void ProcessContactFolders(int processedABs, int totalABs) { ArrayList toDeleteFolders = new ArrayList(); foreach (IResource contactFolder in Folder.GetFolders(FolderType.Contact).ValidResources) { if (ShuttingDown) { break; } OutlookSession.ProcessJobs(); processedABs++; int percentage = (processedABs * 100) / totalABs; Settings.UpdateProgress(percentage, "Indexing Address Books", processedABs.ToString()); PairIDs folderIDs = PairIDs.Get(contactFolder); if (folderIDs == null) { toDeleteFolders.Add(contactFolder); continue; } string abName = OutlookAddressBook.GetProposedName(contactFolder.GetPropText(Core.Props.Name), folderIDs.EntryId); Core.ResourceAP.QueueJob(new OutlookAddressBookReName(folderIDs.EntryId, abName)); if (!Folder.IsIgnoreImport(contactFolder)) { ProcessContactFolder(folderIDs, abName); } else { IResource AB = Core.ResourceStore.FindUniqueResource(STR.AddressBook, PROP.EntryID, folderIDs.EntryId); if (AB != null) { new ResourceProxy(AB).DeleteAsync(); } } } foreach (IResource contactFolder in toDeleteFolders) // delete corrupted 'MAPIFolder' resources { new ResourceProxy(contactFolder).DeleteAsync(); } }
public void Enumerate() { IEFolder folder = _msgStore.GetRootFolder(); if (folder != null) { using ( folder ) { FolderDescriptor tag = null; FolderDescriptor folderDescriptor = FolderDescriptor.Get(_storeID, folder); folderDescriptor.Name = _storeName; bool continueEnumerate = _enumListener.FolderFetched(null, folderDescriptor, out tag); if (continueEnumerate) { OutlookSession.ProcessJobs(); EnumerateInternal(folder, tag); } } } }
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()); }
protected override void Execute() { if (OutlookSession.OutlookProcessor.ShuttingDown) { return; } IStatusWriter statusWriter = Core.UIManager.GetStatusWriter(this, StatusPane.Network); statusWriter.ShowStatus("Performing background mail synchronization..."); Tracer._Trace("MailSyncBackground is executed"); foreach (IEMsgStore msgStore in OutlookSession.GetMsgStores()) { if (OutlookSession.OutlookProcessor.ShuttingDown) { break; } OutlookSession.ProcessJobs(); if (msgStore == null) { continue; } if (OutlookProcessor.IsIgnoredInfoStore(msgStore)) { continue; } string storeID = msgStore.GetBinProp(MAPIConst.PR_STORE_ENTRYID); string name = msgStore.GetStringProp(MAPIConst.PR_DISPLAY_NAME); FolderDescriptorEnumerator.Do(msgStore, storeID, name, this); } statusWriter.ClearStatus(); ProcessedFolders.DecRef(); }
private void EnumerateMail(FolderDescriptor folder, IEFolder mapiFolder) { try { OnFolderFetched(folder.Name); int indexed = 0; IResource resFolder = Folder.Find(folder.FolderIDs.EntryId); DateTime dtRestrict = GetRestrictDate(resFolder); IETable table = null; try { table = mapiFolder.GetEnumTable(dtRestrict); } catch (System.UnauthorizedAccessException exception) { _tracer.TraceException(exception); } catch (OutOfMemoryException exception) { _tracer.TraceException(exception); } if (table == null) { return; } using ( table ) { int count = table.GetRowCount(); if (count > 0) { table.Sort(MAPIConst.PR_MESSAGE_DELIVERY_TIME, false); } for (uint i = 0; i < count; i++) { if (OutlookSession.OutlookProcessor.ShuttingDown) { break; } if (_idle && Settings.IdleModeManager.CheckInterruptIdle()) { break; } IERowSet row = row = table.GetNextRow(); if (row == null) { continue; } using ( row ) { if (row.GetLongProp(6) != 1) { ProcessRow(row, folder, mapiFolder, ref indexed); } } } } if (Settings.IdleModeManager.CompletedIdle) { Folder.SetSeeAllAsync(resFolder); } _tracer.Trace("Indexed " + indexed + " messages in folder " + folder.Name); } finally { OutlookSession.ProcessJobs(); } }
public void RemoveDeletedMailsFromIndex() { try { int count = 0; MailInIndexEnum mailEnum = _mailsInOldIndex.GetEnumerator(); int total = mailEnum.Count; // _tracer.Trace( "Start RemoveDeletedMailsFromIndex" ); // _tracer.Trace( "RemoveDeletedMailsFromIndex : mail to remove " + total.ToString() ); int curTickCount = Environment.TickCount; for (int i = 0; i < total; i++) { OutlookSession.ProcessJobs(); if (OutlookSession.OutlookProcessor.ShuttingDown) { break; } if (_idle && Settings.IdleModeManager.CheckInterruptIdle()) { break; } int percentage = (total == 0) ? 100 : ++count * 100 / total; if (percentage > 100) { percentage = 100; } if (Environment.TickCount - curTickCount > 500) { string statusText = "Synchronizing mails(" + count + "/" + total + ")..."; Settings.UpdateProgress(percentage, statusText, string.Empty); curTickCount = Environment.TickCount; } IResource resMail = mailEnum.GetResource(i); if (resMail == null || !Guard.IsResourceLive(resMail)) { // _tracer.Trace( "RemoveDeletedMailsFromIndex : resMail == null" ); continue; } PairIDs messageIDs = PairIDs.Get(resMail); if (messageIDs == null) { if (!resMail.HasProp(PROP.EmbeddedMessage)) { new ResourceProxy(resMail).DeleteAsync(); } continue; } string storeID = messageIDs.StoreId; string folderID = null; IEMessage mapiMessage = OutlookSession.OpenMessage(messageIDs.EntryId, storeID); if (mapiMessage != null) { using ( mapiMessage ) { folderID = mapiMessage.GetBinProp(MAPIConst.PR_PARENT_ENTRYID); } } FolderDescriptor folder = null; if (folderID != null) { folder = FolderDescriptor.Get(folderID, storeID); } MailSyncToFolder.LinkOrDelete(folder, resMail); OutlookSession.ProcessJobs(); } } finally { _mailsInOldIndex.Clear(); } OutlookSession.ProcessJobs(); }
private void DoSynchronize() { OutlookSession.ProcessJobs(); OutlookSession.OutlookProcessor.RunSynchronizeFolderAndAddressBooks(); DialogResult = DialogResult.OK; }