Ejemplo n.º 1
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);
                }
            }
        }