Наследование: System.Collections.Specialized.NameValueCollection
Пример #1
0
 internal void PersistIfNeeded(HeaderCollection headers, bool forcePersist)
 {
     if (IsChanged || !isPersisted || forcePersist)
     {
         headers.InternalSet(MailHeaderInfo.GetString(MailHeaderID.ContentDisposition), ToString());
         isPersisted = true;
     }
 }
 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);
                 }
             }
         }
     }
 }
Пример #3
0
 private static List<HeaderCollection> PerRecipientList(IEnumerable<Header> fields)
 {
     List<HeaderCollection> perRecipientList = new List<HeaderCollection>();
     HeaderCollection headers = new HeaderCollection();
     foreach (var dsnField in fields)
     {
         if(dsnField.IsNamed(SeperatorHeader) && ! headers.IsNullOrEmpty()) 
         {
             perRecipientList.Add(headers);
             headers = new HeaderCollection();
             continue;
         }              
         headers.Add(dsnField);
     }
     if (! headers.IsNullOrEmpty())
     {
         perRecipientList.Add(headers);
     }
     return perRecipientList;
 }
Пример #4
0
 internal void Set(string contentDisposition, HeaderCollection headers)
 {
     // we don't set ischanged because persistence was already handled
     // via the headers.
     disposition = contentDisposition;
     ParseValue();
     headers.InternalSet(MailHeaderInfo.GetString(MailHeaderID.ContentDisposition), ToString());
     isPersisted = true;
 }
Пример #5
0
        /// <summary>
        /// Extract DSN fields 
        /// 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 fields</returns>
        public static HeaderCollection ParseDSNFields(MimeEntity fieldEntity)
        {
            if (fieldEntity == null)
            {
                throw new ArgumentNullException("fieldEntity");
            }
            Body DSNBody = fieldEntity.Body;
            if (DSNBody == null)
            {
                throw new DSNException(DSNError.InvalidDSNBody);
            }
            HeaderCollection DSNFields = null;
            try
            {
                DSNFields = new HeaderCollection(MimeSerializer.Default.DeserializeHeaders(DSNBody.TrimEmptyLines()));
            }
            catch (Exception ex)
            {
                throw new DSNException(DSNError.InvalidDSNFields, ex);
            }

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

            return DSNFields;
        }
Пример #6
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 Set(string contentType, HeaderCollection headers)
 {
     this.type = contentType;
     this.ParseValue();
     headers.InternalSet(MailHeaderInfo.GetString(MailHeaderID.ContentType), this.ToString());
     this.isPersisted = true;
 }
Пример #8
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);
                    }
                }
            }
        }
 internal void PersistIfNeeded(HeaderCollection headers, bool forcePersist)
 {
     if ((this.IsChanged || !this.isPersisted) || forcePersist)
     {
         headers.InternalSet(MailHeaderInfo.GetString(MailHeaderID.ContentType), this.ToString());
         this.isPersisted = true;
     }
 }
Пример #10
0
        /// <summary>
        /// Extract MDN fields (RFC 3798 Section 3.1.*). 
        /// 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 fields</returns>
        public static HeaderCollection ParseMDNFields(MimeEntity fieldEntity)
        {
            if (fieldEntity == null)
            {
                throw new ArgumentNullException("fieldEntity");
            }
            Body mdnBody = fieldEntity.Body;
            if (mdnBody == null)
            {
                throw new MDNException(MDNError.InvalidMDNBody);
            }
            HeaderCollection mdnFields = null;
            try
            {
                mdnFields = new HeaderCollection(MimeSerializer.Default.DeserializeHeaders(mdnBody.Text));
            }
            catch(Exception ex)
            {
                throw new MDNException(MDNError.InvalidMDNFields, ex);
            }

            if (mdnFields.IsNullOrEmpty())
            {
                throw new MDNException(MDNError.InvalidMDNFields);
            }

            return mdnFields;
        }
Пример #11
0
 public static void Associate(string web, Message message, HeaderCollection headers)
 {
     throw new NotImplementedException();
 }
Пример #12
0
 public static void PrintInfo(string web, HeaderCollection headerCollection, string remove, string name)
 {
 }
 internal void Set(string contentDisposition, HeaderCollection headers)
 {
     this.disposition = contentDisposition;
     this.ParseValue();
     headers.InternalSet(MailHeaderInfo.GetString(MailHeaderID.ContentDisposition), this.ToString());
     this.isPersisted = true;
 }