public void CollectionEnumerator()
        {
            MimeHeaderCollection collection = new MimeHeaderCollection();
            collection.Add(new MimeHeader("name:value"));
            collection.Add(new MimeHeader("name2:value2"));
            collection.Add(new MimeHeader("name3:value3"));

            int x = 0;
            foreach (MimeHeader header in collection)
            {
                switch (x)
                {
                    case 0:
                        AssertionHelper.IsTrue("The header for name:value", header.Name == "name" && header.Value == "value");
                        break;
                    case 1:
                        AssertionHelper.IsTrue("The header for name2:value2", header.Name == "name2" && header.Value == "value2");
                        break;
                    case 2:
                        AssertionHelper.IsTrue("The header for name3:value3", header.Name == "name3" && header.Value == "value3");
                        break;
                    default:
                        AssertionHelper.IsTrue("There are only 3 items in the collection", false);
                        break;
                }
                x++;

            }
        }
 public void BasicCollection()
 {
     MimeHeaderCollection collection = new MimeHeaderCollection();
     collection.Add(new MimeHeader("name:value"));
     collection.Add(new MimeHeader("name2:value2"));
     collection.Add(new MimeHeader("name3:value3"));
     AssertionHelper.IsTrue("The value for name is value", collection["name"].Value == "value");
     AssertionHelper.IsTrue("The value for name2 is value2", collection["name2"].Value == "value2");
     AssertionHelper.IsTrue("The value for name3 is value3", collection["name3"].Value == "value3");
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="headers">The MimeHeaderCollection over which to enumerate.</param>
 public MimeHeaderEnumerator(MimeHeaderCollection headers)
 {
     _headers = headers;
     _currentIndex = -1;
 }
        /// <summary>
        /// This method checks and adds additional required header fields.  
        /// 1. If it is a text type, add the character set
        /// 2. Check and add Content-Transfer-Encoding
        /// 3. Calculates the content length.  For base64 encoding, this
        /// requires encoding the buffer.  Therefore, the encoded data is stored in
        /// _encodedString for use during the body right when base64 encoding is used.
        /// </summary>
        public void AddAdditionalHeader(MimeHeaderCollection headers)
        {
            //Add Content-Type
            if (!headers.Contains("Content-Type") && _contentType != null)
            {
                MimeHeader mh = new MimeHeader("Content-Type", _contentType);
                //if it is a text type, add the character set
                if (_contentType.StartsWith("text/"))
                {
                    mh.Parameters.Add(new MimeHeaderParam("charset", MimeCharsetToString(_charset)));
                }
                headers.Add(mh);
            }

            //Add Content-Transfer-Encoding
            if (!headers.Contains("Content-Transfer-Encoding") && _encoding != MimeEncoding.E7Bit)
            {
                headers.Add(new MimeHeader("Content-Transfer-Encoding", MimeEncodingToString(_encoding)));
            }

            //Add Content-Disposition: attachment; filename="Job_10235.jdf"
            if (!headers.Contains("Content-Disposition") && _fileName != null)
            {
                headers.Add(new MimeHeader("Content-Disposition", @"attachment; filename=""" + _fileName + @""""));
            }

            //Add Content-Length
            if (_buffer != null)
            {
                int contentLength = 0;
                if (_encoding == MimeEncoding.Base64)
                {
                    _encodedString = Convert.ToBase64String(_buffer, 0, _buffer.Length);
                    contentLength = _encodedString.Length;
                }
                else
                {
                    _encodedString = null;
                    contentLength = _buffer.Length;
                }

                if (contentLength != 0)
                {
                    if (!headers.Contains("Content-Length"))
                    {
                        headers.Add(new MimeHeader("Content-Length", contentLength.ToString()));
                    }
                    else
                    {
                        headers["Content-Length"].Value = contentLength.ToString();
                    }
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Add Content type to the given header
 /// </summary>
 /// <param name="headers">headers to add content typ</param>
 public void AddContentType(MimeHeaderCollection headers)
 {
     if (!headers.Contains("Content-Type") && _contentType != null)
     {
         MimeHeader mh = new MimeHeader("Content-Type", _contentType);
         //if it is a text type, add the character set
         if (_contentType.StartsWith("text/") || _contentType.StartsWith("application/vnd.cip4-j"))
         {
             mh.Parameters.Add(new MimeHeaderParam("charset", Mime.MimeCharsetToString(_charset)));
         }
         headers.Add(mh);
     }
 }
Пример #6
0
        /// <summary>
        /// This method checks and adds additional required header fields.  
        /// 1. If it is a text type, add the character set
        /// 2. Check and add Content-Transfer-Encoding
        /// 3. Calculates the content length.  For base64 encoding, this
        /// requires encoding the buffer.  Therefore, the encoded data is stored in
        /// _encodedString for use during the body right when base64 encoding is used.
        /// </summary>
        public void AddAdditionalHeader(MimeHeaderCollection headers)
        {
            //Add Content-Type
            AddContentType(headers);

            //Add Content-Transfer-Encoding
            if (!headers.Contains("Content-Transfer-Encoding") && _encoding != MimeEncoding.E7Bit)
            {
                headers.Add(new MimeHeader("Content-Transfer-Encoding", Mime.MimeEncodingToString(_encoding)));
            }

            //Add Content-Disposition: attachment; filename="Job_10235.jdf"
            if (!headers.Contains("Content-Disposition") && _fileName != null)
            {
                FileInfo fi = new FileInfo(_fileName);
                MimeHeader mh = new MimeHeader("Content-Disposition", "attachment");
                mh.Parameters.Add(new MimeHeaderParam("filename", fi.Name));
                headers.Add(mh);
            }

            //Add Content-Length
            if (_buffer != null)
            {
                int contentLength = 0;
                if (_encoding == MimeEncoding.Base64)
                {
                    if (EncodedString.Length % 76 > 0)
                    {
                        contentLength = EncodedString.Length / 76 * 2 + EncodedString.Length + 1;
                    }
                    else
                    {
                        contentLength = EncodedString.Length / 76 * 2 + EncodedString.Length;
                    }

                }
                else
                {
                    _encodedString = null;
                    contentLength = _buffer.Length;
                }

                if (contentLength != 0)
                {
                    if (!headers.Contains("Content-Length"))
                    {
                        headers.Add(new MimeHeader("Content-Length", contentLength.ToString()));
                    }
                    else
                    {
                        headers["Content-Length"].Value = contentLength.ToString();
                    }
                }
            }
        }
 public void CollectionItemReplacement()
 {
     MimeHeaderCollection collection = new MimeHeaderCollection();
     collection.Add(new MimeHeader("name:value"));
     AssertionHelper.IsTrue("The value for name is value", collection["name"].Value == "value");
     collection.Add(new MimeHeader("name:value2"));
     AssertionHelper.IsTrue("The value for name is value2", collection["name"].Value == "value2");
 }
 public void CollectionItemCase()
 {
     MimeHeaderCollection collection = new MimeHeaderCollection();
     collection.Add(new MimeHeader("NAME:value2"));
     AssertionHelper.IsTrue("The value for name is value2", collection["name"].Value == "value2");
     AssertionHelper.IsTrue("The value for Name is value2", collection["Name"].Value == "value2");
 }