Add() public method

public Add ( string name, string value ) : void
name string
value string
return void
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);
        }
 internal void EncodeHeaders(HeaderCollection headers)
 {
     if (this.headersEncoding == null)
     {
         this.headersEncoding = Encoding.GetEncoding("utf-8");
     }
     for (int i = 0; i < headers.Count; i++)
     {
         string key = headers.GetKey(i);
         if (MailHeaderInfo.IsUserSettable(key))
         {
             string[] values = headers.GetValues(key);
             string str2 = string.Empty;
             for (int j = 0; j < values.Length; j++)
             {
                 if (MimeBasePart.IsAscii(values[j], false))
                 {
                     str2 = values[j];
                 }
                 else
                 {
                     str2 = MimeBasePart.EncodeHeaderValue(values[j], this.headersEncoding, MimeBasePart.ShouldUseBase64Encoding(this.headersEncoding), key.Length);
                 }
                 if (j == 0)
                 {
                     headers.Set(key, str2);
                 }
                 else
                 {
                     headers.Add(key, str2);
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
        internal void EncodeHeaders(HeaderCollection headers, bool allowUnicode)
        {
            if (_headersEncoding == null)
            {
                _headersEncoding = Encoding.GetEncoding(MimeBasePart.DefaultCharSet);
            }

            System.Diagnostics.Debug.Assert(_headersEncoding != null);

            for (int i = 0; i < headers.Count; i++)
            {
                string headerName = headers.GetKey(i);

                //certain well-known values are encoded by PrepareHeaders and PrepareEnvelopeHeaders
                //so we can ignore them because either we encoded them already or there is no 
                //way for the user to have set them.  If a header is well known and user settable then
                //we should encode it here, otherwise we have already encoded it if necessary
                if (!MailHeaderInfo.IsUserSettable(headerName))
                {
                    continue;
                }

                string[] values = headers.GetValues(headerName);
                string encodedValue = string.Empty;
                for (int j = 0; j < values.Length; j++)
                {
                    //encode if we need to
                    if (MimeBasePart.IsAscii(values[j], false)
                         || (allowUnicode && MailHeaderInfo.AllowsUnicode(headerName) // EAI
                            && !MailBnfHelper.HasCROrLF(values[j])))
                    {
                        encodedValue = values[j];
                    }
                    else
                    {
                        encodedValue = MimeBasePart.EncodeHeaderValue(values[j],
                                                        _headersEncoding,
                                                        MimeBasePart.ShouldUseBase64Encoding(_headersEncoding),
                                                        headerName.Length);
                    }

                    //potentially there are multiple values per key
                    if (j == 0)
                    {
                        //if it's the first or only value, set will overwrite all the values assigned to that key
                        //which is fine since we have them stored in values[]
                        headers.Set(headerName, encodedValue);
                    }
                    else
                    {
                        //this is a subsequent key, so we must Add it since the first key will have overwritten the
                        //other values
                        headers.Add(headerName, encodedValue);
                    }
                }
            }
        }