Reads MIME based emails streams and files.
상속: IDisposable
예제 #1
0
 /// <summary>
 /// Creates Mail message object from file.
 /// </summary>
 /// <param name="mailPath">EML file path.</param>
 /// <returns>Mime decoded email object</returns>
 public static MailMessageParser CreateFromFile(string mailPath)
 {
     using (MailMimeReader mimeDecoder = new MailMimeReader())
     {
         return(mimeDecoder.GetEmail(mailPath));
     }
 }
예제 #2
0
 /// <summary>
 /// Creates Mail message object from stream.
 /// </summary>
 /// <param name="emailStream">email stream.</param>
 /// <returns>Mime decoded email object</returns>
 public static MailMessageParser CreateFromStream(Stream emailStream)
 {
     using (MailMimeReader mimeDecoder = new MailMimeReader())
     {
         return(mimeDecoder.GetEmail(emailStream));
     }
 }
예제 #3
0
        /// <summary>
        /// Creates Mail message object from stream.
        /// </summary>
        /// <param name="mimeDecoder">read MIME object</param>
        /// <param name="emailStream">The email stream.</param>
        /// <returns>Mime decoded email object</returns>
        public static MailMessageParser CreateFromStream(MailMimeReader mimeDecoder, Stream emailStream)
        {
            MailMessageParser result = null;

            if (mimeDecoder != null)
            {
                result = mimeDecoder.GetEmail(emailStream);
            }
            else
            {
                result = null;
            }
            return(result);
        }
예제 #4
0
        /// <summary>
        /// Creates Mail message object from file.
        /// </summary>
        /// <param name="mimeDecoder">read MIME object</param>
        /// <param name="mailPath">EML file path.</param>
        /// <returns>Mime decoded email object</returns>
        public static MailMessageParser CreateFromFile(MailMimeReader mimeDecoder, string mailPath)
        {
            MailMessageParser result = null;

            if (null != mimeDecoder)
            {
                result = mimeDecoder.GetEmail(mailPath);
            }
            else
            {
                result = null;
            }
            return(result);
        }
        /// <summary>
        /// Gets the uploaded email file properties.
        /// </summary>
        /// <param name="fileStream">The file stream.</param>
        /// <param name="mailProperties">The mail properties.</param>
        /// <returns>Dictionary string key value pair for mail properties</returns>
        public static Dictionary<string, string> GetMailFileProperties(System.IO.Stream fileStream, Dictionary<string, string> mailProperties)
        {
            if (null != mailProperties && mailProperties.ContainsKey(ConstantStrings.MailFileExtensionKey))
            {
                if (string.Equals(mailProperties[ConstantStrings.MailFileExtensionKey], ConstantStrings.EmailFileExtension, StringComparison.OrdinalIgnoreCase))
                {
                    MailMimeReader mime = new MailMimeReader();
                    MailMessageParser messageParser = mime.GetEmail(fileStream);
                    string fromDisplayName = Convert.ToString(messageParser.From.DisplayName, CultureInfo.InvariantCulture);
                    mailProperties[ConstantStrings.MailSenderKey] = String.Concat(Convert.ToString(messageParser.From.Address, CultureInfo.InvariantCulture), ConstantStrings.Semicolon, fromDisplayName.Replace(Convert.ToString(messageParser.From.Address, CultureInfo.InvariantCulture), string.Empty).Replace(ConstantStrings.OpeningBracket + ConstantStrings.ClosingBracket, string.Empty));
                    mailProperties[ConstantStrings.MailSearchEmailSubject] = messageParser.Subject;
                    mailProperties[ConstantStrings.MailSentDateKey] = Convert.ToString(messageParser.DeliveryDate, CultureInfo.InvariantCulture);
                    mailProperties[ConstantStrings.MailReceivedDateKey] = Convert.ToString(messageParser.ReceivedDate, CultureInfo.InvariantCulture);
                    mailProperties[ConstantStrings.MailOriginalName] = messageParser.Subject;
                    StringBuilder mailReceiver = new StringBuilder();
                    StringBuilder mailCCAddress = new StringBuilder();
                    StringBuilder attachmentName = new StringBuilder();

                    foreach (MailAddress toItem in messageParser.To)
                    {
                        string toMailAlias = Convert.ToString(toItem.Address, CultureInfo.InvariantCulture);
                        string toMailName = Convert.ToString(toItem.DisplayName, CultureInfo.InvariantCulture);
                        if (toMailName.Contains(toMailAlias))
                        {
                            toMailName = toMailName.Replace(toMailAlias, string.Empty).Replace(ConstantStrings.OpeningBracket + ConstantStrings.ClosingBracket, string.Empty);
                        }

                        mailReceiver.Append(toMailAlias + ConstantStrings.Semicolon + toMailName + ConstantStrings.Semicolon);
                    }

                    mailProperties[ConstantStrings.MailReceiverKey] = Convert.ToString(mailReceiver, CultureInfo.InvariantCulture);

                    foreach (MailAddress itemCC in messageParser.CC)
                    {
                        string mailCCAlias = Convert.ToString(itemCC.Address, CultureInfo.InvariantCulture);
                        string mailCCName = Convert.ToString(itemCC.DisplayName, CultureInfo.InvariantCulture);
                        if (mailCCName.Contains(mailCCAlias))
                        {
                            mailCCName = mailCCName.Replace(mailCCAlias, string.Empty).Replace(ConstantStrings.OpeningBracket + ConstantStrings.ClosingBracket, string.Empty);
                        }

                        mailCCAddress.Append(mailCCAlias + ConstantStrings.Semicolon + mailCCName + ConstantStrings.Semicolon);
                    }

                    mailProperties[ConstantStrings.MailCCAddressKey] = Convert.ToString(mailCCAddress, CultureInfo.InvariantCulture);

                    foreach (System.Net.Mail.Attachment itemAttachment in messageParser.Attachments)
                    {
                        if (!string.IsNullOrWhiteSpace(itemAttachment.Name))
                        {
                            attachmentName.Append(itemAttachment.Name + ConstantStrings.Semicolon);
                        }
                    }

                    for (int mailEntitiesCount = 0; mailEntitiesCount < messageParser.Entities.Count; mailEntitiesCount++)
                    {
                        if (string.Equals(messageParser.Entities[mailEntitiesCount].MediaMainType, ConstantStrings.MailAttachmentMediaMainType, StringComparison.CurrentCultureIgnoreCase))
                        {
                            attachmentName.Append(messageParser.Entities[mailEntitiesCount].ContentDescription + ConstantStrings.Semicolon);
                        }
                    }

                    mailProperties[ConstantStrings.MailAttachmentKey] = Convert.ToString(attachmentName, CultureInfo.InvariantCulture);

                    // Setting email importance
                    mailProperties[ConstantStrings.MailImportanceKey] = (!string.IsNullOrWhiteSpace(messageParser.MailImportance) ? messageParser.MailImportance : ConstantStrings.MailDefaultImportance);

                    // Setting email categories
                    mailProperties[ConstantStrings.MailCategoriesKey] = (!string.IsNullOrWhiteSpace(messageParser.MailCategories) ? messageParser.MailCategories.Replace(ConstantStrings.Comma, ConstantStrings.Semicolon) : string.Empty);
                }
            }

            return mailProperties;
        }
 /// <summary>
 /// Creates Mail message object from stream.
 /// </summary>
 /// <param name="mimeDecoder">read MIME object</param>
 /// <param name="emailStream">The email stream.</param>
 /// <returns>Mime decoded email object</returns>
 public static MailMessageParser CreateFromStream(MailMimeReader mimeDecoder, Stream emailStream)
 {
     MailMessageParser result = null;
     if (mimeDecoder != null)
     {
         result = mimeDecoder.GetEmail(emailStream);
     }
     else
     {
         result = null;
     }
     return result;
 }
 /// <summary>
 /// Creates Mail message object from stream.
 /// </summary>
 /// <param name="emailStream">email stream.</param>
 /// <returns>Mime decoded email object</returns>
 public static MailMessageParser CreateFromStream(Stream emailStream)
 {
     using (MailMimeReader mimeDecoder = new MailMimeReader())
     {
         return mimeDecoder.GetEmail(emailStream);
     }
 }
 /// <summary>
 /// Creates Mail message object from file.
 /// </summary>
 /// <param name="mimeDecoder">read MIME object</param>
 /// <param name="mailPath">EML file path.</param>
 /// <returns>Mime decoded email object</returns>
 public static MailMessageParser CreateFromFile(MailMimeReader mimeDecoder, string mailPath)
 {
     MailMessageParser result = null;
     if (null != mimeDecoder)
     {
         result = mimeDecoder.GetEmail(mailPath);
     }
     else
     {
         result = null;
     }
     return result;
 }
 /// <summary>
 /// Creates Mail message object from file.
 /// </summary>
 /// <param name="mailPath">EML file path.</param>
 /// <returns>Mime decoded email object</returns>
 public static MailMessageParser CreateFromFile(string mailPath)
 {
     using (MailMimeReader mimeDecoder = new MailMimeReader())
     {
         return mimeDecoder.GetEmail(mailPath);
     }
 }
예제 #10
0
        /// <summary>
        /// Gets the uploaded email file properties....
        /// </summary>
        /// <param name="fileStream">The file stream.</param>
        /// <param name="mailProperties">The mail properties.</param>
        /// <returns>Dictionary string key value pair for mail properties</returns>
        public static Dictionary <string, string> GetMailFileProperties(System.IO.Stream fileStream, Dictionary <string, string> mailProperties)
        {
            if (null != mailProperties && mailProperties.ContainsKey(ServiceConstants.MAIL_FILE_EXTENSION_KEY))
            {
                if (string.Equals(mailProperties[ServiceConstants.MAIL_FILE_EXTENSION_KEY], ServiceConstants.EMAIL_FILE_EXTENSION, StringComparison.OrdinalIgnoreCase))
                {
                    MailMimeReader    mime            = new MailMimeReader();
                    MailMessageParser messageParser   = mime.GetEmail(fileStream);
                    string            fromDisplayName = Convert.ToString(messageParser.From.DisplayName, CultureInfo.InvariantCulture);
                    mailProperties[ServiceConstants.MAIL_SENDER_KEY]           = String.Concat(Convert.ToString(messageParser.From.Address, CultureInfo.InvariantCulture), ServiceConstants.SEMICOLON, fromDisplayName.Replace(Convert.ToString(messageParser.From.Address, CultureInfo.InvariantCulture), string.Empty).Replace(ServiceConstants.OPENING_BRACKET + ServiceConstants.CLOSING_BRACKET, string.Empty));
                    mailProperties[ServiceConstants.MAIL_SEARCH_EMAIL_SUBJECT] = messageParser.Subject;
                    mailProperties[ServiceConstants.MAIL_SENT_DATE_KEY]        = Convert.ToString(messageParser.DeliveryDate, CultureInfo.InvariantCulture);
                    mailProperties[ServiceConstants.MAIL_RECEIVED_DATEKEY]     = Convert.ToString(messageParser.ReceivedDate, CultureInfo.InvariantCulture);
                    mailProperties[ServiceConstants.MAIL_ORIGINAL_NAME]        = messageParser.Subject;
                    StringBuilder mailReceiver   = new StringBuilder();
                    StringBuilder mailCCAddress  = new StringBuilder();
                    StringBuilder attachmentName = new StringBuilder();

                    foreach (MailAddress toItem in messageParser.To)
                    {
                        string toMailAlias = Convert.ToString(toItem.Address, CultureInfo.InvariantCulture);
                        string toMailName  = Convert.ToString(toItem.DisplayName, CultureInfo.InvariantCulture);
                        if (toMailName.Contains(toMailAlias))
                        {
                            toMailName = toMailName.Replace(toMailAlias, string.Empty).Replace(ServiceConstants.OPENING_BRACKET + ServiceConstants.CLOSING_BRACKET, string.Empty);
                        }

                        mailReceiver.Append(toMailAlias + ServiceConstants.SEMICOLON + toMailName + ServiceConstants.SEMICOLON);
                    }

                    mailProperties[ServiceConstants.MAIL_RECEIVER_KEY] = Convert.ToString(mailReceiver, CultureInfo.InvariantCulture);

                    foreach (MailAddress itemCC in messageParser.CC)
                    {
                        string mailCCAlias = Convert.ToString(itemCC.Address, CultureInfo.InvariantCulture);
                        string mailCCName  = Convert.ToString(itemCC.DisplayName, CultureInfo.InvariantCulture);
                        if (mailCCName.Contains(mailCCAlias))
                        {
                            mailCCName = mailCCName.Replace(mailCCAlias, string.Empty).Replace(ServiceConstants.OPENING_BRACKET + ServiceConstants.CLOSING_BRACKET, string.Empty);
                        }

                        mailCCAddress.Append(mailCCAlias + ServiceConstants.SEMICOLON + mailCCName + ServiceConstants.SEMICOLON);
                    }

                    mailProperties[ServiceConstants.MAIL_CC_ADDRESS_KEY] = Convert.ToString(mailCCAddress, CultureInfo.InvariantCulture);

                    foreach (System.Net.Mail.Attachment itemAttachment in messageParser.Attachments)
                    {
                        if (!string.IsNullOrWhiteSpace(itemAttachment.Name))
                        {
                            attachmentName.Append(itemAttachment.Name + ServiceConstants.SEMICOLON);
                        }
                    }

                    for (int mailEntitiesCount = 0; mailEntitiesCount < messageParser.Entities.Count; mailEntitiesCount++)
                    {
                        if (string.Equals(messageParser.Entities[mailEntitiesCount].MediaMainType, ServiceConstants.MAIL_ATTACHMENT_MEDIA_MAINT_YPE, StringComparison.CurrentCultureIgnoreCase))
                        {
                            attachmentName.Append(messageParser.Entities[mailEntitiesCount].ContentDescription + ServiceConstants.SEMICOLON);
                        }
                    }

                    mailProperties[ServiceConstants.MAIL_ATTACHMENT_KEY] = Convert.ToString(attachmentName, CultureInfo.InvariantCulture);

                    // Setting email importance
                    mailProperties[ServiceConstants.MAIL_IMPORTANCE_KEY] = (!string.IsNullOrWhiteSpace(messageParser.MailImportance) ? messageParser.MailImportance : ServiceConstants.MAIL_DEFAULT_IMPORTANCE);

                    // Setting email categories
                    mailProperties[ServiceConstants.MAIL_CATEGORIES_KEY] = (!string.IsNullOrWhiteSpace(messageParser.MailCategories) ? messageParser.MailCategories.Replace(ServiceConstants.COMMA, ServiceConstants.SEMICOLON) : string.Empty);
                }
            }

            return(mailProperties);
        }
        /// <summary>
        /// Uploads the email to specified folder in matter library.
        /// </summary>
        /// <param name="requestObject">web request object</param>
        /// <param name="client">Provider Service client Object</param>
        /// <param name="folderPath">target folder path for upload</param>
        /// <param name="filename">Name of the file</param>
        /// <param name="documentLibraryName">Name of the document library</param>
        /// <param name="xmlDocument">Mail XML Content</param>
        /// <param name="message">Reference object for the message to be returned</param>
        internal void UploadMail(Client client, string folderPath, string fileName, string documentLibraryName, XmlDocument xmlDocument, ref string message)
        {
            var bytes = (dynamic)null;

            try
            {
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
                nsmgr.AddNamespace("s", ServiceConstants.SOAP_ENVELOP_URI);
                nsmgr.AddNamespace("m", ServiceConstants.EXCHANGE_SERVICE_MESSAGE);
                nsmgr.AddNamespace("t", ServiceConstants.EXCHANGE_SERVICE_TYPES);
                MailMetaData mailMetaData = new MailMetaData();

                bytes = GetEmailProperties(xmlDocument, ref mailMetaData);

                using (MemoryStream memoryStream = new MemoryStream(bytes))
                {
                    using (MailMimeReader mime = new MailMimeReader())
                    {
                        MailMessageParser messageParser = mime.GetEmail(memoryStream);
                        mailMetaData.mailImportance = (string.IsNullOrWhiteSpace(messageParser.MailImportance)) ? ServiceConstants.MAIL_DEFAULT_IMPORTANCE : messageParser.MailImportance;
                        mailMetaData.receivedDate = (string.IsNullOrWhiteSpace(messageParser.ReceivedDate.Date.ToShortDateString())) ? string.Empty : Convert.ToString(messageParser.ReceivedDate, CultureInfo.InvariantCulture);
                        UploadToFolder(client, folderPath, fileName, string.Empty, memoryStream, documentLibraryName, mailMetaData, ref message);
                    }
                }
            }
            catch (Exception exception)
            {
                //Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
        }
예제 #12
0
        /// <summary>
        /// Gets the uploaded email file properties.
        /// </summary>
        /// <param name="fileStream">The file stream.</param>
        /// <param name="mailProperties">The mail properties.</param>
        /// <returns>Dictionary string key value pair for mail properties</returns>
        public static Dictionary <string, string> GetMailFileProperties(System.IO.Stream fileStream, Dictionary <string, string> mailProperties)
        {
            if (null != mailProperties && mailProperties.ContainsKey(ConstantStrings.MailFileExtensionKey))
            {
                if (string.Equals(mailProperties[ConstantStrings.MailFileExtensionKey], ConstantStrings.EmailFileExtension, StringComparison.OrdinalIgnoreCase))
                {
                    MailMimeReader    mime            = new MailMimeReader();
                    MailMessageParser messageParser   = mime.GetEmail(fileStream);
                    string            fromDisplayName = Convert.ToString(messageParser.From.DisplayName, CultureInfo.InvariantCulture);
                    mailProperties[ConstantStrings.MailSenderKey]          = String.Concat(Convert.ToString(messageParser.From.Address, CultureInfo.InvariantCulture), ConstantStrings.Semicolon, fromDisplayName.Replace(Convert.ToString(messageParser.From.Address, CultureInfo.InvariantCulture), string.Empty).Replace(ConstantStrings.OpeningBracket + ConstantStrings.ClosingBracket, string.Empty));
                    mailProperties[ConstantStrings.MailSearchEmailSubject] = messageParser.Subject;
                    mailProperties[ConstantStrings.MailSentDateKey]        = Convert.ToString(messageParser.DeliveryDate, CultureInfo.InvariantCulture);
                    mailProperties[ConstantStrings.MailReceivedDateKey]    = Convert.ToString(messageParser.ReceivedDate, CultureInfo.InvariantCulture);
                    mailProperties[ConstantStrings.MailOriginalName]       = messageParser.Subject;
                    StringBuilder mailReceiver   = new StringBuilder();
                    StringBuilder mailCCAddress  = new StringBuilder();
                    StringBuilder attachmentName = new StringBuilder();

                    foreach (MailAddress toItem in messageParser.To)
                    {
                        string toMailAlias = Convert.ToString(toItem.Address, CultureInfo.InvariantCulture);
                        string toMailName  = Convert.ToString(toItem.DisplayName, CultureInfo.InvariantCulture);
                        if (toMailName.Contains(toMailAlias))
                        {
                            toMailName = toMailName.Replace(toMailAlias, string.Empty).Replace(ConstantStrings.OpeningBracket + ConstantStrings.ClosingBracket, string.Empty);
                        }

                        mailReceiver.Append(toMailAlias + ConstantStrings.Semicolon + toMailName + ConstantStrings.Semicolon);
                    }

                    mailProperties[ConstantStrings.MailReceiverKey] = Convert.ToString(mailReceiver, CultureInfo.InvariantCulture);

                    foreach (MailAddress itemCC in messageParser.CC)
                    {
                        string mailCCAlias = Convert.ToString(itemCC.Address, CultureInfo.InvariantCulture);
                        string mailCCName  = Convert.ToString(itemCC.DisplayName, CultureInfo.InvariantCulture);
                        if (mailCCName.Contains(mailCCAlias))
                        {
                            mailCCName = mailCCName.Replace(mailCCAlias, string.Empty).Replace(ConstantStrings.OpeningBracket + ConstantStrings.ClosingBracket, string.Empty);
                        }

                        mailCCAddress.Append(mailCCAlias + ConstantStrings.Semicolon + mailCCName + ConstantStrings.Semicolon);
                    }

                    mailProperties[ConstantStrings.MailCCAddressKey] = Convert.ToString(mailCCAddress, CultureInfo.InvariantCulture);

                    foreach (System.Net.Mail.Attachment itemAttachment in messageParser.Attachments)
                    {
                        if (!string.IsNullOrWhiteSpace(itemAttachment.Name))
                        {
                            attachmentName.Append(itemAttachment.Name + ConstantStrings.Semicolon);
                        }
                    }

                    for (int mailEntitiesCount = 0; mailEntitiesCount < messageParser.Entities.Count; mailEntitiesCount++)
                    {
                        if (string.Equals(messageParser.Entities[mailEntitiesCount].MediaMainType, ConstantStrings.MailAttachmentMediaMainType, StringComparison.CurrentCultureIgnoreCase))
                        {
                            attachmentName.Append(messageParser.Entities[mailEntitiesCount].ContentDescription + ConstantStrings.Semicolon);
                        }
                    }

                    mailProperties[ConstantStrings.MailAttachmentKey] = Convert.ToString(attachmentName, CultureInfo.InvariantCulture);

                    // Setting email importance
                    mailProperties[ConstantStrings.MailImportanceKey] = (!string.IsNullOrWhiteSpace(messageParser.MailImportance) ? messageParser.MailImportance : ConstantStrings.MailDefaultImportance);

                    // Setting email categories
                    mailProperties[ConstantStrings.MailCategoriesKey] = (!string.IsNullOrWhiteSpace(messageParser.MailCategories) ? messageParser.MailCategories.Replace(ConstantStrings.Comma, ConstantStrings.Semicolon) : string.Empty);
                }
            }

            return(mailProperties);
        }
예제 #13
0
        /// <summary>
        /// Gets the uploaded email file properties....
        /// </summary>
        /// <param name="fileStream">The file stream.</param>
        /// <param name="mailProperties">The mail properties.</param>
        /// <returns>Dictionary string key value pair for mail properties</returns>
        public static Dictionary<string, string> GetMailFileProperties(System.IO.Stream fileStream, Dictionary<string, string> mailProperties)
        {
            if (null != mailProperties && mailProperties.ContainsKey(ServiceConstants.MAIL_FILE_EXTENSION_KEY))
            {
                if (string.Equals(mailProperties[ServiceConstants.MAIL_FILE_EXTENSION_KEY], ServiceConstants.EMAIL_FILE_EXTENSION, StringComparison.OrdinalIgnoreCase))
                {
                    MailMimeReader mime = new MailMimeReader();
                    MailMessageParser messageParser = mime.GetEmail(fileStream);
                    string fromDisplayName = Convert.ToString(messageParser.From.DisplayName, CultureInfo.InvariantCulture);
                    mailProperties[ServiceConstants.MAIL_SENDER_KEY] = String.Concat(Convert.ToString(messageParser.From.Address, CultureInfo.InvariantCulture), ServiceConstants.SEMICOLON, fromDisplayName.Replace(Convert.ToString(messageParser.From.Address, CultureInfo.InvariantCulture), string.Empty).Replace(ServiceConstants.OPENING_BRACKET + ServiceConstants.CLOSING_BRACKET, string.Empty));
                    mailProperties[ServiceConstants.MAIL_SEARCH_EMAIL_SUBJECT] = messageParser.Subject;
                    mailProperties[ServiceConstants.MAIL_SENT_DATE_KEY] = Convert.ToString(messageParser.DeliveryDate, CultureInfo.InvariantCulture);
                    mailProperties[ServiceConstants.MAIL_RECEIVED_DATEKEY] = Convert.ToString(messageParser.ReceivedDate, CultureInfo.InvariantCulture);
                    mailProperties[ServiceConstants.MAIL_ORIGINAL_NAME] = messageParser.Subject;
                    StringBuilder mailReceiver = new StringBuilder();
                    StringBuilder mailCCAddress = new StringBuilder();
                    StringBuilder attachmentName = new StringBuilder();

                    foreach (MailAddress toItem in messageParser.To)
                    {
                        string toMailAlias = Convert.ToString(toItem.Address, CultureInfo.InvariantCulture);
                        string toMailName = Convert.ToString(toItem.DisplayName, CultureInfo.InvariantCulture);
                        if (toMailName.Contains(toMailAlias))
                        {
                            toMailName = toMailName.Replace(toMailAlias, string.Empty).Replace(ServiceConstants.OPENING_BRACKET + ServiceConstants.CLOSING_BRACKET, string.Empty);
                        }

                        mailReceiver.Append(toMailAlias + ServiceConstants.SEMICOLON + toMailName + ServiceConstants.SEMICOLON);
                    }

                    mailProperties[ServiceConstants.MAIL_RECEIVER_KEY] = Convert.ToString(mailReceiver, CultureInfo.InvariantCulture);

                    foreach (MailAddress itemCC in messageParser.CC)
                    {
                        string mailCCAlias = Convert.ToString(itemCC.Address, CultureInfo.InvariantCulture);
                        string mailCCName = Convert.ToString(itemCC.DisplayName, CultureInfo.InvariantCulture);
                        if (mailCCName.Contains(mailCCAlias))
                        {
                            mailCCName = mailCCName.Replace(mailCCAlias, string.Empty).Replace(ServiceConstants.OPENING_BRACKET + ServiceConstants.CLOSING_BRACKET, string.Empty);
                        }

                        mailCCAddress.Append(mailCCAlias + ServiceConstants.SEMICOLON + mailCCName + ServiceConstants.SEMICOLON);
                    }

                    mailProperties[ServiceConstants.MAIL_CC_ADDRESS_KEY] = Convert.ToString(mailCCAddress, CultureInfo.InvariantCulture);

                    foreach (System.Net.Mail.Attachment itemAttachment in messageParser.Attachments)
                    {
                        if (!string.IsNullOrWhiteSpace(itemAttachment.Name))
                        {
                            attachmentName.Append(itemAttachment.Name + ServiceConstants.SEMICOLON);
                        }
                    }

                    for (int mailEntitiesCount = 0; mailEntitiesCount < messageParser.Entities.Count; mailEntitiesCount++)
                    {
                        if (string.Equals(messageParser.Entities[mailEntitiesCount].MediaMainType, ServiceConstants.MAIL_ATTACHMENT_MEDIA_MAINT_YPE, StringComparison.CurrentCultureIgnoreCase))
                        {
                            attachmentName.Append(messageParser.Entities[mailEntitiesCount].ContentDescription + ServiceConstants.SEMICOLON);
                        }
                    }

                    mailProperties[ServiceConstants.MAIL_ATTACHMENT_KEY] = Convert.ToString(attachmentName, CultureInfo.InvariantCulture);

                    // Setting email importance
                    mailProperties[ServiceConstants.MAIL_IMPORTANCE_KEY] = (!string.IsNullOrWhiteSpace(messageParser.MailImportance) ? messageParser.MailImportance : ServiceConstants.MAIL_DEFAULT_IMPORTANCE);

                    // Setting email categories
                    mailProperties[ServiceConstants.MAIL_CATEGORIES_KEY] = (!string.IsNullOrWhiteSpace(messageParser.MailCategories) ? messageParser.MailCategories.Replace(ServiceConstants.COMMA, ServiceConstants.SEMICOLON) : string.Empty);
                }
            }

            return mailProperties;
        }
        /// <summary>
        /// Uploads the email to specified folder in matter library.
        /// </summary>
        /// <param name="requestObject">web request object</param>
        /// <param name="client">Provider Service client Object</param>
        /// <param name="folderPath">target folder path for upload</param>
        /// <param name="filename">Name of the file</param>
        /// <param name="documentLibraryName">Name of the document library</param>
        /// <param name="xmlDocument">Mail XML Content</param>
        /// <param name="message">Reference object for the message to be returned</param>
        internal static void UploadMail(RequestObject requestObject, Client client, string folderPath, string fileName, string documentLibraryName, XmlDocument xmlDocument, ref string message)
        {
            var bytes = (dynamic)null;

            try
            {
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
                nsmgr.AddNamespace("s", ConstantStrings.SoapEnvelopURI);
                nsmgr.AddNamespace("m", ConstantStrings.ExchangeServiceMessage);
                nsmgr.AddNamespace("t", ConstantStrings.ExchangeServiceTypes);
                MailMetaData mailMetaData = new MailMetaData();

                bytes = GetEmailProperties(xmlDocument, ref mailMetaData);

                using (MemoryStream memoryStream = new MemoryStream(bytes))
                {
                    using (MailMimeReader mime = new MailMimeReader())
                    {
                        MailMessageParser messageParser = mime.GetEmail(memoryStream);
                        mailMetaData.mailImportance = (string.IsNullOrWhiteSpace(messageParser.MailImportance)) ? ConstantStrings.MailDefaultImportance : messageParser.MailImportance;
                        mailMetaData.receivedDate = (string.IsNullOrWhiteSpace(messageParser.ReceivedDate.Date.ToShortDateString())) ? string.Empty : Convert.ToString(messageParser.ReceivedDate, CultureInfo.InvariantCulture);
                        UploadToFolder(requestObject, client, folderPath, fileName, string.Empty, memoryStream, documentLibraryName, mailMetaData, ref message);
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ServiceConstantStrings.LogTableName);
            }
        }