コード例 #1
0
ファイル: GroupAddress.cs プロジェクト: ywscr/MimeKit
        static bool TryParse(ParserOptions options, byte[] text, ref int index, int endIndex, bool throwOnError, out GroupAddress group)
        {
            var             flags = AddressParserFlags.AllowGroupAddress;
            InternetAddress address;

            if (throwOnError)
            {
                flags |= AddressParserFlags.ThrowOnError;
            }

            if (!InternetAddress.TryParse(options, text, ref index, endIndex, 0, flags, out address))
            {
                group = null;
                return(false);
            }

            group = (GroupAddress)address;

            return(true);
        }
コード例 #2
0
ファイル: GroupAddress.cs プロジェクト: ywscr/MimeKit
        /// <summary>
        /// Try to parse the given input buffer into a new <see cref="GroupAddress"/> instance.
        /// </summary>
        /// <remarks>
        /// Parses a single <see cref="GroupAddress"/>. If the address is not a group address or
        /// there is more than a single group address, then parsing will fail.
        /// </remarks>
        /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
        /// <param name="options">The parser options to use.</param>
        /// <param name="buffer">The input buffer.</param>
        /// <param name="startIndex">The starting index of the input buffer.</param>
        /// <param name="length">The number of bytes in the input buffer to parse.</param>
        /// <param name="group">The parsed group address.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="options"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="buffer"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="startIndex"/> and <paramref name="length"/> do not specify
        /// a valid range in the byte array.
        /// </exception>
        public static bool TryParse(ParserOptions options, byte[] buffer, int startIndex, int length, out GroupAddress group)
        {
            ParseUtils.ValidateArguments(options, buffer, startIndex, length);

            int endIndex = startIndex + length;
            int index    = startIndex;

            if (!TryParse(options, buffer, ref index, endIndex, false, out group))
            {
                return(false);
            }

            if (!ParseUtils.SkipCommentsAndWhiteSpace(buffer, ref index, endIndex, false) || index != endIndex)
            {
                group = null;
                return(false);
            }

            return(true);
        }
コード例 #3
0
 /// <summary>
 /// Tries to parse the given input buffer into a new <see cref="MimeKit.GroupAddress"/> instance.
 /// </summary>
 /// <remarks>
 /// Parses a single <see cref="GroupAddress"/>. If the address is not a group address or
 /// there is more than a single group address, then parsing will fail.
 /// </remarks>
 /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
 /// <param name="buffer">The input buffer.</param>
 /// <param name="group">The parsed group address.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="buffer"/> is <c>null</c>.
 /// </exception>
 public static bool TryParse(byte[] buffer, out GroupAddress group)
 {
     return(TryParse(ParserOptions.Default, buffer, out group));
 }
コード例 #4
0
 /// <summary>
 /// Tries to parse the given text into a new <see cref="MimeKit.GroupAddress"/> instance.
 /// </summary>
 /// <remarks>
 /// Parses a single <see cref="GroupAddress"/>. If the address is not a group address or
 /// there is more than a single group address, then parsing will fail.
 /// </remarks>
 /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
 /// <param name="text">The text.</param>
 /// <param name="group">The parsed group address.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="text"/> is <c>null</c>.
 /// </exception>
 public static bool TryParse(string text, out GroupAddress group)
 {
     return(TryParse(ParserOptions.Default, text, out group));
 }
コード例 #5
0
		/// <summary>
		/// Tries to parse the given text into a new <see cref="MimeKit.GroupAddress"/> instance.
		/// </summary>
		/// <remarks>
		/// Parses a single <see cref="GroupAddress"/>. If the the address is not a group address or
		/// there is more than a single group address, then parsing will fail.
		/// </remarks>
		/// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
		/// <param name="text">The text.</param>
		/// <param name="group">The parsed group address.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="text"/> is <c>null</c>.
		/// </exception>
		public static bool TryParse (string text, out GroupAddress group)
		{
			return TryParse (ParserOptions.Default, text, out group);
		}
コード例 #6
0
        /// <summary>
        /// Tries to parse the given input buffer into a new <see cref="MimeKit.GroupAddress"/> instance.
        /// </summary>
        /// <remarks>
        /// Parses a single <see cref="GroupAddress"/>. If the address is not a group address or
        /// there is more than a single group address, then parsing will fail.
        /// </remarks>
        /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
        /// <param name="options">The parser options to use.</param>
        /// <param name="buffer">The input buffer.</param>
        /// <param name="startIndex">The starting index of the input buffer.</param>
        /// <param name="group">The parsed group address.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="options"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="buffer"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="startIndex"/> is out of range.
        /// </exception>
        public static bool TryParse(ParserOptions options, byte[] buffer, int startIndex, out GroupAddress group)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

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

            if (startIndex < 0 || startIndex >= buffer.Length)
            {
                throw new ArgumentOutOfRangeException("startIndex");
            }

            int endIndex = buffer.Length;
            int index    = startIndex;

            if (!TryParse(options, buffer, ref index, endIndex, false, out group))
            {
                return(false);
            }

            if (!ParseUtils.SkipCommentsAndWhiteSpace(buffer, ref index, endIndex, false) || index != endIndex)
            {
                group = null;
                return(false);
            }

            return(true);
        }
コード例 #7
0
		/// <summary>
		/// Tries to parse the given input buffer into a new <see cref="MimeKit.GroupAddress"/> instance.
		/// </summary>
		/// <remarks>
		/// Parses a single <see cref="GroupAddress"/>. If the the address is not a group address or
		/// there is more than a single group address, then parsing will fail.
		/// </remarks>
		/// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
		/// <param name="buffer">The input buffer.</param>
		/// <param name="group">The parsed group address.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="buffer"/> is <c>null</c>.
		/// </exception>
		public static bool TryParse (byte[] buffer, out GroupAddress group)
		{
			return TryParse (ParserOptions.Default, buffer, out group);
		}
コード例 #8
0
        /// <summary>
        /// Tries to parse the given input buffer into a new <see cref="MimeKit.GroupAddress"/> instance.
        /// </summary>
        /// <remarks>
        /// Parses a single <see cref="GroupAddress"/>. If the the address is not a group address or
        /// there is more than a single group address, then parsing will fail.
        /// </remarks>
        /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
        /// <param name="options">The parser options to use.</param>
        /// <param name="buffer">The input buffer.</param>
        /// <param name="startIndex">The starting index of the input buffer.</param>
        /// <param name="group">The parsed group address.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="options"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="buffer"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="startIndex"/> is out of range.
        /// </exception>
        public static bool TryParse(ParserOptions options, byte[] buffer, int startIndex, out GroupAddress group)
        {
            InternetAddress address;

            if (!InternetAddress.TryParse(options, buffer, startIndex, out address))
            {
                group = null;
                return(false);
            }

            group = address as GroupAddress;

            return(group != null);
        }
コード例 #9
0
		/// <summary>
		/// Tries to parse the given input buffer into a new <see cref="MimeKit.GroupAddress"/> instance.
		/// </summary>
		/// <remarks>
		/// Parses a single <see cref="GroupAddress"/>. If the the address is not a group address or
		/// there is more than a single group address, then parsing will fail.
		/// </remarks>
		/// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
		/// <param name="buffer">The input buffer.</param>
		/// <param name="startIndex">The starting index of the input buffer.</param>
		/// <param name="length">The number of bytes in the input buffer to parse.</param>
		/// <param name="group">The parsed group address.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="buffer"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="startIndex"/> and <paramref name="length"/> do not specify
		/// a valid range in the byte array.
		/// </exception>
		public static bool TryParse (byte[] buffer, int startIndex, int length, out GroupAddress group)
		{
			return TryParse (ParserOptions.Default, buffer, startIndex, length, out group);
		}
コード例 #10
0
		/// <summary>
		/// Tries to parse the given input buffer into a new <see cref="MimeKit.GroupAddress"/> instance.
		/// </summary>
		/// <remarks>
		/// Parses a single <see cref="GroupAddress"/>. If the the address is not a group address or
		/// there is more than a single group address, then parsing will fail.
		/// </remarks>
		/// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
		/// <param name="options">The parser options to use.</param>
		/// <param name="buffer">The input buffer.</param>
		/// <param name="startIndex">The starting index of the input buffer.</param>
		/// <param name="group">The parsed group address.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="options"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="buffer"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// <paramref name="startIndex"/> is out of range.
		/// </exception>
		public static bool TryParse (ParserOptions options, byte[] buffer, int startIndex, out GroupAddress group)
		{
			InternetAddress address;

			if (!InternetAddress.TryParse (options, buffer, startIndex, out address)) {
				group = null;
				return false;
			}

			group = address as GroupAddress;

			return group != null;
		}
コード例 #11
0
ファイル: GroupAddress.cs プロジェクト: cybercircuits/MimeKit
		/// <summary>
		/// Tries to parse the given text into a new <see cref="MimeKit.GroupAddress"/> instance.
		/// </summary>
		/// <remarks>
		/// Parses a single <see cref="GroupAddress"/>. If the address is not a group address or
		/// there is more than a single group address, then parsing will fail.
		/// </remarks>
		/// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
		/// <param name="options">The parser options to use.</param>
		/// <param name="text">The text.</param>
		/// <param name="group">The parsed group address.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="text"/> is <c>null</c>.
		/// </exception>
		public static bool TryParse (ParserOptions options, string text, out GroupAddress group)
		{
			if (options == null)
				throw new ArgumentNullException (nameof (options));

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

			var buffer = Encoding.UTF8.GetBytes (text);
			int endIndex = buffer.Length;
			int index = 0;

			if (!TryParse (options, buffer, ref index, endIndex, false, out group))
				return false;

			if (!ParseUtils.SkipCommentsAndWhiteSpace (buffer, ref index, endIndex, false) || index != endIndex) {
				group = null;
				return false;
			}

			return true;
		}
コード例 #12
0
ファイル: GroupAddress.cs プロジェクト: cybercircuits/MimeKit
		/// <summary>
		/// Tries to parse the given input buffer into a new <see cref="MimeKit.GroupAddress"/> instance.
		/// </summary>
		/// <remarks>
		/// Parses a single <see cref="GroupAddress"/>. If the address is not a group address or
		/// there is more than a single group address, then parsing will fail.
		/// </remarks>
		/// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
		/// <param name="options">The parser options to use.</param>
		/// <param name="buffer">The input buffer.</param>
		/// <param name="group">The parsed group address.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="options"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="buffer"/> is <c>null</c>.</para>
		/// </exception>
		public static bool TryParse (ParserOptions options, byte[] buffer, out GroupAddress group)
		{
			ParseUtils.ValidateArguments (options, buffer);

			int endIndex = buffer.Length;
			int index = 0;

			if (!TryParse (options, buffer, ref index, endIndex, false, out group))
				return false;

			if (!ParseUtils.SkipCommentsAndWhiteSpace (buffer, ref index, endIndex, false) || index != endIndex) {
				group = null;
				return false;
			}

			return true;
		}
コード例 #13
0
ファイル: GroupAddress.cs プロジェクト: cybercircuits/MimeKit
		static bool TryParse (ParserOptions options, byte[] text, ref int index, int endIndex, bool throwOnError, out GroupAddress group)
		{
			var flags = AddressParserFlags.AllowGroupAddress;
			InternetAddress address;

			if (throwOnError)
				flags |= AddressParserFlags.ThrowOnError;

			if (!InternetAddress.TryParse (options, text, ref index, endIndex, flags, out address)) {
				group = null;
				return false;
			}

			group = (GroupAddress) address;

			return true;
		}
コード例 #14
0
ファイル: GroupAddress.cs プロジェクト: ywscr/MimeKit
 /// <summary>
 /// Try to parse the given input buffer into a new <see cref="GroupAddress"/> instance.
 /// </summary>
 /// <remarks>
 /// Parses a single <see cref="GroupAddress"/>. If the address is not a group address or
 /// there is more than a single group address, then parsing will fail.
 /// </remarks>
 /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
 /// <param name="buffer">The input buffer.</param>
 /// <param name="startIndex">The starting index of the input buffer.</param>
 /// <param name="length">The number of bytes in the input buffer to parse.</param>
 /// <param name="group">The parsed group address.</param>
 /// <exception cref="System.ArgumentNullException">
 /// <paramref name="buffer"/> is <c>null</c>.
 /// </exception>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// <paramref name="startIndex"/> and <paramref name="length"/> do not specify
 /// a valid range in the byte array.
 /// </exception>
 public static bool TryParse(byte[] buffer, int startIndex, int length, out GroupAddress group)
 {
     return(TryParse(ParserOptions.Default, buffer, startIndex, length, out group));
 }
コード例 #15
0
		/// <summary>
		/// Tries to parse the given text into a new <see cref="MimeKit.GroupAddress"/> instance.
		/// </summary>
		/// <remarks>
		/// Parses a single <see cref="GroupAddress"/>. If the the address is not a group address or
		/// there is more than a single group address, then parsing will fail.
		/// </remarks>
		/// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns>
		/// <param name="options">The parser options to use.</param>
		/// <param name="text">The text.</param>
		/// <param name="group">The parsed group address.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="text"/> is <c>null</c>.
		/// </exception>
		public static bool TryParse (ParserOptions options, string text, out GroupAddress group)
		{
			InternetAddress address;

			if (!InternetAddress.TryParse (options, text, out address)) {
				group = null;
				return false;
			}

			group = address as GroupAddress;

			return group != null;
		}
コード例 #16
0
        static bool TryParseGroup(ParserOptions options, byte[] text, int startIndex, ref int index, int endIndex, string name, int codepage, bool throwOnError, out InternetAddress address)
        {
            Encoding encoding = Encoding.GetEncoding (codepage);
            List<InternetAddress> members;

            address = null;

            // skip over the ':'
            index++;
            if (index >= endIndex) {
                if (throwOnError)
                    throw new ParseException (string.Format ("Incomplete address group at offset {0}", startIndex), startIndex, index);

                return false;
            }

            if (InternetAddressList.TryParse (options, text, ref index, endIndex, true, throwOnError, out members))
                address = new GroupAddress (encoding, name, members);
            else
                address = new GroupAddress (encoding, name);

            if (index >= endIndex || text[index] != (byte) ';') {
                if (throwOnError)
                    throw new ParseException (string.Format ("Expected to find ';' at offset {0}", index), startIndex, index);

                while (index < endIndex && text[index] != (byte) ';')
                    index++;
            } else {
                index++;
            }

            return true;
        }
コード例 #17
0
		public void TestCompareTo ()
		{
			var list1 = new InternetAddressList ();

			list1.Add (new GroupAddress ("Local recipients", new InternetAddress[] {
				new MailboxAddress ("", "phil"),
				new MailboxAddress ("", "joe"),
				new MailboxAddress ("", "alex"),
				new MailboxAddress ("", "bob"),
			}));
			list1.Add (new MailboxAddress ("Joey", "*****@*****.**"));
			list1.Add (new MailboxAddress ("Chandler", "*****@*****.**"));

			var list2 = new InternetAddressList ();

			list2.Add (new MailboxAddress ("Chandler", "*****@*****.**"));
			list2.Add (new GroupAddress ("Local recipients", new InternetAddress[] {
				new MailboxAddress ("", "phil"),
				new MailboxAddress ("", "joe"),
				new MailboxAddress ("", "alex"),
				new MailboxAddress ("", "bob"),
			}));
			list2.Add (new MailboxAddress ("Joey", "*****@*****.**"));

			Assert.IsTrue (list1.CompareTo (list2) > 0, "CompareTo() should return < 0.");
			Assert.IsTrue (list2.CompareTo (list1) < 0, "CompareTo() should return > 0.");

			var mailbox = new MailboxAddress ("Joe", "*****@*****.**");
			var group = new GroupAddress ("Joe", new InternetAddress[] {
				new MailboxAddress ("Joe", "*****@*****.**")
			});

			// MailboxAddresses with the same name should always sort first
			Assert.IsTrue (mailbox.CompareTo (group) < 0, "CompareTo() should return < 0.");
			Assert.IsTrue (group.CompareTo (mailbox) > 0, "CompareTo() should return > 0.");

			Assert.IsTrue (mailbox.CompareTo (group.Members[0]) == 0, "CompareTo() should return 0.");
		}