예제 #1
0
        private void MessagesGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            DisplayedMessage message = (DisplayedMessage)MessagesGrid.SelectedItem;

            if (message != null)
            {
                Label fromLabel    = (Label)LogicalTreeHelper.FindLogicalNode(this, "fromLabel");
                Label subjectLabel = (Label)LogicalTreeHelper.FindLogicalNode(this, "subjectLabel");
                Label toLabel      = (Label)LogicalTreeHelper.FindLogicalNode(this, "toLabel");

                AttachmentList.Children.Clear();

                foreach (Attachment attachment in message.Message.Attachments)
                {
                    FileListItem listItem = new FileListItem(new FileModel(attachment, DateTime.Today));
                    AttachmentList.Children.Add(listItem);
                }

                MessageContainer.Visibility = Visibility.Collapsed;

                fromLabel.Content    = message.Message.From;
                subjectLabel.Content = message.Subject;
                toLabel.Content      = message.Message.To[0];

                if (_messageWorker.IsBusy)
                {
                    _queuedMessage = message;
                }
                else
                {
                    _messageWorker.RunWorkerAsync(message);
                }
            }
        }
예제 #2
0
        private void MessageWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            DisplayedMessage message = (DisplayedMessage)e.Argument;

            message.Message.Download(ImapX.Enums.MessageFetchMode.Body);

            e.Result = message;
        }
예제 #3
0
        private void FillMessages(List <Message> messages)
        {
            ObservableCollection <DisplayedMessage> displayedMessages = new ObservableCollection <DisplayedMessage>();

            if (messages.Count > 0)
            {
                foreach (Message message in messages)
                {
                    DisplayedMessage displayedMessage = new DisplayedMessage(message,
                                                                             message.Subject.Replace("\n", "").Replace("\r", "").Trim(' '),
                                                                             message.From.DisplayName == "" ? message.From.Address : message.From.DisplayName,
                                                                             message.Date.Value,
                                                                             message.Seen);

                    displayedMessages.Add(displayedMessage);
                }
                BindingOperations.EnableCollectionSynchronization(displayedMessages, new object());
                MessagesGrid.ItemsSource = displayedMessages;
                MessagesGrid.Items.Refresh();

                MessagesGrid.Columns.Where(column => column.Header.ToString() == "Message").ToList <DataGridColumn>()[0].Visibility = Visibility.Collapsed;
                MessagesGrid.Columns.Where(column => column.Header.ToString() == "Seen").ToList <DataGridColumn>()[0].Visibility    = Visibility.Collapsed;
                MessagesGrid.Columns.Where(column => column.Header.ToString() == "Subject").ToList <DataGridColumn>()[0].Width      = new DataGridLength(3, DataGridLengthUnitType.Star);
                MessagesGrid.Columns.Where(column => column.Header.ToString() == "From").ToList <DataGridColumn>()[0].Width         = new DataGridLength(1, DataGridLengthUnitType.Star);
                MessagesGrid.Columns.Where(column => column.Header.ToString() == "Date").ToList <DataGridColumn>()[0].Width         = new DataGridLength(1, DataGridLengthUnitType.Star);

                MessagesGrid.Columns.Where(column => column.Header.ToString() == "Subject").ToList <DataGridColumn>()[0].Header = "Temat";
                MessagesGrid.Columns.Where(column => column.Header.ToString() == "From").ToList <DataGridColumn>()[0].Header    = "Od";
                MessagesGrid.Columns.Where(column => column.Header.ToString() == "Date").ToList <DataGridColumn>()[0].Header    = "Data";

                MessagesGrid.Visibility    = Visibility.Visible;
                NoMessagesLabel.Visibility = Visibility.Collapsed;
            }
            else
            {
                MessagesGrid.Visibility    = Visibility.Collapsed;
                NoMessagesLabel.Visibility = Visibility.Visible;
            }
        }
예제 #4
0
        private void MessagesGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            for (int i = 0; i < MessagesGrid.Items.Count; i++)
            {
                DataGridRow row = (DataGridRow)MessagesGrid.ItemContainerGenerator.ContainerFromIndex(i);

                if (row != null)
                {
                    Rect  rowRect       = VisualTreeHelper.GetDescendantBounds(row);
                    Point mousePosition = e.GetPosition(row);

                    if (rowRect.Contains(mousePosition))
                    {
                        DisplayedMessage selectedMessage = (DisplayedMessage)MessagesGrid.Items[i];

                        DragDropEffects dragdropeffects = DragDropEffects.Copy;
                        DragDrop.DoDragDrop(MessagesGrid, selectedMessage, dragdropeffects);
                        MessagesGrid.SelectedItem = selectedMessage;
                    }
                }
            }
        }
예제 #5
0
        private void MessageWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            try
            {
                DisplayedMessage message = (DisplayedMessage)e.Result;

                if (!message.Message.Seen)
                {
                    message.Message.Seen = true;
                    message.Seen         = true;
                    EmailModel client = (EmailModel)EmailTreeList.SelectedNode.ChildObject;
                    client.UnseenCount--;
                }

                HtmlPanel messageContainer = (HtmlPanel)LogicalTreeHelper.FindLogicalNode(this, "MessageContainer");

                if (_queuedMessage == null)
                {
                    _queuedMessage = null;

                    messageContainer.Text = !message.Message.Body.HasHtml
                        ? message.Message.Body.Text
                        : " <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'>" +
                                            message.Message.Body.Html;
                }
                else
                {
                    _messageWorker.RunWorkerAsync(_queuedMessage);
                    _queuedMessage = null;
                }
                messageContainer.Visibility        = Visibility.Visible;
                MessageDetailsContainer.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
            }
        }
예제 #6
0
        public void Init()
        {
            EmailList.AddNewEmailAddress      += EmailList_AddNewEmailAddress;
            EmailTreeList.SelectedNodeChanged += EmailTree_SelectedNodeChanged;
            MessagesGrid.SelectionMode         = DataGridSelectionMode.Single;
            SmallToolBarWideButton removeButton = new SmallToolBarWideButton("Usuń");

            removeButton.Click += (s, ea) =>
            {
                EmailModel email = (EmailModel)EmailTreeList.SelectedNode.ChildObject;

                DisplayedMessage message = (DisplayedMessage)MessagesGrid.SelectedItem;

                if (message != null)
                {
                    int index = MessagesGrid.SelectedIndex;

                    email.UnhandledMessages.Remove(message.Message);
                    ObservableCollection <DisplayedMessage> messages =
                        (ObservableCollection <DisplayedMessage>)MessagesGrid.ItemsSource;

                    messages.Remove(message);

                    MessagesGrid.ItemsSource = messages;
                    MessagesGrid.Items.Refresh();

                    _client.HandleMessage(email.Id, message.Message.UId.ToString());

                    MessagesGrid.SelectedIndex = index == 0 ? index : index - 1;

                    if (MessagesGrid.Items.Count == 0)
                    {
                        MessagesGrid.Visibility    = Visibility.Collapsed;
                        NoMessagesLabel.Visibility = Visibility.Visible;

                        MessageContainer.Visibility        = Visibility.Collapsed;
                        MessageDetailsContainer.Visibility = Visibility.Collapsed;
                    }
                }

                _parent.NewEmailAddress += _parent_NewEmailAddress;
            };

            SmallToolBarWideButton removeFromServerButton = new SmallToolBarWideButton("Usuń całkowicie");

            removeFromServerButton.Click += (s, ea) =>
            {
                EmailModel email = (EmailModel)EmailTreeList.SelectedNode.ChildObject;

                DisplayedMessage message = (DisplayedMessage)MessagesGrid.SelectedItem;

                if (message != null)
                {
                    message.Message.Remove();

                    int index = MessagesGrid.SelectedIndex;

                    email.UnhandledMessages.Remove(message.Message);
                    ObservableCollection <DisplayedMessage> messages =
                        (ObservableCollection <DisplayedMessage>)MessagesGrid.ItemsSource;

                    messages.Remove(message);

                    MessagesGrid.ItemsSource = messages;
                    MessagesGrid.Items.Refresh();

                    _client.HandleMessage(email.Id, message.Message.UId.ToString());

                    MessagesGrid.SelectedIndex = index == 0 ? index : index - 1;
                }

                if (MessagesGrid.Items.Count == 0)
                {
                    MessagesGrid.Visibility    = Visibility.Collapsed;
                    NoMessagesLabel.Visibility = Visibility.Visible;

                    MessageContainer.Visibility        = Visibility.Collapsed;
                    MessageDetailsContainer.Visibility = Visibility.Collapsed;
                }
            };

            MessageDetailsMenuStrip.Children.Add(removeButton);

            MessageDetailsContainer.Visibility = Visibility.Collapsed;
            MessageDetailsMenuStrip.Children.Add(removeFromServerButton);

            ConversationList.DisplayItemContextMenus = false;

            _dragIndicator = new DragIndicator();
            _dragAddCursor = new Cursor(new FileStream("../../resources/addMessage_cursor.cur", FileMode.Open));


            _messageWorker.WorkerSupportsCancellation = true;
            _messageWorker.DoWork             += MessageWorker_DoWork;
            _messageWorker.RunWorkerCompleted += MessageWorker_RunWorkerCompleted;

            Unloaded += Email_Unloaded;

            _parent = (MainWindow)Window.GetWindow(this);
            _client = _parent.Client;

            if (_parent.EmailClients != null)
            {
                _emailClients = _parent.EmailClients;
                LoadFolders(_emailClients);
            }

            _parent.EmailWorker.RunWorkerCompleted += _emailWorker_RunWorkerCompleted;

            if (_parent.ConversationWorker.IsBusy)
            {
                _parent.ConversationWorker.RunWorkerCompleted += ConversationWorker_RunWorkerCompleted;
            }
            else
            {
                if (_parent.Conversations != null)
                {
                    _conversations = _parent.Conversations;
                    LoadConversations();
                }
            }

            MessagesGrid.Items.IsLiveSorting = true;
            // MessagesGrid.SelectionMode = DataGridSelectionMode.Extended;


            MessagesGrid.PreviewMouseLeftButtonDown += MessagesGrid_PreviewMouseLeftButtonDown;
            MessagesGrid.GiveFeedback += MessagesGrid_GiveFeedback;

            _processingWorker.DoWork += _processingWorker_DoWork;

            ConversationList.AllowDrop = true;

            WindowInitialized = true;
        }
예제 #7
0
        private void ConversationItem_Drop(object sender, DragEventArgs e)
        {
            try
            {
                ConversationListItem item = (ConversationListItem)sender;

                if (e.Data.GetDataPresent(typeof(DisplayedMessage)))
                {
                    string           conversationId = item.Conversation.Id;
                    DisplayedMessage message        = (DisplayedMessage)e.Data.GetData(typeof(DisplayedMessage));
                    PersonModel      messageSender  =
                        _parent.Persons.Find(
                            obj => obj.EmailAddresses.Any(obj2 => obj2.Address == message.Message.From.Address));

                    if (conversationId != null)
                    {
                        if (messageSender != null)
                        {
                            AddToProcess(conversationId, message.Message);

                            //EmailAddressModel authorEmailAddress =
                            //    messageSender.EmailAddresses.Single(obj => obj.Address == message.Message.From.Address);

                            //ConversationMessageModel receivedMessage = new ConversationMessageModel(messageSender,
                            //    message.Message.InternalDate);
                            //ConversationEmailMessageModel emailMessage =
                            //    new ConversationEmailMessageModel(receivedMessage, authorEmailAddress, message.Subject,
                            //        message.Message.Body.Html == "" ? message.Message.Body.Text : message.Message.Body.Html)
                            //    { ConversationId = conversationId };

                            //if (_processingWorker.IsBusy)
                            //{
                            //    _unprocessedMessages.Add(emailMessage);
                            //}
                            //else
                            //{
                            //    _processingWorker.RunWorkerAsync(emailMessage);
                            //}

                            EmailModel email = (EmailModel)EmailTreeList.SelectedNode.ChildObject;
                            email.UnhandledMessages.Remove(message.Message);
                            ObservableCollection <DisplayedMessage> messages = (ObservableCollection <DisplayedMessage>)MessagesGrid.ItemsSource;

                            messages.Remove(message);

                            MessagesGrid.ItemsSource = messages;
                            MessagesGrid.Items.Refresh();

                            _client.HandleMessage(email.Id, message.Message.UId.ToString());
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }