Exemplo n.º 1
0
 public FolderPermissionViewModel(MailboxFolderViewModel folder, FolderPermissionWrapper permission)
 {
     Permission      = permission;
     User            = Permission.User;
     FolderViewModel = folder;
     addPermissionLevels();
     OriginalAccessRights = Permission.AccessRights;
     AccessRights         = OriginalAccessRights;
 }
Exemplo n.º 2
0
        private void applyMultiPermission(MailboxFolderViewModel folderViewModel, IEnumerable <FolderPermissionViewModel> permissions, bool subfolders)
        {
            ParentMailboxViewModel.Status = "Applying permissions to " + folderViewModel.FolderWrapper.Name;

            if (!subfolders)
            {
                foreach (FolderPermissionViewModel permission in permissions)
                {
                    if (permission.AccessRights == "Remove")
                    {
                        Exchange.RemoveFolderPermissions(ParentMailboxViewModel.Mailbox.PrimarySmtp, folderViewModel.FolderWrapper.CorrectedFolderPath,
                                                         permission.User);
                    }
                    else
                    {
                        Exchange.SetFolderPermissions(ParentMailboxViewModel.Mailbox.PrimarySmtp, folderViewModel.FolderWrapper.CorrectedFolderPath,
                                                      permission.User, permission.AccessRights);
                    }
                }
            }
            else
            {
                Exchange.RemoveAllFolderPermissions(ParentMailboxViewModel.Mailbox.PrimarySmtp, folderViewModel.FolderWrapper.CorrectedFolderPath);

                foreach (FolderPermissionViewModel permission in permissions)
                {
                    if (permission.AccessRights == "Remove")
                    {
                        Exchange.RemoveFolderPermissions(ParentMailboxViewModel.Mailbox.PrimarySmtp, folderViewModel.FolderWrapper.CorrectedFolderPath,
                                                         permission.User);
                    }
                    else
                    {
                        Exchange.SetFolderPermissions(ParentMailboxViewModel.Mailbox.PrimarySmtp, folderViewModel.FolderWrapper.CorrectedFolderPath,
                                                      permission.User, permission.AccessRights);
                    }
                }
                foreach (MailboxFolderViewModel subfolder in folderViewModel.SubfolderViewModels)
                {
                    applyMultiPermission(subfolder, permissions, true);
                }
            }
        }
Exemplo n.º 3
0
        private void getFoldersWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Status = "Retrieving folder list";
            Collection <PSObject> psFolders = Exchange.GetMailboxFolders(Mailbox.DistinguishedName);

            Status = "Organising folder tree";
            MailboxFolderViewModel topLevelFolder = new MailboxFolderViewModel(this, new MailboxFolderWrapper(psFolders[0]))
            {
                IsExpanded = true
            };
            ObservableCollection <MailboxFolderViewModel> folders = new ObservableCollection <MailboxFolderViewModel>();

            folders.Add(topLevelFolder);
            //Add all the folders as a flat list of subfolders to the top of information store.
            for (int i = 1; i < psFolders.Count; i++)
            {
                topLevelFolder.SubfolderViewModels.Add(new MailboxFolderViewModel(this, new MailboxFolderWrapper(psFolders[i])));
            }
            //If the folder path contains a / then it must be a subfolder.
            IEnumerable <MailboxFolderViewModel> subFolders =
                (from folder in topLevelFolder.SubfolderViewModels
                 where folder.FolderWrapper.FolderPath.TrimStart('/').Contains('/')
                 select folder).ToList();

            foreach (MailboxFolderViewModel subFolder in subFolders)
            {
                //The subfolder's parent folder path is everything prior to the last occurrence of / in
                //the subfolder's folder path.
                int    dividorIndex = subFolder.FolderWrapper.FolderPath.LastIndexOf('/');
                string parentPath   = subFolder.FolderWrapper.FolderPath.Substring(0, dividorIndex);

                MailboxFolderViewModel parentFolder = topLevelFolder.SubfolderViewModels.Single(x => x.FolderWrapper.FolderPath == parentPath);
                parentFolder.SubfolderViewModels.Add(subFolder);
            }
            //Once all subfolders have been added to the correct parent folder they need to be removed
            //from the top level.
            foreach (MailboxFolderViewModel folder in subFolders)
            {
                topLevelFolder.SubfolderViewModels.Remove(folder);
            }
            e.Result = folders;
        }
Exemplo n.º 4
0
        private void applySinglePermission(MailboxFolderViewModel folderViewModel, string permission, string user, bool subfolders)
        {
            ParentMailboxViewModel.Status = "Applying permissions to " + folderViewModel.FolderWrapper.Name;

            if (permission == "Remove")
            {
                Exchange.RemoveFolderPermissions(ParentMailboxViewModel.Mailbox.PrimarySmtp, folderViewModel.FolderWrapper.CorrectedFolderPath,
                                                 user);
            }
            else
            {
                Exchange.SetFolderPermissions(ParentMailboxViewModel.Mailbox.PrimarySmtp, folderViewModel.FolderWrapper.CorrectedFolderPath,
                                              user, permission);
            }
            if (subfolders)
            {
                foreach (MailboxFolderViewModel subfolder in folderViewModel.SubfolderViewModels)
                {
                    applySinglePermission(subfolder, permission, user, true);
                }
            }
        }