コード例 #1
0
ファイル: Reader.cs プロジェクト: iraychen/MSGReader
        /// <summary>
        /// Writes the body of the MSG Appointment to html or text and extracts all the attachments. The
        /// result is returned as a List of strings
        /// </summary>
        /// <param name="message"><see cref="Storage.Message"/></param>
        /// <param name="outputFolder">The folder where we need to write the output</param>
        /// <param name="hyperlinks">When true then hyperlinks are generated for the To, CC, BCC and attachments</param>
        /// <returns></returns>
        private List<string> WriteMsgAppointment(Storage.Message message, string outputFolder, bool hyperlinks)
        {
            var fileName = "appointment";
            bool htmlBody;
            string body;
            string dummy;
            List<string> attachmentList;
            List<string> files;

            PreProcessMsgFile(message,
                hyperlinks,
                outputFolder,
                ref fileName,
                out htmlBody,
                out body,
                out dummy,
                out attachmentList,
                out files);

            if (!htmlBody)
                hyperlinks = false;

            var maxLength = 0;

            // Calculate padding width when we are going to write a text file
            if (!htmlBody)
            {
                var languageConsts = new List<string>
                {
                    #region LanguageConsts
                    LanguageConsts.AppointmentSubjectLabel,
                    LanguageConsts.AppointmentLocationLabel,
                    LanguageConsts.AppointmentStartDateLabel,
                    LanguageConsts.AppointmentEndDateLabel,
                    LanguageConsts.AppointmentRecurrenceTypeLabel,
                    LanguageConsts.AppointmentClientIntentLabel,
                    LanguageConsts.AppointmentOrganizerLabel,
                    LanguageConsts.AppointmentRecurrencePaternLabel,
                    LanguageConsts.AppointmentOrganizerLabel,
                    LanguageConsts.AppointmentMandatoryParticipantsLabel,
                    LanguageConsts.AppointmentOptionalParticipantsLabel,
                    LanguageConsts.AppointmentCategoriesLabel,
                    LanguageConsts.ImportanceLabel,
                    LanguageConsts.TaskDateCompleted,
                    LanguageConsts.EmailCategoriesLabel
                    #endregion
                };

                maxLength = languageConsts.Select(languageConst => languageConst.Length).Concat(new[] {0}).Max() + 2;
            }

            var appointmentHeader = new StringBuilder();

            // Start of table
            WriteHeaderStart(appointmentHeader, htmlBody);

            // Subject
            WriteHeaderLine(appointmentHeader, htmlBody, maxLength, LanguageConsts.AppointmentSubjectLabel,
                message.Subject);

            // Location
            WriteHeaderLine(appointmentHeader, htmlBody, maxLength, LanguageConsts.AppointmentLocationLabel,
                message.Appointment.Location);

            // Empty line
            WriteHeaderEmptyLine(appointmentHeader, htmlBody);

            // Start
            if (message.Appointment.Start != null)
                WriteHeaderLine(appointmentHeader, htmlBody, maxLength, LanguageConsts.AppointmentStartDateLabel,
                    ((DateTime) message.Appointment.Start).ToString(LanguageConsts.DataFormatWithTime));

            // End
            if (message.Appointment.End != null)
                WriteHeaderLine(appointmentHeader, htmlBody, maxLength,
                    LanguageConsts.AppointmentEndDateLabel,
                    ((DateTime) message.Appointment.End).ToString(LanguageConsts.DataFormatWithTime));

            // Empty line
            WriteHeaderEmptyLine(appointmentHeader, htmlBody);

            // Recurrence type
            if (!string.IsNullOrEmpty(message.Appointment.RecurrenceTypeText))
                WriteHeaderLine(appointmentHeader, htmlBody, maxLength, LanguageConsts.AppointmentRecurrenceTypeLabel,
                    message.Appointment.RecurrenceTypeText);

            // Recurrence patern
            if (!string.IsNullOrEmpty(message.Appointment.RecurrencePatern))
            {
                WriteHeaderLine(appointmentHeader, htmlBody, maxLength, LanguageConsts.AppointmentRecurrencePaternLabel,
                    message.Appointment.RecurrencePatern);

                // Empty line
                WriteHeaderEmptyLine(appointmentHeader, htmlBody);
            }

            // Status
            if (message.Appointment.ClientIntentText != null)
                WriteHeaderLine(appointmentHeader, htmlBody, maxLength, LanguageConsts.AppointmentClientIntentLabel,
                    message.Appointment.ClientIntentText);

            // Appointment organizer (FROM)
            WriteHeaderLineNoEncoding(appointmentHeader, htmlBody, maxLength, LanguageConsts.AppointmentOrganizerLabel,
                message.GetEmailSender(htmlBody, hyperlinks));

            // Mandatory participants (TO)
            WriteHeaderLineNoEncoding(appointmentHeader, htmlBody, maxLength,
                LanguageConsts.AppointmentMandatoryParticipantsLabel,
                message.GetEmailRecipients(Storage.Recipient.RecipientType.To, htmlBody, hyperlinks));

            // Optional participants (CC)
            var cc = message.GetEmailRecipients(Storage.Recipient.RecipientType.Cc, htmlBody, hyperlinks);
            if (!string.IsNullOrEmpty(cc))
                WriteHeaderLineNoEncoding(appointmentHeader, htmlBody, maxLength,
                    LanguageConsts.AppointmentOptionalParticipantsLabel, cc);

            // Empty line
            WriteHeaderEmptyLine(appointmentHeader, htmlBody);

            // Categories
            var categories = message.Categories;
            if (categories != null)
            {
                WriteHeaderLine(appointmentHeader, htmlBody, maxLength, LanguageConsts.EmailCategoriesLabel,
                    String.Join("; ", categories));

                // Empty line
                WriteHeaderEmptyLine(appointmentHeader, htmlBody);
            }

            // Urgent
            var importance = message.ImportanceText;
            if (!string.IsNullOrEmpty(importance))
            {
                WriteHeaderLine(appointmentHeader, htmlBody, maxLength, LanguageConsts.ImportanceLabel, importance);

                // Empty line
                WriteHeaderEmptyLine(appointmentHeader, htmlBody);
            }

            // Attachments
            if (attachmentList.Count != 0)
            {
                WriteHeaderLineNoEncoding(appointmentHeader, htmlBody, maxLength,
                    LanguageConsts.AppointmentAttachmentsLabel,
                    string.Join(", ", attachmentList));

                // Empty line
                WriteHeaderEmptyLine(appointmentHeader, htmlBody);
            }

            // End of table + empty line
            WriteHeaderEnd(appointmentHeader, htmlBody);

            body = InjectHeader(body, appointmentHeader.ToString());

            // Write the body to a file
            File.WriteAllText(fileName, body, Encoding.UTF8);

            return files;
        }
コード例 #2
0
ファイル: Reader.cs プロジェクト: iraychen/MSGReader
        /// <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(Storage.Recipient.RecipientType.To, false, false));

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

            // BCC
            propertyWriter.WriteProperty(SystemProperties.System.Message.BccAddress,
                message.GetEmailRecipients(Storage.Recipient.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)));
        }
コード例 #3
0
ファイル: Reader.cs プロジェクト: iraychen/MSGReader
        /// <summary>
        /// Writes the body of the MSG E-mail to html or text and extracts all the attachments. The
        /// result is returned as a List of strings
        /// </summary>
        /// <param name="message"><see cref="Storage.Message"/></param>
        /// <param name="outputFolder">The folder where we need to write the output</param>
        /// <param name="hyperlinks">When true then hyperlinks are generated for the To, CC, BCC and attachments</param>
        /// <returns></returns>
        private List<string> WriteMsgEmail(Storage.Message message, string outputFolder, bool hyperlinks)
        {
            var fileName = "email";
            bool htmlBody;
            string body;
            string dummy;
            List<string> attachmentList;
            List<string> files;

            PreProcessMsgFile(message,
                hyperlinks,
                outputFolder,
                ref fileName,
                out htmlBody,
                out body,
                out dummy,
                out attachmentList,
                out files);

            if (!htmlBody)
                hyperlinks = false;

            var maxLength = 0;

            // Calculate padding width when we are going to write a text file
            if (!htmlBody)
            {
                var languageConsts = new List<string>
                {
                    #region LanguageConsts
                    LanguageConsts.EmailFromLabel,
                    LanguageConsts.EmailSentOnLabel,
                    LanguageConsts.EmailToLabel,
                    LanguageConsts.EmailCcLabel,
                    LanguageConsts.EmailBccLabel,
                    LanguageConsts.EmailSubjectLabel,
                    LanguageConsts.ImportanceLabel,
                    LanguageConsts.EmailAttachmentsLabel,
                    LanguageConsts.EmailFollowUpFlag,
                    LanguageConsts.EmailFollowUpLabel,
                    LanguageConsts.EmailFollowUpStatusLabel,
                    LanguageConsts.EmailFollowUpCompletedText,
                    LanguageConsts.TaskStartDateLabel,
                    LanguageConsts.TaskDueDateLabel,
                    LanguageConsts.TaskDateCompleted,
                    LanguageConsts.EmailCategoriesLabel
                    #endregion
                };

                if (message.Type == Storage.Message.MessageType.EmailEncryptedAndMeabySigned)
                    languageConsts.Add(LanguageConsts.EmailSignedBy);

                maxLength = languageConsts.Select(languageConst => languageConst.Length).Concat(new[] {0}).Max() + 2;
            }
            
            var emailHeader = new StringBuilder();

            // Start of table
            WriteHeaderStart(emailHeader, htmlBody);

            // From
            WriteHeaderLineNoEncoding(emailHeader, htmlBody, maxLength, LanguageConsts.EmailFromLabel,
                message.GetEmailSender(htmlBody, hyperlinks));

            // Sent on
            if (message.SentOn != null)
                WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.EmailSentOnLabel,
                    ((DateTime)message.SentOn).ToString(LanguageConsts.DataFormatWithTime));

            // To
            WriteHeaderLineNoEncoding(emailHeader, htmlBody, maxLength, LanguageConsts.EmailToLabel,
                message.GetEmailRecipients(Storage.Recipient.RecipientType.To, htmlBody, hyperlinks));

            // CC
            var cc = message.GetEmailRecipients(Storage.Recipient.RecipientType.Cc, htmlBody, hyperlinks);
            if (!string.IsNullOrEmpty(cc))
                WriteHeaderLineNoEncoding(emailHeader, htmlBody, maxLength, LanguageConsts.EmailCcLabel, cc);

            // BCC
            var bcc = message.GetEmailRecipients(Storage.Recipient.RecipientType.Bcc, htmlBody, hyperlinks);
            if (!string.IsNullOrEmpty(bcc))
                WriteHeaderLineNoEncoding(emailHeader, htmlBody, maxLength, LanguageConsts.EmailBccLabel, bcc);

            if (message.Type == Storage.Message.MessageType.EmailEncryptedAndMeabySigned)
            {
                var signerInfo = message.SignedBy;
                if (message.SignedOn != null)
                    signerInfo += " " + LanguageConsts.EmailSignedByOn + " " +
                                  ((DateTime)message.SignedOn).ToString(LanguageConsts.DataFormatWithTime);

                WriteHeaderLineNoEncoding(emailHeader, htmlBody, maxLength, LanguageConsts.EmailSignedBy, signerInfo);
            }

            // Subject
            WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.EmailSubjectLabel, message.Subject);

            // Urgent
            if (!string.IsNullOrEmpty(message.ImportanceText))
            {
                WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.ImportanceLabel, message.ImportanceText);

                // Empty line
                WriteHeaderEmptyLine(emailHeader, htmlBody);
            }

            // Attachments
            if (attachmentList.Count != 0)
                WriteHeaderLineNoEncoding(emailHeader, htmlBody, maxLength, LanguageConsts.EmailAttachmentsLabel,
                    string.Join(", ", attachmentList));

            // Empty line
            WriteHeaderEmptyLine(emailHeader, htmlBody);

            // Follow up
            if (message.Flag != null)
            {
                WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.EmailFollowUpLabel,
                    message.Flag.Request);

                // When complete
                if (message.Task.Complete != null && (bool) message.Task.Complete)
                {
                    WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.EmailFollowUpStatusLabel,
                        LanguageConsts.EmailFollowUpCompletedText);

                    // Task completed date
                    if (message.Task.CompleteTime != null)
                        WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.TaskDateCompleted,
                            ((DateTime) message.Task.CompleteTime).ToString(LanguageConsts.DataFormatWithTime));
                }
                else
                {
                    // Task startdate
                    if (message.Task.StartDate != null)
                        WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.TaskStartDateLabel,
                            ((DateTime) message.Task.StartDate).ToString(LanguageConsts.DataFormatWithTime));

                    // Task duedate
                    if (message.Task.DueDate != null)
                        WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.TaskDueDateLabel,
                            ((DateTime) message.Task.DueDate).ToString(LanguageConsts.DataFormatWithTime));
                }

                // Empty line
                WriteHeaderEmptyLine(emailHeader, htmlBody);
            }

            // Categories
            var categories = message.Categories;
            if (categories != null)
            {
                WriteHeaderLine(emailHeader, htmlBody, maxLength, LanguageConsts.EmailCategoriesLabel,
                    String.Join("; ", categories));

                // Empty line
                WriteHeaderEmptyLine(emailHeader, htmlBody);
            }

            // End of table + empty line
            WriteHeaderEnd(emailHeader, htmlBody);

            body = InjectHeader(body, emailHeader.ToString());

            // Write the body to a file
            File.WriteAllText(fileName, body, Encoding.UTF8);

            return files;
        }