System.Net.Mime.HeaderCollection.Add C# (CSharp) Method

Add() public method

public Add ( string name, string value ) : void
name string
value string
return void
        public override void Add(string name, string value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (name == string.Empty)
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(name)), nameof(name));
            }
            if (value == string.Empty)
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, nameof(value)), nameof(name));
            }

            MailBnfHelper.ValidateHeaderName(name);

            // normalize the case of well known headers
            name = MailHeaderInfo.NormalizeCase(name);

            MailHeaderID id = MailHeaderInfo.GetID(name);

            value = value.Normalize(NormalizationForm.FormC);

            if (id == MailHeaderID.ContentType && _part != null)
            {
                _part.ContentType.Set(value.ToLower(CultureInfo.InvariantCulture), this);
            }
            else if (id == MailHeaderID.ContentDisposition && _part is MimePart)
            {
                ((MimePart)_part).ContentDisposition.Set(value.ToLower(CultureInfo.InvariantCulture), this);
            }
            else
            {
                InternalAdd(name, value);
            }
        }
    }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Extract per-recipient dsn headers as a collection
        /// Fields are formatted just like MIME headers, but embedded within the Body of MimeEntity instead
        /// </summary>
        /// <param name="fieldEntity">Source entity</param>
        /// <returns>Collection of <see cref="HeaderCollection"/></returns>
        public static List<HeaderCollection> ParsePerRecientFields(MimeEntity fieldEntity)
        {
            if (fieldEntity == null)
            {
                throw new ArgumentNullException("fieldEntity");
            }
            Body dsnBody = fieldEntity.Body;
            if (dsnBody == null)
            {
                throw new DSNException(DSNError.InvalidDSNBody);
            }
            HeaderCollection dsnFields = new HeaderCollection();
            try
            {
                dsnFields.Add(new HeaderCollection(MimeSerializer.Default.DeserializeHeaders(dsnBody.PerRecipientSeperator()))
                    , PerRecipientFieldList());
            }
            catch (Exception ex)
            {
                throw new DSNException(DSNError.InvalidDSNFields, ex);
            }

            if (dsnFields.IsNullOrEmpty())
            {
                throw new DSNException(DSNError.InvalidDSNFields);
            }

            return PerRecipientList(dsnFields);
        }
All Usage Examples Of System.Net.Mime.HeaderCollection::Add