public ItemCountSynchronizer(INavigationNode node, EmailFolder folder)
 {
     this.node   = node;
     this.folder = folder;
     WeakEvent.CollectionChanged.Add(folder.Emails, EmailsCollectionChanged);
     UpdateItemCount();
 }
        /// <summary>
        /// Deletes all items from the specified folder.
        /// </summary>
        /// <param name="folder">The <see cref="EmailFolder" /> to clear.</param>
        public void Clear(EmailFolder folder)
        {
            UpdateStatus($"Clearing {folder} messages for {UserName}.", true);
            var ids = RetrieveHeaders(folder, int.MaxValue).Select(n => n.Id);

            DeleteHeaders(ids);
        }
Example #3
0
 public ItemCountSynchronizer(INavigationNode node, EmailFolder folder)
 {
     this.node   = node;
     this.folder = folder;
     CollectionChangedEventManager.AddHandler(folder.Emails, EmailsCollectionChanged);
     UpdateItemCount();
 }
Example #4
0
 public void NotifyEmailDeleted(EmailFolder emailFolder, Email email)
 {
     if (emailFolder != Deleted)
     {
         Deleted.AddEmail(email);
     }
 }
Example #5
0
        public void AddAndRemoveEmails()
        {
            var emailDeletionService = new MockEmailDeletionService();
            var emailFolder          = new EmailFolder()
            {
                EmailDeletionService = emailDeletionService
            };

            Assert.IsFalse(emailFolder.Emails.Any());
            var email1 = new Email();

            emailFolder.AddEmail(email1);
            Assert.AreEqual(email1, emailFolder.Emails.Single());

            var email2 = new Email();

            emailFolder.AddEmail(email2);
            AssertHelper.SequenceEqual(new[] { email1, email2 }, emailFolder.Emails);

            bool deleteEmailCalled = false;

            emailDeletionService.DeleteEmailAction = (folder, email) =>
            {
                deleteEmailCalled = true;
                Assert.AreEqual(emailFolder, folder);
                Assert.AreEqual(email1, email);
            };
            emailFolder.RemoveEmail(email1);
            Assert.IsTrue(deleteEmailCalled);
        }
Example #6
0
        private void DeleteEmail()
        {
            var nextEmail = CollectionHelper.GetNextElementOrDefault(EmailListViewModel.Emails, EmailListViewModel.SelectedEmail);

            EmailFolder.RemoveEmail(EmailListViewModel.SelectedEmail);
            EmailListViewModel.SelectedEmail = nextEmail ?? EmailListViewModel.Emails.LastOrDefault();
            EmailListViewModel.FocusItem();
        }
Example #7
0
        private void DeleteEmail()
        {
            // Use the EmailCollectionView, which represents the sorted/filtered state of the emails, to determine the next email to select.
            var nextEmail = CollectionHelper.GetNextElementOrDefault(EmailListViewModel.EmailCollectionView, EmailListViewModel.SelectedEmail);

            EmailFolder.RemoveEmail(EmailListViewModel.SelectedEmail);
            EmailListViewModel.SelectedEmail = nextEmail ?? EmailListViewModel.EmailCollectionView.LastOrDefault();
            EmailListViewModel.FocusItem();
        }
Example #8
0
 public EmailClientRoot()
 {
     emailAccounts = new ObservableCollection <EmailAccount>();
     inbox         = new EmailFolder();
     outbox        = new EmailFolder();
     sent          = new EmailFolder();
     drafts        = new EmailFolder();
     deleted       = new EmailFolder();
     Initialize();
 }
Example #9
0
    private void ShowEmails(EmailFolder emailFolder)
    {
        activeEmailFolderController             = emailFolderControllerFactory.CreateExport().Value;
        activeEmailFolderController.EmailFolder = emailFolder;
        activeEmailFolderController.Initialize();
        activeEmailFolderController.Run();
        var uiNewEmailCommand      = new ToolBarCommand(newEmailCommand, "_New email", "Creates a new email.");
        var uiDeleteEmailCommand   = new ToolBarCommand(activeEmailFolderController.DeleteEmailCommand, "_Delete", "Deletes the selected email.");
        var uiEmailAccountsCommand = new ToolBarCommand(emailAccountsController.EmailAccountsCommand, "_Email accounts", "Opens a window that shows the email accounts.");

        shellService.AddToolBarCommands(new[] { uiNewEmailCommand, uiDeleteEmailCommand, uiEmailAccountsCommand });
    }
        /// <summary>
        /// Retrieves up to the specified number email messages from the specfied <see cref="EmailFolder" />.
        /// </summary>
        /// <param name="folder">The <see cref="EmailFolder" /> to retrieve from.</param>
        /// <param name="itemLimit">The maximum number of messages to retrieve.</param>
        /// <returns>A collection of <see cref="EmailMessage" /> objects.</returns>
        public Collection <EmailMessage> RetrieveMessages(EmailFolder folder, int itemLimit)
        {
            Collection <EmailMessage> messages = new Collection <EmailMessage>();

            UpdateStatus($"Retrieving {folder} messages for {UserName}.", true);

            List <Item> items = RetrieveHeaders(folder, itemLimit).ToList();

            if (items.Any())
            {
                UpdateStatus($"Total email messages found: {items.Count}", true);

                // If the inbox has thousands of emails, then we will timeout waiting to download them all.
                // Work on this in batches.
                const int batchSize = 10;
                for (int i = 0; i < items.Count; i += batchSize)
                {
                    // Read in the next batch.
                    List <Item> batch = new List <Item>();
                    for (int j = 0; j < batchSize && (i + j) < items.Count; j++)
                    {
                        batch.Add(items[i + j]);
                    }

                    UpdateStatus($"Retrieving email messages from {i} to {i + batch.Count} (total {items.Count})");
                    PropertySet messageProperties = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments);
                    var         serviceResponses  = _service.LoadPropertiesForItems(batch, messageProperties);
                    UpdateStatus("Messages retrieved.");

                    foreach (GetItemResponse response in serviceResponses)
                    {
                        ExchangeMessage message = response.Item as ExchangeMessage;
                        try
                        {
                            messages.Add(new ExchangeEmailMessage(message));
                        }
                        catch (ServiceObjectPropertyException)
                        {
                            // This error can be thrown when the EmailMessage is an automated email sent from the Exchange server,
                            // such as a notification that the inbox is full. It may not contain all the properties of a normal email.
                            LogWarn($"Found invalid email with subject: {message.Subject}");
                        }
                    }
                }
            }
            return(messages);
        }
Example #11
0
        public void OnEmailFolderChanged(EmailFolder newFolder)
        {
            if (currentFolder != null)
            {
                currentFolder.EmailChanged -= OnFolderContentsChanged;
            }

            currentFolder = newFolder;
            currentFolder.EmailChanged += OnFolderContentsChanged;

            ObservableCollection <MailViewModel> newEmails = new ObservableCollection <MailViewModel>();

            foreach (Email email in currentFolder.Emails)
            {
                newEmails.Add(new MailViewModel(email, emailService));
            }
            Emails = newEmails;
        }
        private IEnumerable <Item> RetrieveHeaders(EmailFolder emailFolder, int itemLimit)
        {
            try
            {
                UpdateStatus($"Binding to {emailFolder} folder...");
                WellKnownFolderName folderName = _exchangeFolders[emailFolder];
                Folder folder = Folder.Bind(_service, folderName);
                UpdateStatus("Folder bind successful.");

                UpdateStatus($"Retrieving {emailFolder} headers...");
                IEnumerable <Item> items = folder.FindItems(new ItemView(itemLimit));
                UpdateStatus($"{emailFolder} headers retrieved.");

                return(items);
            }
            catch (ServiceRequestException ex)
            {
                throw new EmailServerException("Unable to contact the remote email server.", ex);
            }
        }
 /// <summary>
 /// Creates an <see cref="ExchangeServiceSubscription" /> for the specified <see cref="EmailFolder" />.
 /// </summary>
 /// <param name="folder">The <see cref="EmailFolder" /> to monitor.</param>
 /// <returns>An <see cref="ExchangeServiceSubscription" />.</returns>
 public ExchangeServiceSubscription CreateSubscription(EmailFolder folder)
 {
     return(new ExchangeServiceSubscription(_service, _exchangeFolders[folder]));
 }
Example #14
0
        private void OnEmailFolderChanged(EmailFolder newFolder)
        {
            EmailFolderChangeEvent evt = eventAggregator.GetEvent <EmailFolderChangeEvent>();

            evt.Publish(newFolder);
        }
 /// <summary>
 /// Retrieves all email messages from the specfied <see cref="EmailFolder" />.
 /// </summary>
 /// <param name="folder">The <see cref="EmailFolder" /> to retrieve from.</param>
 /// <returns>A collection of <see cref="EmailMessage" /> objects.</returns>
 public Collection <EmailMessage> RetrieveMessages(EmailFolder folder)
 {
     return(RetrieveMessages(folder, int.MaxValue));
 }
Example #16
0
 public void NotifyEmailDeleted(EmailFolder emailFolder, Email email)
 {
     DeleteEmailAction(emailFolder, email);
 }
Example #17
0
        public ActionResult Register()
        {
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;

            RegisterModel rm = new RegisterModel()
            {
                Keywords  = new string[] { "francesco", "Abbruzzese", "Programmer" },
                Keywords1 = new List <KeywordItem> {
                    new KeywordItem {
                        Keyword = "francesco", Title = "My Program 1"
                    },
                    new KeywordItemExt {
                        Keyword = "Giovanni", Title = "My Program 2"
                    },
                    new KeywordItem {
                        Keyword = "Fausto", Title = "My Program 3"
                    }
                },
                UserName = "******", Roles = new List <int> {
                    4
                }
            };

            rm.Start = new DateTime(2010, 3, 2, 16, 20, 22);
            rm.Stop  = new DateTime(2010, 3, 2, 20, 20, 22);
            rm.Delay = new TimeSpan(0, -4, 0, 0, 0);


            rm.Page     = 1;
            rm.PrevPage = rm.Page;
            List <Tracker <ToDoItem> >[] AllPages = null;
            rm.TotalPages = 10; CreatePages(rm.TotalPages, 4, ref AllPages);

            Session["AllPages"] = AllPages;
            if (rm.Page > rm.TotalPages)
            {
                rm.Page = rm.TotalPages;
            }
            rm.ToDoList = AllPages[rm.Page - 1];


            rm.Selection           = "choice2";
            rm.PersonalData        = new PersonalInfosExt();
            rm.PersonalData.MinAge = 18f;

            rm.PersonalData.MaxAge      = 40f;
            rm.PersonalData.MinAgeDelay = 0f;
            rm.ClientKeywords           = new List <string>();
            rm.ClientKeywords.Add("To Start");

            rm.EmailFolders = new List <EmailElement>();
            EmailElement friends = new EmailFolder()
            {
                Name     = "Friends",
                Children =
                    new List <EmailElement> {
                    new EmailDocument {
                        Name = "EMail_Friend_1"
                    },
                    new EmailDocument {
                        Name = "EMail_Friend_2"
                    },
                    new EmailDocument {
                        Name = "EMail_Friend_3"
                    }
                }
            };

            rm.EmailFolders.Add(friends);

            EmailElement relatives = new EmailFolder()
            {
                Name     = "Relatives",
                Children =
                    new List <EmailElement> {
                    new EmailDocument {
                        Name = "EMail_Relatives_1"
                    },
                    new EmailDocument {
                        Name = "EMail_Relatives_2"
                    },
                    new EmailDocument {
                        Name = "EMail_Relatives_3"
                    }
                }
            };

            rm.EmailFolders.Add(relatives);
            EmailElement work = new EmailFolder()
            {
                Name     = "Work",
                Children =
                    new List <EmailElement> {
                    new EmailDocument {
                        Name = "EMail_Work_1"
                    },
                    new EmailDocument {
                        Name = "EMail_Work2"
                    },
                    new EmailDocument {
                        Name = "EMail_Work_3"
                    }
                }
            };

            rm.EmailFolders.Add(work);
            rm.EmailFolders = new List <EmailElement>
            {
                new EmailFolder {
                    Name     = "All Folders",
                    Children = rm.EmailFolders
                }
            };
            return(View(rm));
        }
Example #18
0
 public void AddToEmailFolders(EmailFolder emailFolder)
 {
     base.AddObject("EmailFolders", emailFolder);
 }
Example #19
0
 public static EmailFolder CreateEmailFolder(int mailFolderID, int customerID, int mailCount, int unreadCount, int folderSize, int mailFolderTypeID)
 {
     EmailFolder emailFolder = new EmailFolder();
     emailFolder.MailFolderID = mailFolderID;
     emailFolder.CustomerID = customerID;
     emailFolder.MailCount = mailCount;
     emailFolder.UnreadCount = unreadCount;
     emailFolder.FolderSize = folderSize;
     emailFolder.MailFolderTypeID = mailFolderTypeID;
     return emailFolder;
 }
Example #20
0
 public void NotifyEmailDeleted(EmailFolder emailFolder, Email email) => DeleteEmailAction?.Invoke(emailFolder, email);
Example #21
0
        public ActionResult TreeViewExample()
        {
            var model = new TreeViewExampleViewModel();

            model.EmailFolders = new List <EmailElement>();
            EmailElement friends = new EmailFolder()
            {
                Name     = "Friends",
                Children =
                    new List <EmailElement> {
                    new EmailDocument {
                        Name = "EMail_Friend_1"
                    },
                    new EmailDocument {
                        Name = "EMail_Friend_2"
                    },
                    new EmailDocument {
                        Name = "EMail_Friend_3"
                    }
                }
            };

            model.EmailFolders.Add(friends);

            EmailElement relatives = new EmailFolder()
            {
                Name     = "Relatives",
                Children =
                    new List <EmailElement> {
                    new EmailDocument {
                        Name = "EMail_Relatives_1"
                    },
                    new EmailDocument {
                        Name = "EMail_Relatives_2"
                    },
                    new EmailDocument {
                        Name = "EMail_Relatives_3"
                    }
                }
            };

            model.EmailFolders.Add(relatives);
            EmailElement work = new EmailFolder()
            {
                Name     = "Work",
                Children =
                    new List <EmailElement> {
                    new EmailDocument {
                        Name = "EMail_Work_1"
                    },
                    new EmailDocument {
                        Name = "EMail_Work2"
                    },
                    new EmailDocument {
                        Name = "EMail_Work_3"
                    }
                }
            };

            model.EmailFolders.Add(work);
            model.EmailFolders = new List <EmailElement>
            {
                new EmailFolder {
                    Name     = "All Folders",
                    Children = model.EmailFolders
                }
            };
            return(View(model));
        }