Microsoft.Legal.MatterCenter.Utility.MailMessageParser.SetContentTypeFields C# (CSharp) Méthode

SetContentTypeFields() public méthode

Sets the content type fields.
public SetContentTypeFields ( string mailContentType ) : void
mailContentType string content type string.
Résultat void
        public void SetContentTypeFields(string mailContentType)
        {
            if (!string.IsNullOrEmpty(mailContentType))
            {
                mailContentType = mailContentType.Trim();
                if (null == mailContentType || 1 > mailContentType.Length)
                {
                    this.ContentType = new ContentType(ServiceConstants.MAIL_CONTENT_TYPE);
                }
                else
                {
                    this.ContentType = new ContentType(mailContentType);
                }

                if (null == this.ContentType.CharSet)
                {
                    this.BodyEncoding = Encoding.ASCII;
                }
                else
                {
                    try
                    {
                        this.BodyEncoding = Encoding.GetEncoding(this.ContentType.CharSet);
                    }
                    catch (EncoderFallbackException)
                    {
                        this.BodyEncoding = Encoding.ASCII;
                    }
                    catch
                    {
                        this.BodyEncoding = Encoding.ASCII;
                    }
                }

                if (null == this.ContentType.MediaType || 1 > this.ContentType.MediaType.Length)
                {
                    this.ContentType.MediaType = ServiceConstants.MailMediaType;
                }
                else
                {
                    string mediaTypeString = this.ContentType.MediaType.Trim();
                    int slashPosition = this.ContentType.MediaType.IndexOf(ServiceConstants.FORWARD_SLASH, StringComparison.Ordinal);
                    if (1 > slashPosition)
                    {
                        this.MediaMainType = mediaTypeString;
                        if (string.Equals(this.MediaMainType, ServiceConstants.TEXT_MEDIA_MAIN_TYPE, StringComparison.OrdinalIgnoreCase))
                        {
                            this.MediaSubType = ServiceConstants.MAIL_MEDIA_SUBTYPE;
                        }
                        else
                        {
                            this.MediaSubType = string.Empty;
                        }
                    }
                    else
                    {
                        this.MediaMainType = mediaTypeString.Substring(0, slashPosition);
                        if (mediaTypeString.Length > slashPosition)
                        {
                            this.MediaSubType = mediaTypeString.Substring(slashPosition + 1);
                        }
                        else
                        {
                            if (string.Equals(this.MediaMainType, ServiceConstants.TEXT_MEDIA_MAIN_TYPE, StringComparison.OrdinalIgnoreCase))
                            {
                                this.MediaSubType = ServiceConstants.MAIL_MEDIA_SUBTYPE;
                            }
                            else
                            {
                                this.MediaSubType = string.Empty;
                            }
                        }
                    }
                }

                this.IsBodyHtml = this.MediaSubType == ServiceConstants.HtmlMediaMainType;
            }
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Convert one MIME header field and update message accordingly
        /// </summary>
        /// <param name="message">Parsed message object</param>
        /// <param name="headerField">header field</param>
        private void ProcessHeaderField(MailMessageParser message, string headerField)
        {
            string headerLineType;
            string headerLineContent;
            int separatorPosition = headerField.IndexOf(ServiceConstants.COLON, StringComparison.CurrentCulture);
            if (0 < separatorPosition)
            {
                ////process header field type
                headerLineType = headerField.Substring(0, separatorPosition).ToUpperInvariant();
                headerLineContent = headerField.Substring(separatorPosition + 1).Trim(whiteSpaceChars);
                if (string.IsNullOrEmpty(headerLineType) || string.IsNullOrEmpty(headerLineContent))
                {
                    ////mail header parts missing, exist function
                    return;
                }
                //// add header line to headers
                message.Headers.Add(headerLineType, headerLineContent);

                switch (headerLineType)
                {
                    case ServiceConstants.MailAttributes.BCC:
                        AddMailAddresses(headerLineContent, message.Bcc);
                        break;
                    case ServiceConstants.MailAttributes.CC:
                        AddMailAddresses(headerLineContent, message.CC);
                        break;
                    case ServiceConstants.MailAttributes.CONTENT_DESCRIPTION:
                        message.ContentDescription = headerLineContent;
                        break;
                    case ServiceConstants.MailAttributes.CONTENT_DISPOSITION:
                        message.SetContentDisposition(headerLineContent);
                        break;
                    case ServiceConstants.MailAttributes.CONTENT_ID:
                        message.ContentId = headerLineContent;
                        break;
                    case ServiceConstants.MailAttributes.CONTENT_TRANSFER_ENCODING:
                        message.ContentTransferEncoding = ConvertToTransferEncoding(headerLineContent);
                        break;
                    case ServiceConstants.MailAttributes.CONTENT_TYPE:
                        message.SetContentTypeFields(headerLineContent);
                        break;
                    case ServiceConstants.MailAttributes.DATE:
                        message.DeliveryDate = this.ConvertToDateTime(headerLineContent);
                        break;
                    case ServiceConstants.MailAttributes.FROM:
                        MailAddress address = ConvertToMailAddress(headerLineContent);
                        if (null != address)
                        {
                            message.From = address;
                        }
                        break;
                    case ServiceConstants.MailAttributes.SENDER:
                        message.Sender = ConvertToMailAddress(headerLineContent);
                        break;
                    case ServiceConstants.MailAttributes.SUBJECT:
                        message.Subject = headerLineContent;
                        break;
                    case ServiceConstants.MailAttributes.TO:
                        AddMailAddresses(headerLineContent, message.To);
                        break;
                    case ServiceConstants.MailAttributes.IMPORTANCE:
                        message.MailImportance = headerLineContent;
                        break;
                    case ServiceConstants.MailAttributes.CATEGORIES:
                        message.MailCategories = headerLineContent;
                        break;
                    case ServiceConstants.MailAttributes.RECEIVED:
                        if (message.ReceivedDate.Year.Equals(1))
                        {
                            message.ReceivedDate = this.ProcessReceivedDate(headerLineContent);
                        }
                        break;
                    default:
                        message.UnknowHeaderlines.Add(headerField);
                        if (IsCollectHiddenHeaderLines)
                        {
                            AllHiddenHeaderLines.Add(headerField);
                        }

                        break;
                }
            }
        }
All Usage Examples Of Microsoft.Legal.MatterCenter.Utility.MailMessageParser::SetContentTypeFields