Ejemplo n.º 1
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);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 protected virtual void ExecuteAction(IResource resource, PairIDs pairIDs)
 {
 }
Ejemplo n.º 3
0
 public void DoMove(IResource targetFolder, IResourceList selectedResources)
 {
     SetFolder(PairIDs.Get(targetFolder), targetFolder);
     OutlookSession.OutlookProcessor.QueueJob(JobPriority.Immediate, "Move subfolder to another parent folder",
                                              new ResourceListDelegate(ExecuteActionImpl), selectedResources);
 }
Ejemplo n.º 4
0
 protected void SetFolder(PairIDs selectedFolder, IResource targetFolder)
 {
     _selectedFolder = selectedFolder;
     _targetFolder   = targetFolder;
 }
Ejemplo n.º 5
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);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void SynchronizeFolderStructureImpl()
        {
            _tracer.Trace("Start SynchronizeFolderStructureImpl");
            IResourceList folders = Core.ResourceStore.GetAllResources(STR.MAPIFolder);

            foreach (IResource folder in folders.ValidResources)
            {
                string entryID = folder.GetStringProp(PROP.EntryID);
                if (entryID != null)
                {
                    _folders.Add(entryID);
                }
                else
                {
                    new ResourceProxy(folder).DeleteAsync();
                }
            }
            _tracer.Trace("Start enumeration for info stores");

            foreach (IEMsgStore msgStore in OutlookSession.GetMsgStores())
            {
                if (msgStore == null)
                {
                    continue;
                }
                _tracer.Trace("GetRootFolder");

                IEFolder rootFolder = msgStore.GetRootFolder();
                string   storeID    = msgStore.GetBinProp(MAPIConst.PR_STORE_ENTRYID);
                if (IsIgnoredInfoStore(msgStore))
                {
                    _tracer.Trace("MsgStore is ignored");
                    if (rootFolder == null)
                    {
                        continue;
                    }
                    using ( rootFolder )
                    {
                        string    entryID        = OutlookSession.GetFolderID(rootFolder);
                        IResource rootMAPIFolder = Folder.Find(entryID);
                        if (rootMAPIFolder != null)
                        {
                            _tracer.Trace("Delete folder recursive for " + rootMAPIFolder.DisplayName);
                            Core.ResourceAP.QueueJob("Delete folder recursive", new ResourceDelegate(Folder.DeleteFolderRecursive),
                                                     rootMAPIFolder);
                        }
                    }
                }
                else
                {
                    string name = msgStore.GetStringProp(MAPIConst.PR_DISPLAY_NAME);
                    _tracer.Trace("MsgStore name = " + name);
                    SynchronizeFolderRecursive(rootFolder, name, storeID, null);
                }
            }

            _tracer.Trace("Delete folders recursively if necessary");

            foreach (HashSet.Entry entry in _folders)
            {
                IResource folderToDelete =
                    Core.ResourceStore.FindUniqueResource(STR.MAPIFolder, PROP.EntryID, (string)entry.Key);
                if (folderToDelete != null)
                {
                    PairIDs folderIDs = PairIDs.Get(folderToDelete);
                    if (folderIDs != null)
                    {
                        if (OutlookSession.WereProblemWithOpeningStorage(folderIDs.StoreId))
                        {
                            continue;
                        }
                        if (OutlookSession.WereProblemWithOpeningFolder(folderIDs.EntryId))
                        {
                            continue;
                        }
                    }
                    Core.ResourceAP.QueueJob(new ResourceDelegate(Folder.DeleteFolderRecursive),
                                             folderToDelete);
                }
            }
            _folders.Clear();
            _tracer.Trace("Finish SynchronizeFolderStructureImpl");
        }
Ejemplo n.º 7
0
 public static bool FolderExists(PairIDs IDs)
 {
     return(FolderExists(IDs.EntryId, IDs.StoreId));
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
0
 public static void DeleteFolderWithRename(PairIDs folderIDs, string newName)
 {
     DeleteFolder(folderIDs, true, newName);
 }
Ejemplo n.º 10
0
        public static void Initialize()
        {
            try
            {
                _outlookVersion = GetOutlookVersionFromRegistry();
            }
            catch (Exception ex)
            {
                Core.AddExceptionReportData("\nError getting Outlook version from registry: " + ex.Message);
                Trace.WriteLine("Error getting Outlook version from registry: " + ex.Message);
                _outlookVersion = 0;
            }
            ReportOutlookAddins();
            ReportOutlookExtensions();
            _eSession = new EMAPISession(0);
            _eSession.CheckDependencies();
            try
            {
                if (!_eSession.Initialize(IsPickLogonProfile(), _libManager))
                {
                    throw new Exception("MAPI logon failed");
                }
            }
            catch (COMException exception)
            {
                _tracer.TraceException(exception);
                Core.ReportBackgroundException(exception);
                throw new Exception("MAPI logon failed: " + exception.Message);
            }
            _addressBook = _eSession.OpenAddrBook();
            IEMsgStores stores = _eSession.GetMsgStores();

            if (stores != null)
            {
                using ( stores )
                {
                    int count = stores.GetCount();
                    Trace.WriteLine("*********************************************************");
                    Trace.WriteLine("* " + count + " MAPI stores detected");
                    for (int i = 0; i < count; ++i)
                    {
                        IEMsgStore store = null;
                        try
                        {
                            store = stores.GetMsgStore(i);
                        }
                        catch (EMAPILib.ProblemWhenOpenStorage ex)
                        {
                            Trace.WriteLine("* " + i + "th store caused problem while getting the IEMsgStore resource");
                            ProblemWithOpeningStorage(ex);
                        }
                        if (store == null)
                        {
                            continue;
                        }

                        string storeID = stores.GetStorageID(i);
                        _msgStores.Add(storeID, store);
                        Trace.WriteLine("* " + i + "th store has StoreID [" + storeID + "]");

                        if (Settings.UseOutlookListeners)
                        {
                            try
                            {
                                MAPIListenerStub mapiListener = new MAPIListenerStub(new MAPIListener(storeID));
                                store.Advise(mapiListener);
                            }
                            catch (Exception exception)
                            {
                                _tracer.TraceException(exception);
                                //SetLastException( exception );
                            }
                        }

                        if (stores.IsDefaultStore(i))
                        {
                            Trace.WriteLine("* " + i + "th store is a default store");
                            _defaultMsgStore = store;
                            string delEntryID = _defaultMsgStore.GetBinProp(MAPIConst.PR_IPM_WASTEBASKET_ENTRYID);
                            _deletedFolderIDs = new PairIDs(delEntryID, storeID);
                        }
                    }
                    Trace.WriteLine("*********************************************************");
                }
            }
            if (_defaultMsgStore == null)
            {
                throw new ApplicationException("There is no default storage");
            }
        }
Ejemplo n.º 11
0
 public static void DeleteFolder(PairIDs folderIDs, bool DeletedItems)
 {
     DeleteFolder(folderIDs, DeletedItems, null);
 }
Ejemplo n.º 12
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.º 13
0
 public static FolderDescriptor Get(PairIDs IDs, IEFolder folder)
 {
     Guard.NullArgument(IDs, "IDs");
     Guard.NullArgument(folder, "folder");
     return(new FolderDescriptor(IDs, folder));
 }
Ejemplo n.º 14
0
 public static void Do(JobPriority jobPriority, PairIDs folderIDs, DateTime dateRestriction)
 {
     Do(jobPriority, FolderDescriptor.Get(folderIDs.EntryId, folderIDs.StoreId), dateRestriction);
 }
Ejemplo n.º 15
0
 public FolderDescriptor(IResource folder)
 {
     Init(PairIDs.Get(folder),
          folder.GetPropText(Core.Props.Name),
          Folder.GetContainerClass(folder), Folder.GetStoreSupportMask(folder), Folder.GetConentCount(folder));
 }