/// <summary>
        /// Constuct an achiveable email object represtenting me.
        /// </summary>
        /// <param name="olItem">Me.</param>
        /// <param name="reason">The reason I should be archived.</param>
        /// <returns>An achiveable email object represtenting me.</returns>
        public static ArchiveableEmail AsArchiveable(this Outlook.MailItem olItem, EmailArchiveReason reason)
        {
            ArchiveableEmail mailArchive = new ArchiveableEmail(MailItemExtensions.SuiteCRMUserSession, MailItemExtensions.Log);

            mailArchive.From       = olItem.GetSenderSMTPAddress();
            mailArchive.To         = string.Empty;
            mailArchive.CrmEntryId = olItem.GetCRMEntryId();

            Log.Info($"MailItemExtension.AsArchiveable: serialising mail {olItem.Subject} dated {olItem.SentOn}.");

            foreach (Outlook.Recipient recipient in olItem.Recipients)
            {
                string address = recipient.GetSmtpAddress();

                switch (recipient.Type)
                {
                case (int)Outlook.OlMailRecipientType.olCC:
                    mailArchive.CC = ExtendRecipientField(mailArchive.CC, address);
                    break;

                case (int)Outlook.OlMailRecipientType.olBCC:
                    // unlikely to happen and in any case we don't store these
                    break;

                default:
                    mailArchive.To = ExtendRecipientField(mailArchive.To, address);
                    break;
                }
            }

            mailArchive.CC = olItem.CC;

            mailArchive.ClientId = olItem.EnsureEntryID();
            mailArchive.Subject  = olItem.Subject;
            mailArchive.Sent     = olItem.ArchiveTime(reason);
            mailArchive.Body     = olItem.Body;
            mailArchive.HTMLBody = Tidy(olItem.HTMLBody);
            mailArchive.Reason   = reason;
            mailArchive.Category = olItem.UserProperties[CRMCategoryPropertyName] != null ?
                                   olItem.UserProperties[CRMCategoryPropertyName].Value :
                                   string.Empty;

            if (Properties.Settings.Default.ArchiveAttachments)
            {
                foreach (Outlook.Attachment attachment in olItem.Attachments)
                {
                    mailArchive.Attachments.Add(new ArchiveableAttachment
                    {
                        DisplayName = attachment.DisplayName,
                        FileContentInBase64String = olItem.GetAttachmentAsBytes(attachment)
                    });
                }
            }

            return(mailArchive);
        }
Exemple #2
0
        /// <summary>
        /// Constuct an achiveable email object represtenting me.
        /// </summary>
        /// <param name="olItem">Me.</param>
        /// <param name="reason">The reason I should be archived.</param>
        /// <returns>An achiveable email object represtenting me.</returns>
        public static ArchiveableEmail AsArchiveable(this Outlook.MailItem olItem, EmailArchiveReason reason)
        {
            ArchiveableEmail mailArchive = new ArchiveableEmail(MailItemExtensions.SuiteCRMUserSession, MailItemExtensions.Log);

            mailArchive.From = olItem.GetSenderSMTPAddress();
            mailArchive.To   = string.Empty;

            Log.Info($"EmailArchiving.SerialiseEmailObject: serialising mail {olItem.Subject} dated {olItem.SentOn}.");

            foreach (Outlook.Recipient recipient in olItem.Recipients)
            {
                string address = recipient.GetSmtpAddress();

                if (mailArchive.To == string.Empty)
                {
                    mailArchive.To = address;
                }
                else
                {
                    mailArchive.To += ";" + address;
                }
            }

            mailArchive.OutlookId = olItem.EnsureEntryID();
            mailArchive.Subject   = olItem.Subject;
            mailArchive.Sent      = olItem.ArchiveTime(reason);
            mailArchive.Body      = olItem.Body;
            mailArchive.HTMLBody  = Tidy(olItem.HTMLBody);
            mailArchive.Reason    = reason;
            mailArchive.Category  = olItem.UserProperties[CRMCategoryPropertyName] != null ?
                                    olItem.UserProperties[CRMCategoryPropertyName].Value :
                                    string.Empty;

            if (Properties.Settings.Default.ArchiveAttachments)
            {
                foreach (Outlook.Attachment attachment in olItem.Attachments)
                {
                    mailArchive.Attachments.Add(new ArchiveableAttachment
                    {
                        DisplayName = attachment.DisplayName,
                        FileContentInBase64String = olItem.GetAttachmentAsBytes(attachment)
                    });
                }
            }

            return(mailArchive);
        }