Ejemplo n.º 1
0
        protected virtual void ExecuteActionImpl(IResourceList selectedResources)
        {
            Tracer._Trace("Execute action: SyncMail");
            PairIDs selectedFolderIDs = PairIDs.Get(_selectedFolder);

            if (!OutlookSession.FolderExists(selectedFolderIDs))
            {
                return;
            }
            foreach (IResource resMail in selectedResources.ValidResources)
            {
                PairIDs messageIDs = PairIDs.Get(resMail);
                if (messageIDs == null)
                {
                    continue;
                }

                IEMessage message =
                    OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId);
                if (message == null)
                {
                    continue;
                }

                if (selectedFolderIDs.StoreId.Equals(messageIDs.StoreId))
                {
                    DoMoveImpl(message, messageIDs, selectedFolderIDs);
                }
                else
                {
                    DoMoveBetweenStorages(resMail, message, messageIDs, selectedFolderIDs);
                }
            }
        }
Ejemplo n.º 2
0
        private void OnImportanceMailChangedImpl(IResource emailResource)
        {
            if (emailResource != null && emailResource.Type == STR.Email)
            {
                if (Mail.MailInIMAP(emailResource))
                {
                    return;
                }

                int     importance = emailResource.GetIntProp(PROP.Importance);
                PairIDs messageIDs = PairIDs.Get(emailResource);
                if (messageIDs == null)
                {
                    return;
                }
                IEMessage message = OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId);
                if (message != null)
                {
                    using ( message )
                    {
                        message.SetLongProp(MAPIConst.PR_IMPORTANCE, importance + 1);
                        OutlookSession.SaveChanges("Export importance flag for resource id = " + emailResource.Id, message, messageIDs.EntryId);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        //---------------------------------------------------------------------
        //  Iterate over all contacts in the AB represented by parentId, find all
        //  contact resources with corresponding IEMessages not existing in the AB,
        //  and remove them from AB - remove EntryID property AND unlink with AB
        //  resource.
        //---------------------------------------------------------------------
        private void RemoveContactFromSync(string parentId, string storeId)
        {
            IResource AB = Core.ResourceStore.FindUniqueResource("AddressBook", PROP.EntryID, parentId);

            if (AB != null)
            {
                IResourceList contacts = AB.GetLinksOfType("Contact", "InAddressBook");
                foreach (IResource contact in contacts.ValidResources)
                {
                    if (contact.HasProp(PROP.EntryID))
                    {
                        IEMessage contactMsg = OutlookSession.OpenMessage(contact.GetStringProp(PROP.EntryID), storeId);
                        if (contactMsg != null)
                        {
                            //  Item exists in the Outlook folder, the object is not
                            //  needed anymore.
                            contactMsg.Dispose();
                        }
                        else
                        {
                            Contact.RemoveFromSync(contact, true);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private string[] SaveMessages(IResourceList selectedResources)
        {
            ArrayList array = new ArrayList(selectedResources.Count);

            foreach (IResource resource in selectedResources.ValidResources)
            {
                PairIDs   msgId   = PairIDs.Get(resource);
                IEMessage message = OutlookSession.OpenMessage(msgId.EntryId, msgId.StoreId);
                if (message != null)
                {
                    using ( message )
                    {
                        string path = Core.FileResourceManager.GetUniqueTempDirectory();
                        path = Path.Combine(path, resource.GetPropText(Core.Props.Name) + ".msg");
                        message.SaveToMSG(path);
                        array.Add(path);
                    }
                }
            }
            string[] files = new string[array.Count];
            for (int i = 0; i < array.Count; ++i)
            {
                files[i] = array[i] as string;
            }
            return(files);
        }
Ejemplo n.º 5
0
 private static void AddMail(string messageClass, string entryID,
                             FolderDescriptor folderDescriptor, IEFolder mapiFolder, string longBody)
 {
     Guard.NullArgument(messageClass, "messageClass");
     if (MessageType.InterpretAsMail(messageClass))
     {
         IEMessage message = null;
         try
         {
             message = OutlookSession.OpenMessage(mapiFolder, entryID);
         }
         catch (COMException exception)
         {
             if (exception.ErrorCode == MapiError.MAPI_E_SUBMITTED)
             {
                 Core.NetworkAP.QueueJobAt(DateTime.Now.AddSeconds(10),
                                           new DelegateTryAgainToAddMail(TryAgainToAddMail), folderDescriptor, entryID, longBody);
             }
         }
         if (message == null)
         {
             return;
         }
         using ( message )
         {
             Core.ResourceAP.QueueJob(new MailDescriptor(folderDescriptor, entryID, message, longBody));
         }
     }
 }
Ejemplo n.º 6
0
        protected override void ExecuteAction(IResource resource, PairIDs pairIDs)
        {
            Tracer._Trace("Execute action: SaveToMSGAction");
            Trace.WriteLine(">>> SaveToMSGAction.ExecuteAction");
            if (pairIDs != null)
            {
                IEMessage message = OutlookSession.OpenMessage(pairIDs.EntryId, pairIDs.StoreId);
                if (message == null)
                {
                    return;
                }
                using ( message )
                {
                    string fileName = null;
                    if (!_single)
                    {
                        string subject = message.GetStringProp(MAPIConst.PR_SUBJECT);
                        CorrectFileName(ref subject);

                        if (subject == null || subject.Length == 0)
                        {
                            subject = message.GetBinProp(MAPIConst.PR_ENTRYID);
                        }

                        fileName = Path.Combine(_path, subject + ".msg");
                    }
                    else
                    {
                        fileName = _path;
                    }
                    ExecuteActionImpl(message, fileName);
                }
            }
            Trace.WriteLine("<<< SaveToMSGAction.ExecuteAction");
        }
Ejemplo n.º 7
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);
     }
 }
Ejemplo n.º 8
0
        protected override void ExecuteAction(IResource resource, PairIDs pairIDs)
        {
            Tracer._Trace("Execute action: UnDeleteIMAPMessageAction");
            Trace.WriteLine(">>> UnDeleteIMAPMessageAction.ExecuteAction");
            if (pairIDs == null)
            {
                return;
            }

            IResource folder = resource.GetLinkProp(PROP.MAPIFolder);

            if (!Folder.IsIMAPFolder(folder))
            {
                return;
            }
            IEMessage message = OutlookSession.OpenMessage(pairIDs.EntryId, pairIDs.StoreId);

            if (message == null)
            {
                return;
            }
            using ( message )
            {
                int tag = message.GetIDsFromNames(ref GUID.set1, lID.msgDeletedInIMAP, PropType.PT_LONG);
                message.DeleteProp(tag);
                OutlookSession.SaveChanges("Undelete message resource id = " + resource.Id, message, pairIDs.EntryId);
            }
            Trace.WriteLine("<<< UnDeleteIMAPMessageAction.ExecuteAction");
        }
Ejemplo n.º 9
0
 private void QuoteReply(IResource mail)
 {
     try
     {
         if (_mailItem.BodyFormat == OlBodyFormat.olFormatPlain)
         {
         }
     }
     catch (NullReferenceException)
     {
         return;
     }
     if (_mailItem.BodyFormat == OlBodyFormat.olFormatPlain)
     {
         IEMessage message = OutlookSession.OpenMessage(_entryId, _storeId);
         if (message != null)
         {
             string body = message.GetStringProp(MAPIConst.PR_BODY);
             if (body != null)
             {
                 _newMail.Body = new ReplyQuoter(mail).QuoteReply(body);
             }
         }
     }
 }
Ejemplo n.º 10
0
        protected override void Execute()
        {
            if (OutlookSession.OutlookProcessor.ShuttingDown)
            {
                return;
            }

            IEFolder folder = OutlookSession.OpenFolder(_ntf.ParentID, _storeID);

            if (folder != null)
            {
                using ( folder )
                {
                    FolderDescriptor folderDescriptor = FolderDescriptor.Get(folder);
                    if (folderDescriptor == null)
                    {
                        return;
                    }
                    IResource resFolder = Folder.Find(folderDescriptor.FolderIDs.EntryId);
                    if (resFolder == null)
                    {
                        return;
                    }

                    bool ignoredFolder = Folder.IsIgnored(resFolder);

                    IEMessage message = OutlookSession.OpenMessage(_ntf.EntryID, _storeID);
                    if (message == null)
                    {
                        return;
                    }
                    using ( message )
                    {
                        string    entryId = OutlookSession.GetMessageID(message);
                        IResource mail    = Core.ResourceStore.FindUniqueResource("Email", PROP.EntryID, _ntf.EntryID);
                        if (mail == null && _ntf.OldEntryID != null)
                        {
                            mail = Core.ResourceStore.FindUniqueResource("Email", PROP.EntryID, _ntf.OldEntryID);
                        }

                        if (ignoredFolder && mail != null)
                        {
                            Trace.WriteLine("Moved mail ID=" + mail.Id + " to ignored folder");
                            Mail.ForceDelete(mail);
                            return;
                        }
                        if (mail == null)
                        {
                            ProcessMailAddNtf.DoJob(_ntf, _storeID);
                            return;
                        }
                        mail.SetProp(PROP.EntryID, entryId);
                        Folder.LinkMail(resFolder, mail);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        private void OnUnreadItemChangedImpl(IResource emailResource)
        {
            Guard.NullArgument(emailResource, "emailResource");
            if (emailResource.Type != STR.Email)
            {
                return;
            }
            PairIDs messageIDs = PairIDs.Get(emailResource);

            if (messageIDs == null)
            {
                return;
            }

            IResource folder = Mail.GetParentFolder(emailResource);

            if (folder != null && Folder.IsIMAPFolder(folder))
            {
                PairIDs folderIDs = PairIDs.Get(folder);
                if (folderIDs != null)
                {
                    IEFolder mapiFolder = OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId);
                    if (mapiFolder != null)
                    {
                        using ( mapiFolder )
                        {
                            try
                            {
                                mapiFolder.SetReadFlags(messageIDs.EntryId, emailResource.HasProp(Core.Props.IsUnread));
                                return;
                            }
                            catch (COMException exception)
                            {
                                if (exception.ErrorCode == (unchecked ((int)0x80040604)))
                                {
                                    StandartJobs.MessageBox("Unspecified error. Can't change unread flag for email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                                Core.ReportException(exception, ExceptionReportFlags.AttachLog);
                            }
                        }
                    }
                }
            }

            IEMessage message = OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId);

            if (message != null)
            {
                using ( message )
                {
                    bool unread = emailResource.HasProp(Core.Props.IsUnread);
                    message.SetUnRead(unread);
                    OutlookSession.SaveChanges("Export Read/Unread flag" + emailResource.Id, message, messageIDs.EntryId);
                }
            }
        }
Ejemplo n.º 12
0
        public MailDeletedDescriptor(MAPINtf ntf, string storeId)
        {
            Guard.NullArgument(ntf, "ntf");
            Guard.NullArgument(storeId, "storeID");
            IEMessage deletedItem = OutlookSession.OpenMessage(ntf.EntryID, storeId);

            if (deletedItem != null)
            {
                using ( deletedItem )
                {
                    Trace.WriteLine("Successfully opened deleted item resource");
                    string entryId = OutlookSession.GetMessageID(deletedItem);
                    if (String.IsNullOrEmpty(entryId))
                    {
                        throw new ArgumentNullException("entryId", "MailDeletedDescriptor -- NULL entryId string of the existing IEMessage");
                    }

                    FindResourcesByEntryId(entryId);
                }
            }
            else
            {
                FindResourcesByEntryId(ntf.EntryID);
                if (_resourceToDelete != null)
                {
                    return;
                }

                // we've got a short-term entry ID in the notification; we need to scan the parent
                // folder to find the resources which need to be deleted
                IEFolder parentFolder = OutlookSession.OpenFolder(ntf.ParentID, storeId);
                if (parentFolder != null)
                {
                    using ( parentFolder )
                    {
                        string    parentId         = OutlookSession.GetFolderID(parentFolder);
                        IResource parentMAPIFolder = Folder.Find(parentId);
                        if (parentMAPIFolder != null)
                        {
                            if (Folder.IsFolderOfType(parentMAPIFolder, FolderType.Contact))
                            {
                                RemoveContactFromSync(parentId, storeId);
                                return;
                            }

                            //  Deletion from the folder which we ignore anyway
                            //  must not lead to a great performance loss.
                            if (!parentMAPIFolder.HasProp(PROP.IgnoredFolder))
                            {
                                FindResourceToDelete(parentFolder, parentMAPIFolder, storeId);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public MailBodyDescriptor(IResource mail)
        {
            try
            {
                IEMessage message = null;
                if (mail.Type == STR.Email)
                {
                    PairIDs IDs = PairIDs.Get(mail);
                    if (IDs != null)
                    {
                        message = OutlookSession.OpenMessage(IDs.EntryId, IDs.StoreId);
                    }
                    else
                    {
                        message = new OutlookAttachment(mail).OpenEmbeddedMessage();
                    }
                }
                else if (mail.Type == STR.EmailFile)
                {
                    message = OutlookSession.OpenEmailFile(mail);
                }
                if (message != null)
                {
                    using ( message )
                    {
                        _subject = message.GetStringProp(MAPIConst.PR_SUBJECT);
                        MessageBody body = message.GetRawBodyAsRTF();

                        if (body.Format == MailBodyFormat.PlainTextInRTF || body.Format == MailBodyFormat.RTF)
                        {
                            _body = _rtfParser.Parse(body.text);
                        }
                        else
                        {
                            _body = body.text;
                        }

                        _isHTML = (body.Format == EMAPILib.MailBodyFormat.HTML);
                    }
                }
            }
            catch (Exception exception)
            {
                Tracer._TraceException(exception);
            }
            if (_subject == null)
            {
                _subject = string.Empty;
            }
            if (_body == null)
            {
                _body = string.Empty;
            }
        }
Ejemplo n.º 14
0
        private IEMessage OpenMessage(ref bool wasChanges)
        {
            if (_createNew && _OMTaskId == null)
            {
                return(null);
            }

            wasChanges = false;
            IEMessage message = null;

            if (!_createNew)
            {
                PairIDs IDs = PairIDs.Get(_task);
                if (IDs == null)
                {
                    if (_task.HasProp(PROP.EntryID))
                    {
                        IEFolder taskFolder = OutlookSession.OpenDefaultTaskFolder();
                        if (taskFolder == null)
                        {
                            return(null);
                        }

                        using ( taskFolder )
                        {
                            IDs = new PairIDs(_task.GetStringProp(PROP.EntryID), taskFolder.GetBinProp(MAPIConst.PR_STORE_ENTRYID));
                        }
                    }
                    if (IDs == null)
                    {
                        return(null);
                    }
                }

                message = OutlookSession.OpenMessage(IDs.EntryId, IDs.StoreId);
            }
            if (message == null)
            {
                IEFolder taskFolder = OutlookSession.OpenDefaultTaskFolder();
                if (taskFolder == null)
                {
                    return(null);
                }
                wasChanges = true;

                using ( taskFolder )
                {
                    message  = taskFolder.CreateMessage("IPM.Task");
                    _created = true;
                }
            }
            return(message);
        }
Ejemplo n.º 15
0
            private MessageBody ReadBody()
            {
                if (_mail.HasProp(PROP.EmbeddedMessage))
                {
                    OutlookAttachment  attach  = new OutlookAttachment(_mail);
                    EMAPILib.IEMessage message = attach.OpenEmbeddedMessage();
                    if (message != null)
                    {
                        using ( message )
                        {
                            return(message.GetRawBodyAsRTF());
                        }
                    }
                    return(null);
                }
                if (_mail.Type == STR.EmailFile)
                {
                    IEMessage message = OutlookSession.OpenEmailFile(_mail);
                    if (message != null)
                    {
                        using ( message )
                        {
                            _subject = message.GetStringProp(MAPIConst.PR_SUBJECT);
                            return(message.GetRawBodyAsRTF());
                        }
                    }
                    return(null);
                }

                PairIDs IDs = PairIDs.Get(_mail);

                if (IDs != null)
                {
                    EMAPILib.IEMessage message = OutlookSession.OpenMessage(IDs.EntryId, IDs.StoreId);
                    if (message != null)
                    {
                        using ( message )
                        {
                            return(OutlookSession.GetMessageBody(message));
                        }
                    }
                    else
                    {
                        string bodyText = "Could not open message. It may have been moved or deleted in Outlook. Or message store for this mail cannot be open.";
                        return(new MessageBody(bodyText, MailBodyFormat.PlainText, 0));
                    }
                }
                return(null);
            }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
0
        public static void DoJob(MAPINtf ntf, string storeID)
        {
            if (ntf == null)
            {
                return;
            }

            try
            {
                IEFolder folder = OutlookSession.OpenFolder(ntf.ParentID, storeID);
                if (folder == null)
                {
                    return;
                }
                FolderDescriptor folderDescriptor = FolderDescriptor.Get(folder);
                if (folderDescriptor == null)
                {
                    return;
                }
                using ( folder )
                {
                    if (folderDescriptor.ContainerClass == FolderType.IMAP)
                    {
                        if (!ProcessIMAPMessage(folder, ntf.EntryID))
                        {
                            return;
                        }
                    }
                    IEMessage message = OutlookSession.OpenMessage(ntf.EntryID, storeID);
                    if (message == null)
                    {
                        return;
                    }
                    using ( message )
                    {
                        DoJobImpl(ntf, message, folderDescriptor);
                    }
                }
            }
            catch (System.Threading.ThreadAbortException exception)
            {
                Tracer._TraceException(exception);
            }
            catch (Exception exception)
            {
                Core.ReportException(exception, ExceptionReportFlags.AttachLog);
            }
        }
Ejemplo n.º 18
0
        public IEMessage OpenMessage()
        {
            IResource mail = Core.ResourceStore.LoadResource(_sourceMailID);

            if (mail == null)
            {
                return(null);
            }
            PairIDs messageIDs = PairIDs.Get(mail);

            if (messageIDs == null)
            {
                return(null);
            }
            return(OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId));
        }
Ejemplo n.º 19
0
        protected override void Execute()
        {
            IEMessage message = OutlookSession.OpenMessage(_entryId, _storeId);

            if (message == null)
            {
                return;
            }
            using ( message )
            {
                if (ProcessCategories(message, _mail))
                {
                    OutlookSession.SaveChanges("Export categoryies for resource id = " + _mail.Id, message, _entryId);
                }
            }
        }
Ejemplo n.º 20
0
        protected override void Execute()
        {
            IEMessage message = OutlookSession.OpenMessage(_messageIDs.EntryId, _messageIDs.StoreId);

            if (message == null)
            {
                return;
            }
            using ( message )
            {
                int flagStatus = 0;
                int flagColor  = 0;
                GetCurrentFlag(message, out flagStatus, out flagColor);
                ExportFlag(message, flagStatus, flagColor);
            }
        }
Ejemplo n.º 21
0
        private static void ExportAnnotationImpl(IResource emailResource)
        {
            Guard.NullArgument(emailResource, "emailResource");
            if (emailResource.Type != STR.Email)
            {
                throw new ArgumentException("Expected 'Email' resource but was " + emailResource.Type);
            }
            if (Mail.MailInIMAP(emailResource))
            {
                return;
            }

            PairIDs messageIDs = PairIDs.Get(emailResource);

            if (messageIDs == null)
            {
                return;
            }
            IEMessage message = OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId);

            if (message == null)
            {
                return;
            }
            using ( message )
            {
                string annotation    = emailResource.GetPropText(Core.Props.Annotation);
                int    tag           = message.GetIDsFromNames(ref GUID.set1, lID.msgFlagAnnotation, PropType.PT_STRING8);
                string oldAnnotation = message.GetStringProp(tag);
                if (oldAnnotation == null)
                {
                    oldAnnotation = string.Empty;
                }
                if (!oldAnnotation.Equals(annotation))
                {
                    if (annotation.Length == 0)
                    {
                        message.DeleteProp(tag);
                    }
                    else
                    {
                        message.SetStringProp(tag, annotation);
                    }
                    OutlookSession.SaveChanges("ExportAnnotation for resource id = " + emailResource.Id, message, messageIDs.EntryId);
                }
            }
        }
Ejemplo n.º 22
0
 protected override void Execute()
 {
     if (IsDataCorrect(_folder))
     {
         PairIDs   folderIDs = _folder.FolderIDs;
         IEMessage message   = OutlookSession.OpenMessage(_entryID, folderIDs.StoreId);
         if (message == null)
         {
             return;
         }
         using ( message )
         {
             OutlookAddressBook AB = new OutlookAddressBook(_folder.Name, _folder.FolderIDs, true);
             ContactDescriptor  contactDescriptor =
                 new ContactDescriptor(message, _entryID, _searchEntryID, AB);
             Core.ResourceAP.QueueJob(contactDescriptor);
         }
     }
 }
Ejemplo n.º 23
0
 private void OnMailModifyImpl(MAPIFullNtf ntf)
 {
     if (CheckStorageIgnored(_storeID))
     {
         return;
     }
     try
     {
         IEFolder folder = OutlookSession.OpenFolder(ntf.ParentID, _storeID);
         if (folder == null)
         {
             return;
         }
         using ( folder )
         {
             FolderDescriptor folderDescriptor = FolderDescriptor.Get(folder);
             if (folderDescriptor.ContainerClass == FolderType.IMAP)
             {
                 if (!ProcessMailAddNtf.ProcessIMAPMessage(folder, ntf.EntryID))
                 {
                     return;
                 }
             }
             IEMessage message = OutlookSession.OpenMessage(ntf.EntryID, _storeID);
             if (message == null)
             {
                 return;
             }
             using ( message )
             {
                 ProcessMailModifyImpl(ntf, message, folderDescriptor);
             }
         }
     }
     catch (System.Threading.ThreadAbortException ex)
     {
         Tracer._TraceException(ex);
     }
     catch (Exception exception)
     {
         Core.ReportBackgroundException(exception);
     }
 }
Ejemplo n.º 24
0
        private static void TryAgainToAddMail(FolderDescriptor folderDescriptor, string entryID, string longBody)
        {
            IEMessage message = null;

            try
            {
                message = OutlookSession.OpenMessage(entryID, folderDescriptor.FolderIDs.StoreId);
            }
            catch (COMException exception)
            {
                if (exception.ErrorCode == MapiError.MAPI_E_SUBMITTED)
                {
                    Core.NetworkAP.QueueJobAt(DateTime.Now.AddMinutes(1),
                                              new DelegateTryAgainToAddMail(TryAgainToAddMail), folderDescriptor, entryID, longBody);
                }
            }
            using ( message )
            {
                Core.ResourceAP.QueueJob(new MailDescriptor(folderDescriptor, entryID, message, longBody));
            }
        }
Ejemplo n.º 25
0
        public static bool DeleteMessage(string storeId, string entryId, bool DeletedItems)
        {
            if (!DeletedItems)
            {
                OutlookSession.DeleteMessageImpl(storeId, entryId, false);
                return(true);
            }

            PairIDs folderIds = OutlookSession.GetDeletedItemsFolderIDs(storeId);

            if (folderIds == null)
            {
                OutlookSession.DeleteMessageImpl(storeId, entryId, false);
                return(true);
            }

            string    folderID = null;
            IEMessage message  = OutlookSession.OpenMessage(entryId, storeId);

            if (message == null)
            {
                return(false);
            }
            using ( message )
            {
                folderID = message.GetBinProp(MAPIConst.PR_PARENT_ENTRYID);
            }
            if (folderID != null)
            {
                if (folderID != folderIds.EntryId)
                {
                    if (MoveMessage(storeId, entryId, folderID, folderIds))
                    {
                        return(true);
                    }
                }
            }
            OutlookSession.DeleteMessageImpl(storeId, entryId, false);
            return(true);
        }
Ejemplo n.º 26
0
        private void FindResourceToDelete(IEFolder parentFolder, IResource parentMAPIFolder, string storeId)
        {
            // NOTE: In Cached Exchange mode (at least), messages can be opened successfully
            // immediately after they are permanently deleted, but opening them through
            // the short-term entry ID that we got in the notification still does not work.
            // Thus, if the message was permanently deleted in Outlook, the code below will
            // not find the deleted message, and we will have to rely on background enumeration
            // to delete it.
            // When the message is permanently deleted in OmniaMea, we immediately delete
            // the resource as well.
            IResourceList children = parentMAPIFolder.GetLinksOfType(null, PROP.MAPIFolder);

            foreach (IResource child in children.ValidResources)
            {
                if (child.HasProp(PROP.EntryID))
                {
                    IEMessage deletedItem = OutlookSession.OpenMessage(child.GetStringProp(PROP.EntryID), storeId);
                    if (deletedItem != null)
                    {
                        //  Item exists in the folder, the object is not needed anymore
                        deletedItem.Dispose();
                    }
                    else
                    {
                        Trace.WriteLine("Failed to open resource with ID=" + child.Id + ", queueing for delete");
                        _resourceToDelete = child;
                        break;
                    }
                }
            }
            if (_resourceToDelete == null)
            {
                HashSet set = new HashSet(children.Count);
                Tracer._Trace("Cannot find deleted mail.");
                Tracer._Trace("Try another algorithm.");
                foreach (IResource child in children.ValidResources)
                {
                    if (!child.HasProp(PROP.EntryID))
                    {
                        continue;
                    }
                    set.Add(child.GetStringProp(PROP.EntryID));
                }

                IEMessages messages = parentFolder.GetMessages();
                if (messages != null)
                {
                    using ( messages )
                    {
                        for (int i = 0; i < messages.GetCount(); i++)
                        {
                            IEMessage message = messages.OpenMessage(i);
                            if (message != null)
                            {
                                using ( message )
                                {
                                    string entryid = message.GetBinProp(MAPIConst.PR_ENTRYID);
                                    if (entryid != null)
                                    {
                                        set.Remove(entryid);
                                    }
                                }
                            }
                        }
                    }
                }
                if (set.Count > 0)
                {
                    foreach (HashSet.Entry entry in set)
                    {
                        FindResourcesByEntryId((string)entry.Key);
                        if (_resourceToDelete != null)
                        {
                            Tracer._Trace("Resource found for deleting.");
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 27
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();
        }
Ejemplo n.º 28
0
        private void OnNewMailImpl(MAPINtf ntf)
        {
            Trace("[New] *Email* - OnNewMailImpl");
            if (CheckStorageIgnored(_storeID))
            {
                Trace("OnNewMailImpl: storage is ignored");
                return;
            }
            FolderDescriptor folderDescriptor = FolderDescriptor.Get(ntf.ParentID, _storeID);

            if (folderDescriptor == null)
            {
                Trace("OnNewMailImpl: folderDescriptor == null");
                return;
            }

            if (folderDescriptor.ContainerClass == FolderType.IMAP)
            {
                IEFolder folder = OutlookSession.OpenFolder(ntf.ParentID, _storeID);
                if (folder == null)
                {
                    return;
                }
                using ( folder )
                {
                    if (!ProcessMailAddNtf.ProcessIMAPMessage(folder, ntf.EntryID))
                    {
                        return;
                    }
                }
            }

            IEMessage message = OutlookSession.OpenMessage(ntf.EntryID, _storeID);

            if (message == null)
            {
                Trace("OnNewMailImpl: cannot open mapi message");
                return;
            }
            using ( message )
            {
                try
                {
                    string entryId = OutlookSession.GetMessageID(message);
                    if (OutlookSession.IsMailExported(entryId))
                    {
                        Trace("OnNewMailImpl: mail is exported at the moment");
                        return;
                    }
                    new NewMailDescriptor(folderDescriptor, entryId, message).QueueJob(JobPriority.AboveNormal);
                }
                catch (System.Threading.ThreadAbortException ex)
                {
                    Tracer._TraceException(ex);
                }
                catch (Exception exception)
                {
                    Core.ReportBackgroundException(exception);
                }
            }
        }
Ejemplo n.º 29
0
        private void OnMailMoveImpl(MAPIFullNtf ntf)
        {
            if (CheckStorageIgnored(_storeID))
            {
                return;
            }
            FolderDescriptor folderDescriptor = FolderDescriptor.Get(ntf.ParentID, _storeID);

            if (folderDescriptor == null)
            {
                return;
            }

            try
            {
                IEMessage message = OutlookSession.OpenMessage(ntf.EntryID, _storeID);
                if (message == null)
                {
                    return;
                }
                using ( message )
                {
                    string realID = message.GetBinProp(MAPIConst.PR_ENTRYID);
                    if (realID == null)
                    {
                        realID = ntf.EntryID;
                    }
                    else
                    {
                        if (OutlookSession.IsMailExported(realID))
                        {
                            return;
                        }
                    }
                    string messageClass = MessageType.GetMessageClass(message);
                    if (MessageType.InterpretAsMail(messageClass))
                    {
                        Core.ResourceAP.QueueJob(JobPriority.AboveNormal, new MailMovedDescriptor(ntf, _storeID));
                    }
                    else
                    if (MessageType.InterpretAsContact(messageClass))
                    {
                        if (folderDescriptor.ContainerClass != FolderType.Contact)
                        {
                            _tracer.Trace("Contact was moved to deleted items");
                            IResource contact = Core.ResourceStore.FindUniqueResource(STR.Contact, PROP.EntryID, realID);
                            string    entryID = realID;
                            if (contact == null && ntf.OldEntryID != null)
                            {
                                _tracer.Trace("contact not found");
                                contact = Core.ResourceStore.FindUniqueResource(STR.Contact, PROP.EntryID, ntf.OldEntryID);
                                entryID = ntf.EntryID;
                            }
                            if (contact != null)
                            {
                                _tracer.Trace("contact found");
                                _tracer.Trace("RemoveFromSync");
                                Contact.RemoveFromSync(contact, entryID);
                            }
                            else
                            {
                                _tracer.Trace("ClearInvalidEntryIDFromContacts");
                                _jobStrategy.QueueJob(new MethodInvoker(REGISTRY.ClearInvalidEntryIDFromContacts));
                            }
                        }
                        else
                        {
                            string searchEntryID = realID;
                            if (realID != ntf.OldEntryID)
                            {
                                searchEntryID = ntf.OldEntryID;
                            }

                            _tracer.Trace("ContactDescriptorWrapper process moving");
                            ContactDescriptorWrapper.Do(_jobStrategy.JobPriority, folderDescriptor, realID, searchEntryID);
                        }
                        //OutlookSession.OutlookProcessor.QueueJob( new ContactDescriptorWrapper( folderDescriptor, ntf.EntryID ) );
                    }
                    else if (MessageType.InterpretAsTask(messageClass))
                    {
                        _tracer.Trace("Task was moved");
                        if (Core.ResourceStore.FindUniqueResource(STR.Task, PROP.EntryID, realID) != null)
                        {
                            TaskDescriptor.Do(JobPriority.AboveNormal, folderDescriptor, message, realID);
                        }
                        else
                        {
                            RefreshTaskFolder(folderDescriptor);
                            FolderDescriptor oldFolderDescriptor = FolderDescriptor.Get(ntf.OldParentID, _storeID);
                            if (oldFolderDescriptor != null)
                            {
                                RefreshTaskFolder(oldFolderDescriptor);
                            }
                        }
                    }
                    else
                    {
                        _tracer.Trace("Unknown item of class " + messageClass + " was moved");
                    }
                }
            }
            catch (System.Threading.ThreadAbortException ex)
            {
                Tracer._TraceException(ex);
            }
            catch (Exception exception)
            {
                Core.ReportBackgroundException(exception);
            }
        }