예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.Header"/> class.
        /// </summary>
        /// <remarks>
        /// Creates a new message or entity header for the specified field and
        /// value pair. The encoding is used to determine which charset to use
        /// when encoding the value according to the rules of rfc2047.
        /// </remarks>
        /// <param name="charset">The charset that should be used to encode the
        /// header value.</param>
        /// <param name="id">The header identifier.</param>
        /// <param name="value">The value of the header.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="charset"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="value"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
        /// </exception>
        /// <exception cref="System.ArgumentException">
        /// <paramref name="charset"/> cannot be empty.
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        /// <paramref name="charset"/> is not supported.
        /// </exception>
        public Header(string charset, HeaderId id, string value)
        {
            if (charset == null)
            {
                throw new ArgumentNullException("charset");
            }

            if (charset.Length == 0)
            {
                throw new ArgumentException("The charset name cannot be empty.", "charset");
            }

            if (id == HeaderId.Unknown)
            {
                throw new ArgumentOutOfRangeException("id");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var encoding = CharsetUtils.GetEncoding(charset);

            Options = ParserOptions.Default.Clone();
            Field   = id.ToHeaderName();
            Id      = id;

            SetValue(encoding, value);
        }
예제 #2
0
        /// <summary>
        /// Checks if the <see cref="MimeKit.HeaderList"/> contains a header with the specified field name.
        /// </summary>
        /// <remarks>
        /// Determines whether or not the header list contains the specified header.
        /// </remarks>
        /// <returns><value>true</value> if the requested header exists;
        /// otherwise <value>false</value>.</returns>
        /// <param name="id">The header identifier.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
        /// </exception>
        public bool Contains(HeaderId id)
        {
            if (id == HeaderId.Unknown)
            {
                throw new ArgumentOutOfRangeException("id");
            }

            return(table.ContainsKey(id.ToHeaderName()));
        }
예제 #3
0
파일: HeaderSet.cs 프로젝트: zamis/MailKit
        /// <summary>
        /// Check if the set of headers contains the specified header.
        /// </summary>
        /// <remarks>
        /// Determines whether or not the set of headers contains the specified header.
        /// </remarks>
        /// <returns><value>true</value> if the specified header exists;
        /// otherwise <value>false</value>.</returns>
        /// <param name="header">The header identifier.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="header"/> is not a valid <see cref="HeaderId"/>.
        /// </exception>
        public bool Contains(HeaderId header)
        {
            if (header == HeaderId.Unknown)
            {
                throw new ArgumentOutOfRangeException(nameof(header));
            }

            return(hash.Contains(header.ToHeaderName().ToUpperInvariant()));
        }
예제 #4
0
파일: HeaderSet.cs 프로젝트: zamis/MailKit
        /// <summary>
        /// Remove the specified header.
        /// </summary>
        /// <remarks>
        /// Removes the specified header if it exists.
        /// </remarks>
        /// <returns><c>true</c> if the specified header was removed;
        /// otherwise <c>false</c>.</returns>
        /// <param name="header">The header.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="header"/> is not a valid <see cref="HeaderId"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// The operation is invalid because the <see cref="HeaderSet"/> is read-only.
        /// </exception>
        public bool Remove(HeaderId header)
        {
            if (header == HeaderId.Unknown)
            {
                throw new ArgumentOutOfRangeException(nameof(header));
            }

            CheckReadOnly();

            return(hash.Remove(header.ToHeaderName().ToUpperInvariant()));
        }
예제 #5
0
        /// <summary>
        /// Gets or sets the value of the first occurance of a header
        /// with the specified field name.
        /// </summary>
        /// <remarks>
        /// Gets or sets the value of the first occurance of a header
        /// with the specified field name.
        /// </remarks>
        /// <value>The value of the first occurrance of the specified header if it exists; otherwise <c>null</c>.</value>
        /// <param name="id">The header identifier.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="value"/> is <c>null</c>.
        /// </exception>
        public string this [HeaderId id] {
            get {
                if (id == HeaderId.Unknown)
                {
                    throw new ArgumentOutOfRangeException("id");
                }

                Header header;
                if (table.TryGetValue(id.ToHeaderName(), out header))
                {
                    return(header.Value);
                }

                return(null);
            }
            set {
                if (id == HeaderId.Unknown)
                {
                    throw new ArgumentOutOfRangeException("id");
                }

                if (value == null)
                {
                    throw new ArgumentNullException("value");
                }

                Header header;
                if (table.TryGetValue(id.ToHeaderName(), out header))
                {
                    header.Value = value;
                }
                else
                {
                    Add(id, value);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Removes the first occurance of the specified header field.
        /// </summary>
        /// <remarks>
        /// Removes the first occurance of the specified header field, if any exist.
        /// </remarks>
        /// <returns><value>true</value> if the first occurance of the specified
        /// header was removed; otherwise <value>false</value>.</returns>
        /// <param name="id">The header identifier.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="id"/> is is not a valid <see cref="HeaderId"/>.
        /// </exception>
        public bool Remove(HeaderId id)
        {
            if (id == HeaderId.Unknown)
            {
                throw new ArgumentNullException("id");
            }

            Header header;

            if (!table.TryGetValue(id.ToHeaderName(), out header))
            {
                return(false);
            }

            return(Remove(header));
        }
예제 #7
0
파일: Header.cs 프로젝트: gphummer/MimeKit
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.Header"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new message or entity header for the specified field and
		/// value pair. The encoding is used to determine which charset to use
		/// when encoding the value according to the rules of rfc2047.
		/// </remarks>
		/// <param name="charset">The charset that should be used to encode the
		/// header value.</param>
		/// <param name="id">The header identifier.</param>
		/// <param name="value">The value of the header.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="charset"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="value"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
		/// </exception>
		public Header (Encoding charset, HeaderId id, string value)
		{
			if (charset == null)
				throw new ArgumentNullException ("charset");

			if (id == HeaderId.Unknown)
				throw new ArgumentOutOfRangeException ("id");

			if (value == null)
				throw new ArgumentNullException ("value");

			Options = ParserOptions.Default.Clone ();
			Field = id.ToHeaderName ();
			Id = id;

			SetValue (charset, value);
		}
예제 #8
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.Header"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new message or entity header for the specified field and
		/// value pair. The encoding is used to determine which charset to use
		/// when encoding the value according to the rules of rfc2047.
		/// </remarks>
		/// <param name="encoding">The character encoding that should be used to
		/// encode the header value.</param>
		/// <param name="id">The header identifier.</param>
		/// <param name="value">The value of the header.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="encoding"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="value"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
		/// </exception>
		public Header (Encoding encoding, HeaderId id, string value)
		{
			if (encoding == null)
				throw new ArgumentNullException ("encoding");

			if (id == HeaderId.Unknown)
				throw new ArgumentOutOfRangeException ("id");

			if (value == null)
				throw new ArgumentNullException ("value");

			Options = ParserOptions.Default.Clone ();
			Field = id.ToHeaderName ();
			Id = id;

			rawField = Encoding.ASCII.GetBytes (Field);
			SetValue (encoding, value);
		}
예제 #9
0
        /// <summary>
        /// Removes all of the headers matching the specified field name.
        /// </summary>
        /// <remarks>
        /// Removes all of the headers matching the specified field name.
        /// </remarks>
        /// <param name="id">The header identifier.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
        /// </exception>
        public void RemoveAll(HeaderId id)
        {
            if (id == HeaderId.Unknown)
            {
                throw new ArgumentNullException("field");
            }

            table.Remove(id.ToHeaderName());

            for (int i = headers.Count - 1; i >= 0; i--)
            {
                if (headers[i].Id != id)
                {
                    continue;
                }

                var header = headers[i];
                headers.RemoveAt(i);

                OnChanged(header, HeaderListChangedAction.Removed);
            }
        }
예제 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeKit.Header"/> class.
        /// </summary>
        /// <param name="charset">The charset that should be used to encode the
        /// header value.</param>
        /// <param name="id">The header identifier.</param>
        /// <param name="value">The value of the header.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="charset"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="value"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
        /// </exception>
        public Header(Encoding charset, HeaderId id, string value)
        {
            if (charset == null)
            {
                throw new ArgumentNullException("charset");
            }

            if (id == HeaderId.Unknown)
            {
                throw new ArgumentOutOfRangeException("id");
            }

            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            Options = ParserOptions.Default.Clone();
            Field   = id.ToHeaderName();
            Id      = id;

            SetValue(charset, value);
        }
예제 #11
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.Header"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new message or entity header for the specified field and
		/// value pair. The encoding is used to determine which charset to use
		/// when encoding the value according to the rules of rfc2047.
		/// </remarks>
		/// <param name="charset">The charset that should be used to encode the
		/// header value.</param>
		/// <param name="id">The header identifier.</param>
		/// <param name="value">The value of the header.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="charset"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="value"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="charset"/> cannot be empty.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// <paramref name="charset"/> is not supported.
		/// </exception>
		public Header (string charset, HeaderId id, string value)
		{
			if (charset == null)
				throw new ArgumentNullException ("charset");

			if (charset.Length == 0)
				throw new ArgumentException ("The charset name cannot be empty.", "charset");

			if (id == HeaderId.Unknown)
				throw new ArgumentOutOfRangeException ("id");

			if (value == null)
				throw new ArgumentNullException ("value");

			var encoding = CharsetUtils.GetEncoding (charset);
			Options = ParserOptions.Default.Clone ();
			Field = id.ToHeaderName ();
			Id = id;

			rawField = Encoding.ASCII.GetBytes (Field);
			SetValue (encoding, value);
		}
예제 #12
0
        internal static Dictionary <string, string> ParseParameterTags(HeaderId header, string signature)
        {
            var parameters = new Dictionary <string, string> ();
            var value      = new StringBuilder();
            int index      = 0;

            while (index < signature.Length)
            {
                while (index < signature.Length && IsWhiteSpace(signature[index]))
                {
                    index++;
                }

                if (index >= signature.Length)
                {
                    break;
                }

                if (signature[index] == ';' || !IsAlpha(signature[index]))
                {
                    throw new FormatException(string.Format("Malformed {0} value.", header.ToHeaderName()));
                }

                int startIndex = index++;

                while (index < signature.Length && signature[index] != '=')
                {
                    index++;
                }

                if (index >= signature.Length)
                {
                    continue;
                }

                var name = signature.Substring(startIndex, index - startIndex).TrimEnd();

                // skip over '=' and clear value buffer
                value.Length = 0;
                index++;

                while (index < signature.Length && signature[index] != ';')
                {
                    if (!IsWhiteSpace(signature[index]))
                    {
                        value.Append(signature[index]);
                    }
                    index++;
                }

                if (parameters.ContainsKey(name))
                {
                    throw new FormatException(string.Format("Malformed {0} value: duplicate parameter '{1}'.", header.ToHeaderName(), name));
                }

                parameters.Add(name, value.ToString());

                // skip over ';'
                index++;
            }

            return(parameters);
        }
예제 #13
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MimeKit.Header"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new message or entity header for the specified field and
		/// value pair. The encoding is used to determine which charset to use
		/// when encoding the value according to the rules of rfc2047.
		/// </remarks>
		/// <param name="charset">The charset that should be used to encode the
		/// header value.</param>
		/// <param name="id">The header identifier.</param>
		/// <param name="value">The value of the header.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="charset"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="value"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// <paramref name="charset"/> is not supported.
		/// </exception>
		public Header (string charset, HeaderId id, string value)
		{
			if (charset == null)
				throw new ArgumentNullException (nameof (charset));

			if (id == HeaderId.Unknown)
				throw new ArgumentOutOfRangeException (nameof (id));

			if (value == null)
				throw new ArgumentNullException (nameof (value));

			var encoding = CharsetUtils.GetEncoding (charset);
			Options = ParserOptions.Default.Clone ();
			Field = id.ToHeaderName ();
			Id = id;

			rawField = Encoding.ASCII.GetBytes (Field);
			SetValue (encoding, value);
		}