示例#1
0
        private static void ExecuteAction(IResource resFolder, string name)
        {
            Trace.WriteLine(">>> RenameFolderAction.ExecuteAction");
            PairIDs pairIDs = PairIDs.Get(resFolder);

            if (pairIDs == null)
            {
                return;
            }

            IEFolder folder = OutlookSession.OpenFolder(pairIDs.EntryId, pairIDs.StoreId);

            if (folder == null)
            {
                MsgBox.Error("Outlook plugin", "Cannot rename folder: it was not found in Outlook storage");
                return;
            }
            using ( folder )
            {
                folder.SetStringProp(MAPIConst.PR_DISPLAY_NAME, name);
                folder.SaveChanges();
            }

            Trace.WriteLine("<<< RenameFolderAction.ExecuteAction");
        }
示例#2
0
        internal static void Detect()
        {
            if (!Settings.DetectOwnerEmail)
            {
                return;
            }
            IEMsgStore defStore = OutlookSession.GetDefaultMsgStore();

            if (defStore == null)
            {
                return;
            }
            string folderId = defStore.GetBinProp(MAPIConst.PR_IPM_SENTMAIL_ENTRYID);

            if (folderId == null)
            {
                return;
            }
            string storeID = defStore.GetBinProp(MAPIConst.PR_ENTRYID);

            if (storeID == null)
            {
                return;
            }
            IEFolder folder = OutlookSession.OpenFolder(folderId, storeID);

            if (folder == null)
            {
                return;
            }
            using ( folder )
            {
                ProcessFolder(folder);
            }
        }
示例#3
0
        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);
                        }
                    }
                }
            }
        }
示例#4
0
        private void DoMoveBetweenStorages(IResource resMail, IEMessage message, PairIDs messageIDs, PairIDs selectedFolderIDs)
        {
            using ( message )
            {
                IEFolder folder =
                    OutlookSession.OpenFolder(selectedFolderIDs.EntryId, selectedFolderIDs.StoreId);
                if (folder == null)
                {
                    return;
                }
                using ( folder )
                {
                    IEMessage newMessage = folder.CreateMessage("IPM.note");
                    using ( newMessage )
                    {
                        message.CopyTo(newMessage);
                        string entryID = newMessage.GetBinProp(MAPIConst.PR_ENTRYID);
                        OutlookSession.SaveChanges(true, "Save mail for moving between storages resource id = " + resMail.Id, newMessage, entryID);
                        if (_copy)
                        {
                            return;
                        }

                        if (!string.IsNullOrEmpty(entryID) && !resMail.HasProp(-PROP.Attachment))
                        {
                            new ResourceProxy(resMail).SetProp(PROP.EntryID, entryID);
                        }
                        OutlookSession.DeleteMessage(messageIDs.StoreId, messageIDs.EntryId, false);
                    }
                }
            }
        }
示例#5
0
        private void _ABList_ResourceChanged(object sender, ResourcePropIndexEventArgs e)
        {
            string    entryID   = e.Resource.GetStringProp(PROP.EntryID);
            IResource resFolder = Folder.Find(entryID);
            PairIDs   pairIDs   = PairIDs.Get(resFolder);

            if (pairIDs == null)
            {
                return;
            }

            IEFolder folder = OutlookSession.OpenFolder(pairIDs.EntryId, pairIDs.StoreId);

            if (folder != null)
            {
                using ( folder )
                {
                    if (!e.Resource.GetPropText(Core.Props.Name).EndsWith("(Outlook)"))
                    {
                        folder.SetStringProp(MAPIConst.PR_DISPLAY_NAME, e.Resource.GetStringProp(Core.Props.Name));
                        folder.SaveChanges();
                    }
                }
            }
        }
示例#6
0
        public FolderModifiedDescriptor(MAPINtf ntf, string storeID, bool isMovedFolder)
        {
            Guard.NullArgument(ntf, "ntf");
            _isMovedFolder = isMovedFolder;
            IEFolder folder = OutlookSession.OpenFolder(ntf.EntryID, storeID);

            if (folder != null)
            {
                using ( folder )
                {
                    _folder = FolderDescriptor.Get(folder);
                    if (ntf.ParentID != null && ntf.ParentID.Length > 0)
                    {
                        IEFolder parentFolder =
                            OutlookSession.OpenFolder(ntf.ParentID, storeID);
                        if (parentFolder != null)
                        {
                            using ( parentFolder )
                            {
                                _parentFolder = FolderDescriptor.Get(parentFolder);
                            }
                        }
                    }
                }
            }
        }
示例#7
0
        private static bool MoveFolder(string storeID, string entryID, string folderID, PairIDs delFolderIds)
        {
            if (folderID == null || folderID == delFolderIds.EntryId)
            {
                return(false);
            }
            IEFolder delFolder = OutlookSession.OpenFolder(delFolderIds.EntryId, delFolderIds.StoreId);

            if (delFolder == null)
            {
                return(false);
            }
            using ( delFolder )
            {
                IEFolder folder = OutlookSession.OpenFolder(folderID, storeID);
                if (folder == null)
                {
                    return(false);
                }
                using ( folder )
                {
                    try
                    {
                        folder.MoveFolder(entryID, delFolder);
                        return(true);
                    }
                    catch (COMException exception)
                    {
                        OutlookSession.OutlookProcessor.HandleException(exception);
                        return(false);
                    }
                }
            }
        }
示例#8
0
        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));
                        }
                    }
                }
            }
        }
示例#9
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);
                    }
                }
            }
        }
示例#10
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);
                }
            }
        }
示例#11
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);
                            }
                        }
                    }
                }
            }
        }
示例#12
0
        private static void EmptyFolder(IResource resource)
        {
            PairIDs  IDs    = PairIDs.Get(resource);
            IEFolder folder = OutlookSession.OpenFolder(IDs.EntryId, IDs.StoreId);

            if (folder != null)
            {
                using ( folder )
                {
                    folder.Empty();
                }
            }
        }
示例#13
0
        public static void DeleteFolder(PairIDs folderIDs, bool DeletedItems, string newName)
        {
            if (!DeletedItems)
            {
                DeleteFolderImpl(folderIDs, false);
                return;
            }

            PairIDs deletedItems = OutlookSession.GetDeletedItemsFolderIDs(folderIDs.StoreId);

            if (deletedItems == null)
            {
                DeleteFolderImpl(folderIDs, false);
                return;
            }

            string   folderID = null;
            IEFolder folder   = OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId);

            if (folder != null)
            {
                using ( folder )
                {
                    folderID = folder.GetFolderID();
                }
            }
            if (folderID != null)
            {
                if (folderID != deletedItems.EntryId)
                {
                    if (newName != null)
                    {
                        IEFolder eFolder = OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId);
                        if (eFolder != null)
                        {
                            using ( eFolder )
                            {
                                eFolder.SetStringProp(MAPIConst.PR_DISPLAY_NAME, newName);
                                eFolder.SaveChanges();
                            }
                        }
                    }

                    if (MoveFolder(folderIDs.StoreId, folderIDs.EntryId, folderID, deletedItems))
                    {
                        return;
                    }
                }
            }
            DeleteFolderImpl(folderIDs, false);
        }
示例#14
0
        internal static IEFolder GetAddressBookFolder(IResource AB)
        {
            Guard.NullArgument(AB, "AB");
            string entryID = AB.GetStringProp(PROP.EntryID);
            string storeID = AB.GetStringProp(PROP.StoreID);

            if (entryID == null || storeID == null)
            {
                Trace("ERROR: Can't export contact because address book has not entryID and storeID", false);
                Trace("WARNING: Probably this address book is unmodifiable", false);
                return(null);
            }
            return(OutlookSession.OpenFolder(entryID, storeID));
        }
示例#15
0
        public static FolderDescriptor Get(PairIDs IDs)
        {
            Guard.NullArgument(IDs, "IDs");
            IEFolder folder =
                OutlookSession.OpenFolder(IDs.EntryId, IDs.StoreId);

            if (folder != null)
            {
                using ( folder )
                {
                    return(Get(IDs, folder));
                }
            }
            return(null);
        }
示例#16
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);
            }
        }
示例#17
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);
     }
 }
示例#18
0
        public void EnumerateMessageItems(FolderDescriptor folderDescriptor)
        {
            if (OutlookSession.WereProblemWithOpeningStorage(folderDescriptor.FolderIDs.StoreId) ||
                OutlookSession.WereProblemWithOpeningFolder(folderDescriptor.FolderIDs.EntryId))
            {
                return;
            }

            try
            {
                IEFolder mapiFolder =
                    OutlookSession.OpenFolder(folderDescriptor.FolderIDs.EntryId, folderDescriptor.FolderIDs.StoreId);
                if (mapiFolder == null)
                {
                    return;
                }
                using ( mapiFolder )
                {
                    string containerClass = mapiFolder.GetStringProp(MAPIConst.PR_CONTAINER_CLASS);
                    bool   taskFolder     = (FolderType.Task.Equals(containerClass));
                    if (taskFolder)
                    {
                        EnumerateTasks(folderDescriptor, mapiFolder);
                    }
                    else
                    {
                        EnumerateMail(folderDescriptor, mapiFolder);
                    }
                }
            }
            catch (COMException exception)
            {
                _tracer.TraceException(exception);
                if (exception.ErrorCode == MapiError.MAPI_E_NOT_ENOUGH_DISK)
                {
                    StandartJobs.MessageBox("Outlook reports that there is no enough disk space.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                OutlookSession.ProblemWithOpeningFolder(folderDescriptor.FolderIDs.EntryId);
                return;
            }
        }
示例#19
0
 private static bool MoveMessage(string storeID, string entryID, string folderID, PairIDs delFolderIds)
 {
     if (folderID == null)
     {
         return(false);
     }
     if (folderID != delFolderIds.EntryId)
     {
         IEFolder delFolder = OutlookSession.OpenFolder(delFolderIds.EntryId, delFolderIds.StoreId);
         if (delFolder == null)
         {
             return(false);
         }
         using ( delFolder )
         {
             IEFolder folder = OutlookSession.OpenFolder(folderID, storeID);
             if (folder == null)
             {
                 return(false);
             }
             using ( folder )
             {
                 try
                 {
                     folder.MoveMessage(entryID, delFolder);
                     return(true);
                 }
                 catch (COMException exception)
                 {
                     _tracer.TraceException(exception);
                     StandartJobs.MessageBox("Cannot complete deleting mail. Reason: " + exception.Message, "Error",
                                             MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return(false);
                 }
             }
         }
     }
     return(false);
 }
示例#20
0
        private void DoMoveImpl(IEMessage message, PairIDs messageIDs, PairIDs selectedFolderIDs)
        {
            string parentID = string.Empty;

            using ( message )
            {
                parentID = message.GetBinProp(MAPIConst.PR_PARENT_ENTRYID);
            }
            IEFolder parentFolder =
                OutlookSession.OpenFolder(parentID, messageIDs.StoreId);

            if (parentFolder == null)
            {
                return;
            }

            using ( parentFolder )
            {
                IEFolder folder =
                    OutlookSession.OpenFolder(selectedFolderIDs.EntryId, selectedFolderIDs.StoreId);
                if (folder == null)
                {
                    return;
                }
                using ( folder )
                {
                    if (_copy)
                    {
                        parentFolder.CopyMessage(messageIDs.EntryId, folder);
                    }
                    else
                    {
                        parentFolder.MoveMessage(messageIDs.EntryId, folder);
                    }
                }
            }
        }
示例#21
0
        protected override void ExecuteAction(IResourceList selectedResources)
        {
            Trace.WriteLine(">>> CreateFolderAction.ExecuteAction");
            PairIDs folderIDs = PairIDs.Get(selectedResources[0]);

            try
            {
                IEFolder folder =
                    OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId);
                if (folder == null)
                {
                    return;
                }
                using ( folder )
                {
                    IEFolder subFolder = folder.CreateSubFolder(_folderName);
                    if (subFolder != null)
                    {
                        using ( subFolder )
                        {}
                    }
                }
            }
            catch (COMException exception)
            {
                Tracer._TraceException(exception);
                MsgBox.Error("Outlook Plugin", "Cannot create new folder.\n" +
                             "Reason is: folder with such name already exists.");
            }
            catch (System.UnauthorizedAccessException exception)
            {
                Tracer._TraceException(exception);
                MsgBox.Error("Outlook Plugin", "Cannot create new folder.\n" + exception.Message);
            }
            Trace.WriteLine("<<< CreateFolderAction.ExecuteAction");
        }
示例#22
0
        protected void Init(FolderDescriptor folderDescriptor, string entryID, IEMessage message, string longBody)
        {
            _longBody     = longBody;
            _folder       = folderDescriptor;
            _messageClass = MessageType.GetMessageClass(message);
            if (!Settings.ProcessAllPropertiesForMessage)
            {
                _subject = "test";
                return;
            }
            string folderID = message.GetBinProp(MAPIConst.PR_PARENT_ENTRYID);

            if (folderID != null)
            {
                string   storeID = message.GetBinProp(MAPIConst.PR_STORE_ENTRYID);
                IEFolder folder  = OutlookSession.OpenFolder(folderID, storeID);
                if (folder != null)
                {
                    using ( folder )
                    {
                        _folder = FolderDescriptor.Get(folder);
                    }
                }
            }
            _entryID = entryID;

            if (_folder != null && Folder.IsIgnored(_folder))
            {
                _toDeleteResource = true;
                return;
            }

            int tag = message.GetIDsFromNames(ref GUID.set1, lID.msgDeletedInIMAP, PropType.PT_LONG);

            _deletedInIMAP = message.GetLongProp(tag) == 1;

            if (_deletedInIMAP && Settings.IgnoreDeletedIMAPMessages)
            {
                _toDeleteResource = true;
                return;
            }

            _subject = message.GetStringProp(MAPIConst.PR_SUBJECT);
            if (_subject == null)
            {
                _subject = string.Empty;
            }
            _unread = message.IsUnread();

            _lastModifiedDate = message.GetDateTimeProp(MAPIConst.PR_LAST_MODIFICATION_TIME);
            _lastModifiedDate = _lastModifiedDate.ToUniversalTime();

            _messageSize = message.GetLongProp(MAPIConst.PR_MESSAGE_SIZE);
            _iconIndex   = message.GetLongProp(MAPIConst.PR_ICON_INDEX);

            _priority = message.GetLongProp(MAPIConst.PR_PRIORITY);
            int importance = message.GetLongProp(MAPIConst.PR_IMPORTANCE, true);

            if (importance == -9999)
            {
                importance = 1;
            }
            _importance = importance - 1;
            _flagStatus = message.GetLongProp(MAPIConst.PR_FLAG_STATUS);

            if (_flagStatus == 2)
            {
                _flagColor = message.GetLongProp(MAPIConst.PR_FLAG_COLOR, true);
                if (_flagColor == -9999)
                {
                    _flagColor = 6;
                }
            }

            _internetMessageID = message.GetStringProp(MAPIConst.PR_INTERNET_MESSAGE_ID);

            _recordKey         = message.GetBinProp(MAPIConst.PR_RECORD_KEY);
            _conversationIndex = message.GetBinProp(MAPIConst.PR_CONVERSATION_INDEX);

            _replyToID          = message.GetStringProp(MAPIConst.PR_IN_REPLY_TO_ID);
            _internetReferences = message.GetStringProp(MAPIConst.PR_INTERNET_REFERENCES);

            if (Settings.CreateAnnotationFromFollowup)
            {
                int annotationTag = message.GetIDsFromNames(ref GUID.set1, lID.msgFlagAnnotation, PropType.PT_STRING8);
                _flag = message.GetStringProp(annotationTag);
            }

            _outlookCategories = OutlookSession.GetCategories(message);;

            _receivedTime = message.GetDateTimeProp(MAPIConst.PR_MESSAGE_DELIVERY_TIME);
            _sentOn       = message.GetDateTimeProp(MAPIConst.PR_CLIENT_SUBMIT_TIME);
            if (_receivedTime == DateTime.MinValue)
            {
                _receivedTime = _sentOn;
            }

            _listUnsubscribe = message.GetStringProp(MAPIConst.PR_LIST_UNSUBSCRIBE);
            if (_listUnsubscribe != null)
            {
                _listUnsubscribe = ExtractUnsubscribeEmail(_listUnsubscribe);
            }

            _contactCreated = MailSenderHelper.LoadSenderInfo(message, out _senderName, out _senderEmail);

            if (Settings.ProcessRecipients)
            {
                _state.EndOfInit(this, message);
            }
        }
示例#23
0
        public FolderDeletedDescriptor(MAPINtf ntf, string storeID)
        {
            Guard.NullArgument(ntf, "ntf");
            Guard.EmptyStringArgument(storeID, "storeID");
            _ntf     = ntf;
            _storeID = storeID;

            // The notification contains only the short-term entry ID, and since the
            // folder has already been deleted, it is no longer possible to get the
            // long-term entry ID. Thus, we need to scan the children of the parent of
            // the deleted folder and check if all of them still exist.
            IResource resFolder = Folder.Find(ntf.EntryID);

            if (resFolder == null)
            {
                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)
                        {
                            parentMAPIFolder = Folder.Find(ntf.ParentID);
                        }

                        if (parentMAPIFolder != null)
                        {
                            IResourceList childFolders = parentMAPIFolder.GetLinksTo("MAPIFolder", "Parent");
                            foreach (IResource childFolderRes in childFolders)
                            {
                                IEFolder childFolder = OutlookSession.OpenFolder(childFolderRes.GetStringProp("EntryID"),
                                                                                 storeID);
                                if (childFolder != null)
                                {
                                    childFolder.Dispose();
                                }
                                else
                                {
                                    _entryId = childFolderRes.GetStringProp("EntryID");
                                }
                            }

                            if (_entryId == null)
                            {
                                HashSet set = new HashSet(childFolders.Count);
                                foreach (IResource childFolderRes in childFolders)
                                {
                                    set.Add(childFolderRes.GetStringProp("EntryID"));
                                }

                                IEFolders folders = OutlookSession.GetFolders(parentFolder);
                                if (folders != null)
                                {
                                    using ( folders )
                                    {
                                        for (int i = 0; i < folders.GetCount(); ++i)
                                        {
                                            IEFolder folder = OutlookSession.OpenFolder(folders, i);
                                            if (folder != null)
                                            {
                                                using ( folder )
                                                {
                                                    string entryId = folder.GetBinProp(MAPIConst.PR_ENTRYID);
                                                    if (entryId != null)
                                                    {
                                                        set.Remove(entryId);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                foreach (HashSet.Entry entry in set)
                                {
                                    _entryId = (string)entry.Key;
                                    break;
                                }

                                if (_entryId == null && Retry)
                                {
                                    OutlookSession.OutlookProcessor.QueueJobAt(DateTime.Now.AddMinutes(2), "Delete folder",
                                                                               new MethodInvoker(CreateFolderDeletedDescriptor));
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                _entryId = ntf.EntryID;
            }
        }
示例#24
0
        protected void ExecuteActionImpl(IResourceList selectedResources)
        {
            Tracer._Trace("Execute action: MoveFolderToFolderAction");
            if (_selectedFolder == null || _targetFolder == null)
            {
                return;
            }

            IEFolder destFolder =
                OutlookSession.OpenFolder(_selectedFolder.EntryId, _selectedFolder.StoreId);

            if (destFolder == null)
            {
                return;
            }

            using ( destFolder )
            {
                for (int i = 0; i < selectedResources.Count; i++)
                {
                    PairIDs folderIDs = PairIDs.Get(selectedResources[i]);
                    if (folderIDs == null)
                    {
                        continue;
                    }
                    IResource parentFolder    = Folder.GetParent(selectedResources[i]);
                    PairIDs   parentFolderIDs = PairIDs.Get(parentFolder);
                    if (parentFolderIDs == null)
                    {
                        continue;
                    }

                    IEFolder ieFolder =
                        OutlookSession.OpenFolder(parentFolderIDs.EntryId, parentFolderIDs.StoreId);
                    if (ieFolder == null)
                    {
                        continue;
                    }
                    using ( ieFolder )
                    {
                        Tracer._Trace("Move folder: " + folderIDs.EntryId.GetHashCode() + "/" + folderIDs.EntryId);
                        try
                        {
                            ieFolder.MoveFolder(folderIDs.EntryId, destFolder);
                        }
                        catch (COMException exception)
                        {
                            Tracer._TraceException(exception);
                            if (exception.ErrorCode == (unchecked ((int)0x8004010F)))
                            {
                                StandartJobs.MessageBox("Folder is not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (exception.ErrorCode == (unchecked ((int)0x80040604)))
                            {
                                StandartJobs.MessageBox("Collision. Probably target folder has subfolder with the same name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (exception.ErrorCode == (unchecked ((int)0x80040119)) || exception.ErrorCode == (unchecked ((int)0x8004dff2)))
                            {
                                StandartJobs.MessageBox("Unspecified error. Can't move or copt folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                StandartJobs.MessageBox(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
            }
        }
示例#25
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);
                }
            }
        }