public MailInformation(Storage.Message message)
        {
            mSender       = message.GetEmailSender(false, false).Trim();
            mSubject      = message.Subject;
            mHtmlBody     = message.BodyHtml;
            mCreationDate = message.CreationTime;
            mAttachments  = message.Attachments;

            string recipientItems = message.GetEmailRecipients(Storage.Recipient.RecipientType.To, false, false);

            if (recipientItems.Contains(";"))
            {
                mToRecipients = GetRecipients(recipientItems).ToList();
            }
            else
            {
                mToRecipients = new List <string>()
                {
                    recipientItems
                };
            }

            recipientItems = message.GetEmailRecipients(Storage.Recipient.RecipientType.Cc, false, false);
            if (recipientItems.Contains(";"))
            {
                mCCRecipients = GetRecipients(recipientItems).ToList();
            }
            else
            {
                mCCRecipients = new List <string>();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Search for matches in the in .MSG or .OFT files.
        /// </summary>
        /// <param name="fileName">The name of the file.</param>
        /// <param name="searchTerms">The terms to search.</param>
        /// <param name="matcher">The matcher object to determine search criteria.</param>
        /// <returns>The matched lines containing the search terms.</returns>
        private List <MatchedLine> GetMatchesInMsgOftFiles(string fileName, IEnumerable <string> searchTerms, Matcher matcher)
        {
            List <MatchedLine> matchedLines = new List <MatchedLine>();

            using (var msg = new Storage.Message(fileName))
            {
                string recipients   = msg.GetEmailRecipients(RecipientType.To, false, false);
                string recipientsCc = msg.GetEmailRecipients(RecipientType.Cc, false, false);
                string headerInfo   = string.Join(", ", new string[] { msg.Sender.Raw, msg.SentOn.GetValueOrDefault().ToString(), recipients, recipientsCc, msg.Subject });

                matchedLines.AddRange(GetMatchesForHeader());
                matchedLines.AddRange(GetMatchesForBody());

                // Local function to get matches in the header part of mail.
                List <MatchedLine> GetMatchesForHeader()
                {
                    int matchCounter = 0;

                    foreach (string searchTerm in searchTerms)
                    {
                        MatchCollection matches = Regex.Matches(headerInfo, searchTerm, matcher.RegularExpressionOptions);            // Use this match for getting the locations of the match.
                        if (matches.Count > 0)
                        {
                            foreach (Match match in matches)
                            {
                                matchedLines.Add(new MatchedLine
                                {
                                    MatchId    = matchCounter++,
                                    Content    = string.Format("{0}:\t{1}", Resources.Strings.Header, headerInfo),
                                    SearchTerm = searchTerm,
                                    FileName   = fileName,
                                    LineNumber = 1,
                                    StartIndex = match.Index + Resources.Strings.Header.Length + 2,
                                    Length     = match.Length
                                });
                            }
                        }
                    }

                    return(matchedLines);
                }

                // Local function to get matches in the body of mail.
                List <MatchedLine> GetMatchesForBody()
                {
                    return(matcher.GetMatch(msg.BodyText.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries), searchTerms));
                }
            }

            return(matchedLines);
        }
Beispiel #3
0
        public void SetFile(String file)
        {
            if (string.IsNullOrWhiteSpace(file))
            {
                Logging.Error("No filename given.");
                return;
            }


            Logging.Log("File name: " + file);

            htmlPanel.Text = "";


            if (file.ToLower().EndsWith(".msg"))
            {
                using (var msg = new Storage.Message(file))
                {
                    labelDate.Text = msg.SentOn.ToString();
                    labelFrom.Text = (msg.Sender != null ? msg.Sender.DisplayName + " <" + msg.Sender.Email + ">" : "");
                    labelTo.Text   = msg.GetEmailRecipients(Storage.Recipient.RecipientType.To, false, false);
                    //labelTo.Text += " | " + msg.GetEmailRecipients(Storage.Recipient.RecipientType.Cc, false, false);
                    labelSubject.Text     = msg.Subject;
                    labelAttachments.Text = msg.Attachments.Count.ToString();
                    htmlPanel.Text        = (string.IsNullOrWhiteSpace(msg.BodyHtml) ? msg.BodyText : msg.BodyHtml);
                }
            }
            if (file.ToLower().EndsWith(".eml"))
            {
                var msg = MimeMessage.Load(file);
                labelDate.Text = msg.Date.ToLocalTime().ToString();
                labelFrom.Text = (msg.From != null ? msg.From.ToString() : "");
                labelTo.Text   = (msg.To != null ? msg.To.ToString() : "");
                //labelTo.Text += " | " + msg.Cc.ToString();
                labelSubject.Text     = msg.Subject;
                labelAttachments.Text = msg.Attachments.Count().ToString();
                htmlPanel.Text        = (string.IsNullOrWhiteSpace(msg.HtmlBody) ? (string.IsNullOrWhiteSpace(msg.TextBody) ? "" : msg.TextBody) : msg.HtmlBody);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Maps all the filled <see cref="Storage.Message"/> properties to the corresponding extended file attributes
        /// </summary>
        /// <param name="message">The <see cref="Storage.Message"/> object</param>
        /// <param name="propertyWriter">The <see cref="ShellPropertyWriter"/> object</param>
        private void MapEmailPropertiesToExtendedFileAttributes(Storage.Message message, ShellPropertyWriter propertyWriter)
        {
            // From
            propertyWriter.WriteProperty(SystemProperties.System.Message.FromAddress, message.Sender.Email);
            propertyWriter.WriteProperty(SystemProperties.System.Message.FromName, message.Sender.DisplayName);

            // Sent on
            propertyWriter.WriteProperty(SystemProperties.System.Message.DateSent, message.SentOn);

            // To
            propertyWriter.WriteProperty(SystemProperties.System.Message.ToAddress,
                                         message.GetEmailRecipients(RecipientType.To, false, false));

            // CC
            propertyWriter.WriteProperty(SystemProperties.System.Message.CcAddress,
                                         message.GetEmailRecipients(RecipientType.Cc, false, false));

            // BCC
            propertyWriter.WriteProperty(SystemProperties.System.Message.BccAddress,
                                         message.GetEmailRecipients(RecipientType.Bcc, false, false));

            // Subject
            propertyWriter.WriteProperty(SystemProperties.System.Subject, message.Subject);

            // Urgent
            propertyWriter.WriteProperty(SystemProperties.System.Importance, message.Importance);
            propertyWriter.WriteProperty(SystemProperties.System.ImportanceText, message.ImportanceText);

            // Attachments
            var attachments = message.GetAttachmentNames();

            if (string.IsNullOrEmpty(attachments))
            {
                propertyWriter.WriteProperty(SystemProperties.System.Message.HasAttachments, false);
                propertyWriter.WriteProperty(SystemProperties.System.Message.AttachmentNames, null);
            }
            else
            {
                propertyWriter.WriteProperty(SystemProperties.System.Message.HasAttachments, true);
                propertyWriter.WriteProperty(SystemProperties.System.Message.AttachmentNames, attachments);
            }

            // Clear properties
            propertyWriter.WriteProperty(SystemProperties.System.StartDate, null);
            propertyWriter.WriteProperty(SystemProperties.System.DueDate, null);
            propertyWriter.WriteProperty(SystemProperties.System.DateCompleted, null);
            propertyWriter.WriteProperty(SystemProperties.System.IsFlaggedComplete, null);
            propertyWriter.WriteProperty(SystemProperties.System.FlagStatusText, null);

            // Follow up
            if (message.Flag != null)
            {
                propertyWriter.WriteProperty(SystemProperties.System.IsFlagged, true);
                propertyWriter.WriteProperty(SystemProperties.System.FlagStatusText, message.Flag.Request);

                // Flag status text
                propertyWriter.WriteProperty(SystemProperties.System.FlagStatusText, message.Task.StatusText);

                // When complete
                if (message.Task.Complete != null && (bool)message.Task.Complete)
                {
                    // Flagged complete
                    propertyWriter.WriteProperty(SystemProperties.System.IsFlaggedComplete, true);

                    // Task completed date
                    if (message.Task.CompleteTime != null)
                    {
                        propertyWriter.WriteProperty(SystemProperties.System.DateCompleted, (DateTime)message.Task.CompleteTime);
                    }
                }
                else
                {
                    // Flagged not complete
                    propertyWriter.WriteProperty(SystemProperties.System.IsFlaggedComplete, false);

                    propertyWriter.WriteProperty(SystemProperties.System.DateCompleted, null);

                    // Task startdate
                    if (message.Task.StartDate != null)
                    {
                        propertyWriter.WriteProperty(SystemProperties.System.StartDate, (DateTime)message.Task.StartDate);
                    }

                    // Task duedate
                    if (message.Task.DueDate != null)
                    {
                        propertyWriter.WriteProperty(SystemProperties.System.DueDate, (DateTime)message.Task.DueDate);
                    }
                }
            }

            // Categories
            var categories = message.Categories;

            if (categories != null)
            {
                propertyWriter.WriteProperty(SystemProperties.System.Category, String.Join("; ", String.Join("; ", categories)));
            }
        }