This class is responsible for parsing a string array of lines containing a MIME message.
예제 #1
0
 /// <summary>
 /// Sets the type of the content.
 /// </summary>
 /// <param name="contentType">
 /// Type of the content.
 /// </param>
 internal void SetContentType(ContentType contentType)
 {
     this._contentType           = contentType;
     this._contentType.MediaType = MimeReader.GetMediaType(contentType.MediaType);
     this._mediaMainType         = MimeReader.GetMediaMainType(contentType.MediaType);
     this._mediaSubType          = MimeReader.GetMediaSubType(contentType.MediaType);
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeEntity"/> class.
 /// </summary>
 public MimeEntity()
 {
     this._children       = new List <MimeEntity>();
     this._headers        = new NameValueCollection();
     this._contentType    = MimeReader.GetContentType(string.Empty);
     this.Parent          = null;
     this._encodedMessage = new StringBuilder();
 }
예제 #3
0
        /// <summary>
        /// Adds the child entity.
        /// </summary>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <param name="lines">
        /// The lines.
        /// </param>
        private void AddChildEntity(MimeEntity entity, Queue <string> lines)
        {
            /*if (entity == null)
             * {
             *              return;
             * }
             *
             * if (lines == null)
             * {
             *              return;
             * }*/
            var reader = new MimeReader(entity, lines);

            entity.Children.Add(reader.CreateMimeEntity());
        }
예제 #4
0
 private static MailMessageEx GetMailMessage(string file)
 {
     var allLines = File.ReadAllLines(file);
     var mimeReader = new MimeReader(allLines);
     return mimeReader.CreateMimeEntity().ToMailMessageEx();
 }
예제 #5
0
        /// <summary>
        /// Adds the child entity.
        /// </summary>
        /// <param name="entity">
        /// The entity. 
        /// </param>
        /// <param name="lines">
        /// The lines. 
        /// </param>
        private void AddChildEntity(MimeEntity entity, Queue<string> lines)
        {
            /*if (entity == null)
            {
                    return;
            }

            if (lines == null)
            {
                    return;
            }*/
            var reader = new MimeReader(entity, lines);
            entity.Children.Add(reader.CreateMimeEntity());
        }
예제 #6
0
        /// <summary>
        ///     The messages list_ selection changed.
        /// </summary>
        /// <param name="sender">
        ///     The sender.
        /// </param>
        /// <param name="e">
        ///     The e.
        /// </param>
        private void messagesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var setTitle = new Action<string>(
                t =>
                {
                    this.Subject.Content = t;
                    this.Subject.ToolTip = t;
                });

            // If there are no selected items, then disable the Delete button, clear the boxes, and return
            if (e.AddedItems.Count == 0)
            {
                this.deleteButton.IsEnabled = false;
                this.forwardButton.IsEnabled = false;
                this.rawView.Text = string.Empty;
                this.bodyView.Text = string.Empty;
                this.htmlViewTab.Visibility = Visibility.Hidden;
                this.tabControl.SelectedIndex = this.defaultTab.IsVisible ? 0 : 1;

                // Clear fields
                this.FromEdit.Text = string.Empty;
                this.ToEdit.Text = string.Empty;
                this.CCEdit.Text = string.Empty;
                this.BccEdit.Text = string.Empty;
                this.DateEdit.Text = string.Empty;

                var subject = string.Empty;
                this.SubjectEdit.Text = subject;

                this.defaultBodyView.Text = string.Empty;

                this.defaultHtmlView.Content = null;
                this.defaultHtmlView.NavigationService.RemoveBackEntry();
                //this.defaultHtmlView.Refresh();

                setTitle("Papercut");

                return;
            }

            var mailFile = ((MessageEntry)e.AddedItems[0]).File;

            try
            {
                this.tabControl.IsEnabled = false;
                this.SpinAnimation.Visibility = Visibility.Visible;
                setTitle("Loading...");

                if (this._currentMessageCancellationTokenSource != null)
                {
                    this._currentMessageCancellationTokenSource.Cancel();
                }

                this._currentMessageCancellationTokenSource = new CancellationTokenSource();

                Task.Factory.StartNew(() => { })
                    .ContinueWith(
                        task => File.ReadAllLines(mailFile, Encoding.ASCII),
                        this._currentMessageCancellationTokenSource.Token,
                        TaskContinuationOptions.NotOnCanceled,
                        TaskScheduler.Default)
                    .ContinueWith(
                        task =>
                        {
                            // Load the MIME body
                            var mimeReader = new MimeReader(task.Result);
                            MimeEntity me = mimeReader.CreateMimeEntity();

                            return Tuple.Create(task.Result, me.ToMailMessageEx());
                        },
                        this._currentMessageCancellationTokenSource.Token,
                        TaskContinuationOptions.NotOnCanceled,
                        TaskScheduler.Default).ContinueWith(
                            task =>
                            {
                                var resultTuple = task.Result;
                                var mailMessageEx = resultTuple.Item2;

                                // set the raw view...
                                this.rawView.Text = string.Join("\n", resultTuple.Item1);

                                this.bodyView.Text = mailMessageEx.Body;
                                this.bodyViewTab.Visibility = Visibility.Visible;

                                this.defaultBodyView.Text = mailMessageEx.Body;

                                this.FromEdit.Text = mailMessageEx.From.IfNotNull(s => s.ToString()) ?? string.Empty;
                                this.ToEdit.Text = mailMessageEx.To.IfNotNull(s => s.ToString()) ?? string.Empty;
                                this.CCEdit.Text = mailMessageEx.CC.IfNotNull(s => s.ToString()) ?? string.Empty;
                                this.BccEdit.Text = mailMessageEx.Bcc.IfNotNull(s => s.ToString()) ?? string.Empty;
                                this.DateEdit.Text = mailMessageEx.DeliveryDate.IfNotNull(s => s.ToString()) ?? string.Empty;

                                var subject = mailMessageEx.Subject.IfNotNull(s => s.ToString()) ?? string.Empty;
                                this.SubjectEdit.Text = subject;

                                setTitle(subject);

                                // If it is HTML, render it to the HTML view
                                if (mailMessageEx.IsBodyHtml)
                                {
                                    if (task.IsCanceled)
                                    {
                                        return;
                                    }

                                    this.SetBrowserDocument(mailMessageEx);
                                    this.htmlViewTab.Visibility = Visibility.Visible;

                                    this.defaultHtmlView.Visibility = Visibility.Visible;
                                    this.defaultBodyView.Visibility = Visibility.Collapsed;
                                }
                                else
                                {
                                    this.htmlViewTab.Visibility = Visibility.Hidden;
                                    if (this.defaultTab.IsVisible)
                                    {
                                        this.tabControl.SelectedIndex = 0;
                                    }
                                    else if (Equals(this.tabControl.SelectedItem, this.htmlViewTab))
                                    {
                                        this.tabControl.SelectedIndex = 2;
                                    }

                                    this.defaultHtmlView.Visibility = Visibility.Collapsed;
                                    this.defaultBodyView.Visibility = Visibility.Visible;
                                }

                                this.SpinAnimation.Visibility = Visibility.Collapsed;
                                this.tabControl.IsEnabled = true;

                                // Enable the delete and forward button
                                this.deleteButton.IsEnabled = true;
                                this.forwardButton.IsEnabled = true;
                            },
                            this._currentMessageCancellationTokenSource.Token,
                            TaskContinuationOptions.NotOnCanceled,
                            TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                Logger.WriteWarning(string.Format(@"Unable to Load Message ""{0}"": {1}", mailFile, ex));

                setTitle("Papercut");
                this.tabControl.SelectedIndex = 1;
                this.bodyViewTab.Visibility = Visibility.Hidden;
                this.htmlViewTab.Visibility = Visibility.Hidden;
            }
        }