当前位置: 首页>>代码示例>>C#>>正文


C# InternetAddressList.Add方法代码示例

本文整理汇总了C#中InternetAddressList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# InternetAddressList.Add方法的具体用法?C# InternetAddressList.Add怎么用?C# InternetAddressList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InternetAddressList的用法示例。


在下文中一共展示了InternetAddressList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestEncodingMailboxWithArabicName

        public void TestEncodingMailboxWithArabicName()
        {
            var mailbox = new MailboxAddress ("هل تتكلم اللغة الإنجليزية /العربية؟", "[email protected]");
            var list = new InternetAddressList ();
            list.Add (mailbox);

            var expected = "=?utf-8?b?2YfZhCDYqtiq2YPZhNmFINin2YTZhNi62Kk=?=\n =?utf-8?b?INin2YTYpdmG2KzZhNmK2LLZitipIC/Yp9mE2LnYsdio2YrYqdif?=\n\t<[email protected]>";
            var actual = list.ToString (UnixFormatOptions, true);

            Assert.AreEqual (expected, actual, "Encoding arabic mailbox did not match expected result: {0}", expected);
            Assert.IsTrue (InternetAddressList.TryParse (actual, out list), "Failed to parse arabic mailbox");
            Assert.AreEqual (mailbox.Name, list[0].Name);
        }
开发者ID:hultqvist,项目名称:MimeKit,代码行数:13,代码来源:InternetAddressListTests.cs

示例2: TestSimpleAddrSpec

		public void TestSimpleAddrSpec ()
		{
			var expected = new InternetAddressList ();
			var mailbox = new MailboxAddress ("", "");
			InternetAddressList result;
			string text;

			expected.Add (mailbox);

			text = "[email protected]";
			mailbox.Address = "[email protected]";
			Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
			AssertInternetAddressListsEqual (text, expected, result);

			result = InternetAddressList.Parse (text);
			AssertInternetAddressListsEqual (text, expected, result);

			text = "fejj";
			mailbox.Address = "fejj";
			Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
			AssertInternetAddressListsEqual (text, expected, result);

			result = InternetAddressList.Parse (text);
			AssertInternetAddressListsEqual (text, expected, result);
		}
开发者ID:gphummer,项目名称:MimeKit,代码行数:25,代码来源:InternetAddressListTests.cs

示例3: TestArgumentExceptions

		public void TestArgumentExceptions ()
		{
			var mailbox = new MailboxAddress ("MimeKit Unit Tests", "[email protected]");
			var list = new InternetAddressList ();

			list.Add (new MailboxAddress ("Example User", "[email protected]"));

			Assert.Throws<ArgumentNullException> (() => new InternetAddressList (null));
			Assert.Throws<ArgumentNullException> (() => list.Add (null));
			Assert.Throws<ArgumentNullException> (() => list.AddRange (null));
			Assert.Throws<ArgumentNullException> (() => list.CompareTo (null));
			Assert.Throws<ArgumentNullException> (() => list.Contains (null));
			Assert.Throws<ArgumentNullException> (() => list.CopyTo (null, 0));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.CopyTo (new InternetAddress[0], -1));
			Assert.Throws<ArgumentNullException> (() => list.IndexOf (null));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, mailbox));
			Assert.Throws<ArgumentNullException> (() => list.Insert (0, null));
			Assert.Throws<ArgumentNullException> (() => list.Remove (null));
			Assert.Throws<ArgumentOutOfRangeException> (() => list.RemoveAt (-1));
			Assert.Throws<ArgumentOutOfRangeException> (() => list[-1] = mailbox);
			Assert.Throws<ArgumentNullException> (() => list[0] = null);
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:22,代码来源:InternetAddressListTests.cs

示例4: TestDecodedMailboxHasCorrectCharsetEncoding

        public void TestDecodedMailboxHasCorrectCharsetEncoding()
        {
            var latin1 = Encoding.GetEncoding ("iso-8859-1");
            var mailbox = new MailboxAddress (latin1, "Kristoffer Brånemyr", "[email protected]");
            var list = new InternetAddressList ();
            list.Add (mailbox);

            var encoded = list.ToString (UnixFormatOptions, true);

            InternetAddressList parsed;
            Assert.IsTrue (InternetAddressList.TryParse (encoded, out parsed), "Failed to parse address");
            Assert.AreEqual (latin1.HeaderName, parsed[0].Encoding.HeaderName, "Parsed charset does not match");
        }
开发者ID:hultqvist,项目名称:MimeKit,代码行数:13,代码来源:InternetAddressListTests.cs

示例5: TestMailboxWithDotsInTheName

        public void TestMailboxWithDotsInTheName()
        {
            var expected = new InternetAddressList ();
            InternetAddressList result;
            string text;

            text = "Nathaniel S. Borenstein <[email protected]>";

            expected.Add (new MailboxAddress ("Nathaniel S. Borenstein", "[email protected]"));

            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);
        }
开发者ID:hultqvist,项目名称:MimeKit,代码行数:16,代码来源:InternetAddressListTests.cs

示例6: TestEquality

		public void TestEquality ()
		{
			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", "[email protected]"));
			list1.Add (new MailboxAddress ("Chandler", "[email protected]"));

			var list2 = new InternetAddressList ();

			list2.Add (new MailboxAddress ("Chandler", "[email protected]"));
			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", "[email protected]"));

			Assert.IsTrue (list1.Equals (list2), "The 2 lists should be equal.");
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:26,代码来源:InternetAddressListTests.cs

示例7: TestEncodingSimpleAddressList

		public void TestEncodingSimpleAddressList ()
		{
			const string expectedEncoded = "Kristoffer =?iso-8859-1?q?Br=E5nemyr?= <[email protected]>, Jeffrey Stedfast\n\t<[email protected]>";
			const string expectedDisplay = "\"Kristoffer Brånemyr\" <[email protected]>, \"Jeffrey Stedfast\" <[email protected]>";
			var latin1 = Encoding.GetEncoding ("iso-8859-1");
			var options = FormatOptions.Default.Clone ();
			var list = new InternetAddressList ();

			list.Add (new MailboxAddress (latin1, "Kristoffer Brånemyr", "[email protected]"));
			list.Add (new MailboxAddress ("Jeffrey Stedfast", "[email protected]"));

			options.NewLineFormat = NewLineFormat.Unix;

			var display = list.ToString (options, false);
			Assert.AreEqual (expectedDisplay, display, "Display value does not match the expected result: {0}", display);

			var encoded = list.ToString (options, true);
			Assert.AreEqual (expectedEncoded, encoded, "Encoded value does not match the expected result: {0}", display);
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:19,代码来源:InternetAddressListTests.cs

示例8: TestEncodingMailboxWithReallyLongWord

		public void TestEncodingMailboxWithReallyLongWord ()
		{
			const string expected = "=?us-ascii?q?reeeeeeeeeeeeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaallllllllllll?=\n =?us-ascii?q?llllllllllllllllllllllllllllllllllllllllllly?= long word\n\t<[email protected]>";
			const string name = "reeeeeeeeeeeeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaallllllllllllllllllllllllllllllllllllllllllllllllllllllly long word";
			var mailbox = new MailboxAddress (name, "[email protected]");
			var list = new InternetAddressList ();
			list.Add (mailbox);

			var actual = list.ToString (UnixFormatOptions, true);

			Assert.AreEqual (expected, actual, "Encoding really long mailbox did not match expected result: {0}", expected);
			Assert.IsTrue (InternetAddressList.TryParse (actual, out list), "Failed to parse really long mailbox");
			Assert.AreEqual (mailbox.Name, list[0].Name);
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:14,代码来源:InternetAddressListTests.cs

示例9: TestObsoleteMailboxRoutingSyntaxWithEmptyDomains

		public void TestObsoleteMailboxRoutingSyntaxWithEmptyDomains ()
		{
			const string text = "Routed Address <@route1,,@route2,,,@route3:[email protected]>";
			const string encoded = "Routed Address <@route1,@route2,@route3:[email protected]>";
			var expected = new InternetAddressList ();

			expected.Add (new MailboxAddress ("Routed Address", new [] { "route1", "route2", "route3" }, "[email protected]"));

			AssertParseAndTryParse (text, encoded, expected);
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:10,代码来源:InternetAddressListTests.cs

示例10: TestMailboxWith8bitName

		public void TestMailboxWith8bitName ()
		{
			const string encoded = "Patrik =?iso-8859-1?b?RqVkbHRzdHKldm0=?= <[email protected]>";
			const string text = "Patrik F¥dltstr¥vm <[email protected]>";
			var expected = new InternetAddressList ();

			expected.Add (new MailboxAddress ("Patrik F¥dltstr¥vm", "[email protected]"));

			AssertParseAndTryParse (text, encoded, expected);
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:10,代码来源:InternetAddressListTests.cs

示例11: TestSimpleAddrSpec

		public void TestSimpleAddrSpec ()
		{
			var expected = new InternetAddressList ();
			var mailbox = new MailboxAddress ("", "");
			string text;

			expected.Add (mailbox);

			text = "[email protected]";
			mailbox.Address = "[email protected]";
			AssertParseAndTryParse (text, text, expected);

			text = "fejj";
			mailbox.Address = "fejj";
			AssertParseAndTryParse (text, text, expected);
		}
开发者ID:cybercircuits,项目名称:MimeKit,代码行数:16,代码来源:InternetAddressListTests.cs

示例12: ParseEnvelopeAddressList

		static void ParseEnvelopeAddressList (InternetAddressList list, ImapEngine engine, CancellationToken cancellationToken)
		{
			var token = engine.ReadToken (cancellationToken);

			if (token.Type == ImapTokenType.Nil)
				return;

			if (token.Type != ImapTokenType.OpenParen)
				throw ImapEngine.UnexpectedToken (token, false);

			GroupAddress group = null;

			do {
				token = engine.ReadToken (cancellationToken);

				if (token.Type == ImapTokenType.CloseParen)
					break;

				if (token.Type != ImapTokenType.OpenParen)
					throw ImapEngine.UnexpectedToken (token, false);

				var item = ParseEnvelopeAddress (engine, cancellationToken);

				if (item.IsGroupStart && !engine.IsGMail && group == null) {
					group = item.ToGroupAddress ();
					list.Add (group);
				} else if (item.IsGroupEnd) {
					group = null;
				} else if (group != null) {
					group.Members.Add (item.ToMailboxAddress ());
				} else {
					list.Add (item.ToMailboxAddress ());
				}
			} while (true);
		}
开发者ID:BehnamEmamian,项目名称:MailKit,代码行数:35,代码来源:ImapUtils.cs

示例13: Expand

		/// <summary>
		/// Expand a mailing address alias.
		/// </summary>
		/// <remarks>
		/// Expands a mailing address alias.
		/// </remarks>
		/// <returns>The expanded list of mailbox addresses.</returns>
		/// <param name="alias">The mailing address alias.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="alias"/> is <c>null</c>.
		/// </exception>
		/// <exception cref="System.ArgumentException">
		/// <paramref name="alias"/> is an empty string.
		/// </exception>
		/// <exception cref="System.ObjectDisposedException">
		/// The <see cref="SmtpClient"/> has been disposed.
		/// </exception>
		/// <exception cref="ServiceNotConnectedException">
		/// The <see cref="SmtpClient"/> is not connected.
		/// </exception>
		/// <exception cref="ServiceNotAuthenticatedException">
		/// Authentication is required before verifying the existence of an address.
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation has been canceled.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		/// <exception cref="SmtpCommandException">
		/// The SMTP command failed.
		/// </exception>
		/// <exception cref="SmtpProtocolException">
		/// An SMTP protocol exception occurred.
		/// </exception>
		public InternetAddressList Expand (string alias, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (alias == null)
				throw new ArgumentNullException (nameof (alias));

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

			if (alias.IndexOfAny (new [] { '\r', '\n' }) != -1)
				throw new ArgumentException ("The alias cannot contain newline characters.", nameof (alias));

			CheckDisposed ();

			if (!IsConnected)
				throw new ServiceNotConnectedException ("The SmtpClient is not connected.");

			var response = SendCommand (string.Format ("EXPN {0}", alias), cancellationToken);

			if (response.StatusCode != SmtpStatusCode.Ok)
				throw new SmtpCommandException (SmtpErrorCode.UnexpectedStatusCode, response.StatusCode, response.Response);

			var lines = response.Response.Split ('\n');
			var list = new InternetAddressList ();

			for (int i = 0; i < lines.Length; i++) {
				InternetAddress address;

				if (InternetAddress.TryParse (lines[i], out address))
					list.Add (address);
			}

			return list;
		}
开发者ID:jstedfast,项目名称:MailKit,代码行数:69,代码来源:SmtpClient.cs

示例14: TestSimpleMailboxes

        public void TestSimpleMailboxes()
        {
            var expected = new InternetAddressList ();
            var mailbox = new MailboxAddress ("", "");
            InternetAddressList result;
            string text;

            expected.Add (mailbox);

            mailbox.Name = "Jeffrey Stedfast";
            mailbox.Address = "[email protected]";
            text = "Jeffrey Stedfast <[email protected]>";
            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);

            mailbox.Name = "this is a folded name";
            mailbox.Address = "[email protected]";
            text = "this is\n\ta folded name <[email protected]>";
            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);

            mailbox.Name = "Jeffrey fejj Stedfast";
            mailbox.Address = "[email protected]";
            text = "Jeffrey \"fejj\" Stedfast <[email protected]>";
            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);

            mailbox.Name = "Jeffrey \"fejj\" Stedfast";
            mailbox.Address = "[email protected]";
            text = "\"Jeffrey \\\"fejj\\\" Stedfast\" <[email protected]>";
            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);

            mailbox.Name = "Stedfast, Jeffrey";
            mailbox.Address = "[email protected]";
            text = "\"Stedfast, Jeffrey\" <[email protected]>";
            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);

            mailbox.Name = "Jeffrey Stedfast";
            mailbox.Address = "[email protected]";
            text = "[email protected] (Jeffrey Stedfast)";
            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);

            mailbox.Name = "Jeffrey Stedfast";
            mailbox.Address = "[email protected]";
            text = "Jeffrey Stedfast <fejj(recursive (comment) block)@helixcode.(and a comment here)com>";
            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);
        }
开发者ID:hultqvist,项目名称:MimeKit,代码行数:72,代码来源:InternetAddressListTests.cs

示例15: TestObsoleteMailboxRoutingSyntaxWithEmptyDomains

        public void TestObsoleteMailboxRoutingSyntaxWithEmptyDomains()
        {
            var expected = new InternetAddressList ();
            InternetAddressList result;
            string text;

            text = "Routed Address <@route1,,@route2,,,@route3:[email protected]>";

            expected.Add (new MailboxAddress ("Routed Address", new [] { "route1", "route2", "route3" }, "[email protected]"));

            Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
            AssertInternetAddressListsEqual (text, expected, result);

            result = InternetAddressList.Parse (text);
            AssertInternetAddressListsEqual (text, expected, result);
        }
开发者ID:hultqvist,项目名称:MimeKit,代码行数:16,代码来源:InternetAddressListTests.cs


注:本文中的InternetAddressList.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。