Example #1
0
        private void UpdateMail(IERowSet row, IResource email, string messageClass, string entryId,
                                FolderDescriptor folder, IEFolder mapiFolder)
        {
            Guard.NullArgument(messageClass, "messageClass");

            bool checkForDateTimeNeeded = false;
            bool bWereChanges           = false;
            bool interpretAsMail        = MessageType.InterpretAsMail(messageClass);

            if (interpretAsMail)
            {
                bWereChanges = WereChanges(row, email, out checkForDateTimeNeeded);
            }

            if (bWereChanges)
            {
                IEMessage message = OutlookSession.OpenMessage(folder.FolderIDs.EntryId, mapiFolder, entryId);
                if (message == null)
                {
                    return;
                }

                using ( message )
                {
                    if (checkForDateTimeNeeded)
                    {
                        DateTime lastModifiedDate = message.GetDateTimeProp(MAPIConst.PR_LAST_MODIFICATION_TIME);
                        lastModifiedDate = lastModifiedDate.ToUniversalTime();
                        if (lastModifiedDate.Equals(email.GetProp(PROP.LastModifiedTime)))
                        {
                            bWereChanges = false;
                        }
                    }
                    if (bWereChanges)
                    {
                        Core.ResourceAP.QueueJob(new MailDescriptor(folder, entryId, message, MailDescriptor.UpdateState, row.GetStringProp(7)));
                    }
                    else
                    {
                        Core.ResourceAP.QueueJob(new SyncOnlyMailDescriptor(folder, entryId, message));
                    }
                }
            }
            else
            {
                MailSyncToFolder.LinkOrDelete(folder, email);
            }
        }
Example #2
0
        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();
        }