public MessageHeaderViewModel(Message message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message", "MessageHeaderViewModel constructor was expecting a Message object; received null.");
            }

            Message = message;
            Date    = ImapParser.ParseDate(Message.DateString);
            Message.PropertyChanged += HandleModelPropertyChanged;
        }
        private void SetMessage(Message newMessage)
        {
            if (Message != null)
            {
                Message.PropertyChanged -= HandleModelPropertyChanged;
            }

            Message = newMessage;
            Message.PropertyChanged += HandleModelPropertyChanged;

            Date = ImapParser.ParseDate(Message.DateString);

            if (string.IsNullOrEmpty(Message.Body))
            {
                DownloadMessageBodyAsync();
            }
            else
            {
                // Loading a message whose body has already been downloaded.
                TextBody          = MimeUtility.GetTextBody(Message.Body);
                HtmlBody          = MimeUtility.GetHtmlBody(Message.Body);
                ProcessedHtmlBody = ProcessHtmlBody(HtmlBody);
                LoadAttachments(Message.Body);

                if (!Message.IsSeen)
                {
                    // Set the \Seen flag.
                    Message.IsSeen = true;
                    DatabaseManager.Update(Message);

                    Task.Run(() => {
                        ImapClient imap = new ImapClient(notification.SelectedAccount);
                        if (imap.Connect())
                        {
                            // Not readonly because we need to set the \Seen flag.
                            bool readOnly = false;
                            if (imap.SelectMailbox(notification.SelectedMailbox.DirectoryPath, readOnly))
                            {
                                imap.SetFlag(ImapClient.FlagAction.Add, Message.Uid, "\\Seen");
                            }

                            imap.Disconnect();
                        }
                    });
                }
            }
        }
Exemple #3
0
        private void HandleModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "AccountName":
            case "MailboxPath":
            case "Subject":
            case "SenderAddress":
            case "SenderName":
            case "IsSeen":
                OnPropertyChanged(e.PropertyName);
                break;

            case "DateString":
                Date = ImapParser.ParseDate(Message.DateString);
                break;
            }
        }
Exemple #4
0
        private void HandleModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case "Subject":
            case "Sender":
            case "Recipient":
                OnPropertyChanged(e.PropertyName);
                break;

            case "DateString":
                Date = ImapParser.ParseDate(Message.DateString);
                break;

            case "Body":
                TextBody       = MimeUtility.GetTextBody(Message.Body);
                HtmlBody       = MimeUtility.GetHtmlBody(Message.Body);
                BrowserContent = PrepareBrowserContent(HtmlBody);
                OnPropertyChanged(e.PropertyName);
                break;
            }
        }