コード例 #1
0
        private void UpdateCurrentMessage(MessageView mv)
        {
            CurrentMessage = mv;
            if (mv != null)
            {
                CurrentProperties.PopulateWith(mv.Properties);
            }
            else
            {
                CurrentProperties.Clear();
            }

            OnPropertyChanged(
                nameof(CurrentMessage),
                nameof(CurrentProperties),
                nameof(IsMessagePresent),
                nameof(CanExportProperties),
                nameof(CanPopMessage),
                nameof(IsAttachmentPresent),
                nameof(IsFileAttachmentPresent),
                nameof(IsFileAttachmentSelected),
                nameof(IsEmailAttachmentPresent),
                nameof(IsEmailAttachmentSelected)
                );
        }
コード例 #2
0
        private void OpenEmailAttachment(Attachment a)
        {
            Message m  = xstFile.OpenAttachedMessage(a);
            var     mv = new MessageView(m);

            ShowMessage(mv);
            view.PushMessage(mv);
        }
コード例 #3
0
 public void SetMessage(MessageView mv)
 {
     if (CurrentMessage != null)
     {
         CurrentMessage.ClearContents();
     }
     stackMessage.Clear();
     UpdateCurrentMessage(mv);
 }
コード例 #4
0
        private void listMessages_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            searchIndex = listMessages.SelectedIndex;
            searchTextBox.ShowSearch = true;
            MessageView mv = (MessageView)listMessages.SelectedItem;

            if (mv != null)
            {
                try
                {
                    xstFile.ReadMessageDetails(mv.Message);
                    ShowMessage(mv);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error reading message details");
                }
            }
            view.SetMessage(mv);
        }
コード例 #5
0
        private bool PropertyHitTest(int index, string text, bool subject, bool fromTo, bool date, bool cc, bool bcc)
        {
            MessageView mv = listMessages.Items[index] as MessageView;

            if ((subject && mv.Subject != null && mv.Subject.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0) ||
                (fromTo && mv.FromTo != null && mv.FromTo.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0) ||
                (date && mv.DisplayDate.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0) ||
                (cc && mv.CcDisplayList.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0) ||
                (bcc && mv.BccDisplayList.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0))
            {
                searchIndex = index;
                listMessages.UnselectAll();
                mv.IsSelected = true;
                listMessages.ScrollIntoView(mv);
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #6
0
 public void PushMessage(MessageView mv)
 {
     stackMessage.Push(CurrentMessage);
     UpdateCurrentMessage(mv);
 }
コード例 #7
0
        private void ShowMessage(MessageView mv)
        {
            try
            {
                //clear any existing status
                ShowStatus(null);

                if (mv != null)
                {
                    //email is signed and/or encrypted and no body was included
                    if (mv.IsEncryptedOrSigned)
                    {
                        try
                        {
                            mv.ReadSignedOrEncryptedMessage(xstFile);
                        }
                        catch
                        {
                            ShowStatus("Message Failed to Decrypt");
                        }
                    }

                    // Populate the view of the attachments
                    mv.SortAndSaveAttachments(mv.Message.Attachments);

                    // Can't bind HTML content, so push it into the control, if the message is HTML
                    if (mv.ShowHtml)
                    {
                        string body = mv.Message.GetBodyAsHtmlString();
                        if (mv.MayHaveInlineAttachment)
                        {
                            body = mv.Message.EmbedAttachments(body, xstFile);  // Returns null if this is not appropriate
                        }
                        if (body != null)
                        {
                            // For testing purposes, can show print header in main visualisation
                            if (view.DisplayPrintHeaders)
                            {
                                body = mv.Message.EmbedHtmlPrintHeader(body, view.DisplayEmailType);
                            }

                            wbMessage.NavigateToString(body);
                            if (mv.MayHaveInlineAttachment)
                            {
                                mv.SortAndSaveAttachments();  // Re-sort attachments in case any new in-line rendering discovered
                            }
                        }
                    }
                    // Can't bind RTF content, so push it into the control, if the message is RTF
                    else if (mv.ShowRtf)
                    {
                        var body = mv.Message.GetBodyAsFlowDocument();

                        // For testing purposes, can show print header in main visualisation
                        if (view.DisplayPrintHeaders)
                        {
                            mv.Message.EmbedRtfPrintHeader(body, view.DisplayEmailType);
                        }

                        rtfMessage.Document = body;
                    }
                    // Could bind text content, but use push so that we can optionally add headers
                    else if (mv.ShowText)
                    {
                        var body = mv.Body;

                        // For testing purposes, can show print header in main visualisation
                        if (view.DisplayPrintHeaders)
                        {
                            body = mv.Message.EmbedTextPrintHeader(body, true, view.DisplayEmailType);
                        }

                        txtMessage.Text = body;
                        scrollTextMessage.ScrollToHome();
                    }
                }
                else
                {
                    // Clear the displays, in case we were showing that type before
                    wbMessage.Navigate("about:blank");
                    rtfMessage.Document.Blocks.Clear();
                    txtMessage.Text = "";
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error reading message body");
            }
        }
コード例 #8
0
        private void ExportEmails(IEnumerable <MessageView> messages)
        {
            string folderName = GetEmailsExportFolderName();

            if (folderName != null)
            {
                ShowStatus("Exporting emails...");
                Mouse.OverrideCursor = Cursors.Wait;

                // Export emails on a background thread so we can keep the UI in sync
                Task.Factory.StartNew <Tuple <int, int> >(() =>
                {
                    MessageView current = null;
                    int good            = 0, bad = 0;
                    // If files already exist, we overwrite them.
                    // But if emails within this batch generate the same filename,
                    // use a numeric suffix to distinguish them
                    HashSet <string> usedNames = new HashSet <string>();
                    foreach (MessageView mv in messages)
                    {
                        try
                        {
                            current         = mv;
                            string fileName = mv.ExportFileName;
                            for (int i = 1; ; i++)
                            {
                                if (!usedNames.Contains(fileName))
                                {
                                    usedNames.Add(fileName);
                                    break;
                                }
                                else
                                {
                                    fileName = String.Format("{0} ({1})", mv.ExportFileName, i);
                                }
                            }
                            Application.Current.Dispatcher.Invoke(new Action(() =>
                            {
                                ShowStatus("Exporting " + mv.ExportFileName);
                            }));
                            // Ensure that we have the message contents
                            xstFile.ReadMessageDetails(mv.Message);
                            var fullFileName = String.Format(@"{0}\{1}.{2}",
                                                             folderName, fileName, mv.Message.ExportFileExtension);
                            mv.Message.ExportToFile(fullFileName, xstFile);
                            xstFile.SaveVisibleAttachmentsToAssociatedFolder(fullFileName, mv.Message);
                            good++;
                        }
                        catch (System.Exception ex)
                        {
                            var result = MessageBox.Show(String.Format("Error '{0}' exporting email '{1}'",
                                                                       ex.Message, current.Subject), "Error exporting emails",
                                                         MessageBoxButton.OKCancel);
                            bad++;
                            if (result == MessageBoxResult.Cancel)
                            {
                                break;
                            }
                        }
                    }
                    return(new Tuple <int, int>(good, bad));
                })
                // When exporting completes, update the UI using the UI thread
                .ContinueWith((task) =>
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        ShowStatus(null);
                        Mouse.OverrideCursor = null;
                        txtStatus.Text       = String.Format("Completed with {0} successes and {1} failures",
                                                             task.Result.Item1, task.Result.Item2);
                    }));
                });
            }
        }