• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# MimeKit.MailboxAddress类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MimeKit.MailboxAddress的典型用法代码示例。如果您正苦于以下问题:C# MailboxAddress类的具体用法?C# MailboxAddress怎么用?C# MailboxAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MailboxAddress类属于MimeKit命名空间,在下文中一共展示了MailboxAddress类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: TestPgpMimeSigning

		public void TestPgpMimeSigning ()
		{
			var self = new MailboxAddress ("MimeKit UnitTests", "[email protected]");

			var cleartext = new TextPart ("plain");
			cleartext.Text = "This is some cleartext that we'll end up signing...";

			using (var ctx = new DummyOpenPgpContext ()) {
				var multipart = MultipartSigned.Create (ctx, self, DigestAlgorithm.Sha1, cleartext);
				Assert.AreEqual (2, multipart.Count, "The multipart/signed has an unexpected number of children.");

				var protocol = multipart.ContentType.Parameters["protocol"];
				Assert.AreEqual (ctx.SignatureProtocol, protocol, "The multipart/signed protocol does not match.");

				Assert.IsInstanceOfType (typeof (TextPart), multipart[0], "The first child is not a text part.");
				Assert.IsInstanceOfType (typeof (ApplicationPgpSignature), multipart[1], "The second child is not a detached signature.");

				var signatures = multipart.Verify (ctx);
				Assert.AreEqual (1, signatures.Count, "Verify returned an unexpected number of signatures.");
				foreach (var signature in signatures) {
					try {
						bool valid = signature.Verify ();

						Assert.IsTrue (valid, "Bad signature from {0}", signature.SignerCertificate.Email);
					} catch (DigitalSignatureVerifyException ex) {
						Assert.Fail ("Failed to verify signature: {0}", ex);
					}
				}
			}
		}
开发者ID:gphummer,项目名称:MimeKit,代码行数:30,代码来源:PgpMimeTests.cs


示例3: 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]lixcode.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);

			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


示例4: SignEntity

 /*
  * tries to sign a MimeEntity
  */
 public static MimeEntity SignEntity(MimeEntity entity, MailboxAddress signer)
 {
     using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
     {
         return MultipartSigned.Create(ctx, signer, DigestAlgorithm.Sha1, entity);
     }
 }
开发者ID:polterguy,项目名称:magix,代码行数:10,代码来源:CryptographyHelper.cs


示例5: 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


示例6: CanSign

 /*
  * returns true if email address can sign email
  */
 public static bool CanSign(string email)
 {
     try
     {
         MailboxAddress signer = new MailboxAddress("", email);
         TextPart entity = new TextPart("text");
         using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
         {
             MultipartSigned.Create(ctx, signer, DigestAlgorithm.Sha1, entity);
             return true;
         }
     }
     catch
     {
         return false;
     }
 }
开发者ID:Letractively,项目名称:magix-illuminate-2,代码行数:20,代码来源:CryptographyHelper.cs


示例7: 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


示例8: TestPgpMimeEncryption

        public void TestPgpMimeEncryption()
        {
            var self = new MailboxAddress ("MimeKit UnitTests", "[email protected]");
            var recipients = new List<MailboxAddress> ();

            // encrypt to ourselves...
            recipients.Add (self);

            var cleartext = new TextPart ("plain");
            cleartext.Text = "This is some cleartext that we'll end up encrypting...";

            using (var ctx = new DummyOpenPgpContext ()) {
                var encrypted = MultipartEncrypted.Create (ctx, recipients, cleartext);

                //using (var file = File.Create ("pgp-encrypted.asc"))
                //	encrypted.WriteTo (file);

                var decrypted = encrypted.Decrypt (ctx);

                Assert.IsInstanceOfType (typeof (TextPart), decrypted, "Decrypted part is not the expected type.");
                Assert.AreEqual (cleartext.Text, ((TextPart) decrypted).Text, "Decrypted content is not the same as the original.");
            }
        }
开发者ID:vdaron,项目名称:MimeKit,代码行数:23,代码来源:PgpMimeTests.cs


示例9: TestMimeMessageSign

		public void TestMimeMessageSign ()
		{
			var body = new TextPart ("plain") { Text = "This is some cleartext that we'll end up signing..." };
			var self = new MailboxAddress ("MimeKit UnitTests", "[email protected]com");
			var message = new MimeMessage { Subject = "Test of signing with OpenPGP" };

			message.From.Add (self);
			message.Body = body;

			using (var ctx = new DummyOpenPgpContext ()) {
				message.Sign (ctx);

				Assert.IsInstanceOf<MultipartSigned> (message.Body);

				var multipart = (MultipartSigned) message.Body;

				Assert.AreEqual (2, multipart.Count, "The multipart/signed has an unexpected number of children.");

				var protocol = multipart.ContentType.Parameters["protocol"];
				Assert.AreEqual (ctx.SignatureProtocol, protocol, "The multipart/signed protocol does not match.");

				Assert.IsInstanceOf<TextPart> (multipart[0], "The first child is not a text part.");
				Assert.IsInstanceOf<ApplicationPgpSignature> (multipart[1], "The second child is not a detached signature.");

				var signatures = multipart.Verify (ctx);
				Assert.AreEqual (1, signatures.Count, "Verify returned an unexpected number of signatures.");
				foreach (var signature in signatures) {
					try {
						bool valid = signature.Verify ();

						Assert.IsTrue (valid, "Bad signature from {0}", signature.SignerCertificate.Email);
					} catch (DigitalSignatureVerifyException ex) {
						Assert.Fail ("Failed to verify signature: {0}", ex);
					}
				}
			}
		}
开发者ID:surekqomi,项目名称:MimeKit,代码行数:37,代码来源:PgpMimeTests.cs


示例10: GetCmsRecipient

		/// <summary>
		/// Gets the <see cref="CmsRecipient"/> for the specified mailbox.
		/// </summary>
		/// <returns>A <see cref="CmsRecipient"/>.</returns>
		/// <param name="mailbox">The mailbox.</param>
		/// <exception cref="CertificateNotFoundException">
		/// A certificate for the specified <paramref name="mailbox"/> could not be found.
		/// </exception>
		protected override CmsRecipient GetCmsRecipient (MailboxAddress mailbox)
		{
			var now = DateTime.Now;

			foreach (var certificate in certificates) {
				if (certificate.NotBefore > now || certificate.NotAfter < now)
					continue;

				var keyUsage = certificate.GetKeyUsageFlags ();
				if (keyUsage != 0 && (keyUsage & X509KeyUsageFlags.KeyEncipherment) == 0)
					continue;

				if (certificate.GetSubjectEmailAddress () == mailbox.Address) {
					var recipient = new CmsRecipient (certificate);
					EncryptionAlgorithm[] algorithms;

					if (capabilities.TryGetValue (certificate, out algorithms))
						recipient.EncryptionAlgorithms = algorithms;

					return recipient;
				}
			}

			throw new CertificateNotFoundException (mailbox, "A valid certificate could not be found.");
		}
开发者ID:ruffin--,项目名称:MimeKit,代码行数:33,代码来源:DummySecureMimeContext.cs


示例11: SignAndEncryptEntity

 /*
  * tries to sign and encrypt a MimeEntity
  */
 public static MimeEntity SignAndEncryptEntity(MimeEntity entity, MailboxAddress signer, IEnumerable<MailboxAddress> list)
 {
     using (WindowsSecureMimeContext ctx = new WindowsSecureMimeContext(sys.StoreLocation.CurrentUser))
     {
         return ApplicationPkcs7Mime.SignAndEncrypt(ctx, signer, DigestAlgorithm.Sha1, list, entity);
     }
 }
开发者ID:Letractively,项目名称:magix-illuminate-2,代码行数:10,代码来源:CryptographyHelper.cs


示例12: FlushCommandQueue

		void FlushCommandQueue (MailboxAddress sender, IList<MailboxAddress> recipients, CancellationToken cancellationToken)
		{
			if (queued.Count == 0)
				return;

			try {
				var responses = new List<SmtpResponse> ();
				Exception rex = null;
				int rcpt = 0;

				// Note: queued commands are buffered by the stream
				Stream.Flush (cancellationToken);

				// Note: we need to read all responses from the server before we can process
				// them in case any of them have any errors so that we can RSET the state.
				try {
					for (int i = 0; i < queued.Count; i++)
						responses.Add (Stream.ReadResponse (cancellationToken));
				} catch (Exception ex) {
					// Note: save this exception for later (it may be related to
					// an error response for a MAIL FROM or RCPT TO command).
					rex = ex;
				}

				for (int i = 0; i < responses.Count; i++) {
					switch (queued[i]) {
					case SmtpCommand.MailFrom:
						ProcessMailFromResponse (responses[i], sender);
						break;
					case SmtpCommand.RcptTo:
						ProcessRcptToResponse (responses[i], recipients[rcpt++]);
						break;
					}
				}

				if (rex != null)
					throw new SmtpProtocolException ("Error reading a response from the SMTP server.", rex);
			} finally {
				queued.Clear ();
			}
		}
开发者ID:erdonet,项目名称:MailKit,代码行数:41,代码来源:SmtpClient.cs


示例13: Send

		/// <summary>
		/// Send the specified message using the supplied sender and recipients.
		/// </summary>
		/// <remarks>
		/// Sends the message by uploading it to an SMTP server using the supplied sender and recipients.
		/// </remarks>
		/// <param name="options">The formatting options.</param>
		/// <param name="message">The message.</param>
		/// <param name="sender">The mailbox address to use for sending the message.</param>
		/// <param name="recipients">The mailbox addresses that should receive the message.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <param name="progress">The progress reporting mechanism.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="options"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="message"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="sender"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="recipients"/> is <c>null</c>.</para>
		/// </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 sending a message.
		/// </exception>
		/// <exception cref="System.InvalidOperationException">
		/// <para>A sender has not been specified.</para>
		/// <para>-or-</para>
		/// <para>No recipients have been specified.</para>
		/// </exception>
		/// <exception cref="System.NotSupportedException">
		/// Internationalized formatting was requested but is not supported by the server.
		/// </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 override void Send (FormatOptions options, MimeMessage message, MailboxAddress sender, IEnumerable<MailboxAddress> recipients, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
		{
			if (options == null)
				throw new ArgumentNullException ("options");

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

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

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

			var rcpts = recipients.ToList ();

			if (rcpts.Count == 0)
				throw new InvalidOperationException ("No recipients have been specified.");

			Send (options, message, sender, rcpts, cancellationToken, progress);
		}
开发者ID:erdonet,项目名称:MailKit,代码行数:71,代码来源:SmtpClient.cs


示例14: RcptTo

		void RcptTo (MimeMessage message, MailboxAddress mailbox, CancellationToken cancellationToken)
		{
			var command = string.Format ("RCPT TO:<{0}>", mailbox.Address);

			if ((capabilities & SmtpCapabilities.Dsn) != 0) {
				var notify = GetDeliveryStatusNotifications (message, mailbox);

				if (notify.HasValue)
					command += " NOTIFY=" + GetNotifyString (notify.Value);
			}

			if ((capabilities & SmtpCapabilities.Pipelining) != 0) {
				QueueCommand (SmtpCommand.RcptTo, command, cancellationToken);
				return;
			}

			ProcessRcptToResponse (SendCommand (command, cancellationToken), mailbox);
		}
开发者ID:erdonet,项目名称:MailKit,代码行数:18,代码来源:SmtpClient.cs


示例15: GetCmsSigner

		/// <summary>
		/// Gets the <see cref="CmsSigner"/> for the specified mailbox.
		/// </summary>
		/// <returns>A <see cref="CmsSigner"/>.</returns>
		/// <param name="mailbox">The mailbox.</param>
		/// <param name="digestAlgo">The preferred digest algorithm.</param>
		/// <exception cref="CertificateNotFoundException">
		/// A certificate for the specified <paramref name="mailbox"/> could not be found.
		/// </exception>
		protected override CmsSigner GetCmsSigner (MailboxAddress mailbox, DigestAlgorithm digestAlgo)
		{
			var now = DateTime.Now;

			foreach (var certificate in certificates) {
				AsymmetricKeyParameter key;

				if (certificate.NotBefore > now || certificate.NotAfter < now)
					continue;

				var keyUsage = certificate.GetKeyUsageFlags ();
				if (keyUsage != 0 && (keyUsage & SecureMimeContext.DigitalSignatureKeyUsageFlags) == 0)
					continue;

				if (!keys.TryGetValue (certificate, out key))
					continue;

				if (certificate.GetSubjectEmailAddress () == mailbox.Address) {
					var signer = new CmsSigner (certificate, key);
					signer.DigestAlgorithm = digestAlgo;
					return signer;
				}
			}

			throw new CertificateNotFoundException (mailbox, "A valid signing certificate could not be found.");
		}
开发者ID:ruffin--,项目名称:MimeKit,代码行数:35,代码来源:DummySecureMimeContext.cs


示例16: TryParseMailbox

        internal static bool TryParseMailbox(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);
            DomainList route = null;

            address = null;

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

                return false;
            }

            if (text[index] == (byte) '@') {
                if (!DomainList.TryParse (text, ref index, endIndex, throwOnError, out route)) {
                    if (throwOnError)
                        throw new ParseException (string.Format ("Invalid route in mailbox at offset {0}", startIndex), startIndex, index);

                    return false;
                }

                if (index + 1 >= endIndex || text[index] != (byte) ':') {
                    if (throwOnError)
                        throw new ParseException (string.Format ("Incomplete route in mailbox at offset {0}", startIndex), startIndex, index);

                    return false;
                }

                index++;
            }

            string addrspec;
            if (!TryParseAddrspec (text, ref index, endIndex, (byte) '>', throwOnError, out addrspec))
                return false;

            if (!ParseUtils.SkipCommentsAndWhiteSpace (text, ref index, endIndex, throwOnError))
                return false;

            if (index >= endIndex || text[index] != (byte) '>') {
                if (options.AddressParserComplianceMode == RfcComplianceMode.Strict) {
                    if (throwOnError)
                        throw new ParseException (string.Format ("Unexpected end of mailbox at offset {0}", startIndex), startIndex, index);

                    return false;
                }
            } else {
                index++;
            }

            if (route != null)
                address = new MailboxAddress (encoding, name, route, addrspec);
            else
                address = new MailboxAddress (encoding, name, addrspec);

            return true;
        }
开发者ID:richard2753,项目名称:MimeKit,代码行数:59,代码来源:InternetAddress.cs


示例17: ReloadHeader

		void ReloadHeader (HeaderId id)
		{
			if (id == HeaderId.Unknown)
				return;

			switch (id) {
			case HeaderId.ResentMessageId:
				resentMessageId = null;
				break;
			case HeaderId.ResentSender:
				resentSender = null;
				break;
			case HeaderId.ResentDate:
				resentDate = DateTimeOffset.MinValue;
				break;
			case HeaderId.References:
				references.Changed -= ReferencesChanged;
				references.Clear ();
				references.Changed += ReferencesChanged;
				break;
			case HeaderId.InReplyTo:
				inreplyto = null;
				break;
			case HeaderId.MessageId:
				messageId = null;
				break;
			case HeaderId.Sender:
				sender = null;
				break;
			case HeaderId.Importance:
				importance = MessageImportance.Normal;
				break;
			case HeaderId.Priority:
				priority = MessagePriority.Normal;
				break;
			case HeaderId.Date:
				date = DateTimeOffset.MinValue;
				break;
			}

			foreach (var header in Headers) {
				if (header.Id != id)
					continue;

				var rawValue = header.RawValue;
				InternetAddress address;
				int index = 0;

				switch (id) {
				case HeaderId.MimeVersion:
					if (MimeUtils.TryParse (rawValue, 0, rawValue.Length, out version))
						return;
					break;
				case HeaderId.References:
					references.Changed -= ReferencesChanged;
					foreach (var msgid in MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length))
						references.Add (msgid);
					references.Changed += ReferencesChanged;
					break;
				case HeaderId.InReplyTo:
					inreplyto = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault ();
					break;
				case HeaderId.ResentMessageId:
					resentMessageId = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault ();
					if (resentMessageId != null)
						return;
					break;
				case HeaderId.MessageId:
					messageId = MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length).FirstOrDefault ();
					if (messageId != null)
						return;
					break;
				case HeaderId.ResentSender:
					if (InternetAddress.TryParse (Headers.Options, rawValue, ref index, rawValue.Length, false, out address))
						resentSender = address as MailboxAddress;
					if (resentSender != null)
						return;
					break;
				case HeaderId.Sender:
					if (InternetAddress.TryParse (Headers.Options, rawValue, ref index, rawValue.Length, false, out address))
						sender = address as MailboxAddress;
					if (sender != null)
						return;
					break;
				case HeaderId.ResentDate:
					if (DateUtils.TryParse (rawValue, 0, rawValue.Length, out resentDate))
						return;
					break;
				case HeaderId.Importance:
					switch (header.Value.ToLowerInvariant ().Trim ()) {
					case "high": importance = MessageImportance.High; break;
					case "low": importance = MessageImportance.Low; break;
					default: importance = MessageImportance.Normal; break;
					}
					break;
				case HeaderId.Priority:
					switch (header.Value.ToLowerInvariant ().Trim ()) {
					case "non-urgent": priority = MessagePriority.NonUrgent; break;
					case "urgent": priority = MessagePriority.Urgent; break;
					default: priority = MessagePriority.Normal; break;
//.........这里部分代码省略.........
开发者ID:yukine,项目名称:MimeKit,代码行数:101,代码来源:MimeMessage.cs


示例18: FlushCommandQueue

        void FlushCommandQueue(MailboxAddress sender, IList<MailboxAddress> recipients, CancellationToken cancellationToken)
        {
            if (queued.Count == 0)
                return;

            try {
                var responses = new List<SmtpResponse> ();
                int rcpt = 0;
                int nread;

                queue.Position = 0;
                while ((nread = queue.Read (input, 0, input.Length)) > 0) {
                    cancellationToken.ThrowIfCancellationRequested ();
                    stream.Write (input, 0, nread);
                    logger.LogClient (input, 0, nread);
                }

                // Note: we need to read all responses from the server before we can process
                // them in case any of them have any errors so that we can RSET the state.
                for (int i = 0; i < queued.Count; i++)
                    responses.Add (ReadResponse (cancellationToken));

                for (int i = 0; i < queued.Count; i++) {
                    switch (queued [i]) {
                    case SmtpCommand.MailFrom:
                        ProcessMailFromResponse (responses[i], sender);
                        break;
                    case SmtpCommand.RcptTo:
                        ProcessRcptToResponse (responses[i], recipients[rcpt++]);
                        break;
                    }
                }
            } finally {
                queue.SetLength (0);
                queued.Clear ();
            }
        }
开发者ID:richard2753,项目名称:MailKit,代码行数:37,代码来源:SmtpClient.cs


示例19: TryParse

        internal static bool TryParse(ParserOptions options, byte[] text, ref int index, int endIndex, bool throwOnError, out InternetAddress address)
        {
            address = null;

            if (!ParseUtils.SkipCommentsAndWhiteSpace (text, ref index, endIndex, throwOnError))
                return false;

            if (index == endIndex) {
                if (throwOnError)
                    throw new ParseException ("No address found.", index, index);

                return false;
            }

            // keep track of the start & length of the phrase
            int startIndex = index;
            int length = 0;

            while (index < endIndex && ParseUtils.Skip8bitWord (text, ref index, endIndex, throwOnError)) {
                length = index - startIndex;

                do {
                    if (!ParseUtils.SkipCommentsAndWhiteSpace (text, ref index, endIndex, throwOnError))
                        return false;

                    // Note: some clients don't quote dots in the name
                    if (index >= endIndex || text[index] != (byte) '.')
                        break;

                    index++;
                } while (true);
            }

            if (!ParseUtils.SkipCommentsAndWhiteSpace (text, ref index, endIndex, throwOnError))
                return false;

            // specials    =  "(" / ")" / "<" / ">" / "@"  ; Must be in quoted-
            //             /  "," / ";" / ":" / "\" / <">  ;  string, to use
            //             /  "." / "[" / "]"              ;  within a word.

            if (index >= endIndex || text[index] == (byte) ',' || text[index] == ';') {
                // we've completely gobbled up an addr-spec w/o a domain
                byte sentinel = index < endIndex ? text[index] : (byte) ',';
                string name, addrspec;

                // rewind back to the beginning of the local-part
                index = startIndex;

                if (!TryParseAddrspec (text, ref index, endIndex, sentinel, throwOnError, out addrspec))
                    return false;

                ParseUtils.SkipWhiteSpace (text, ref index, endIndex);

                if (index < endIndex && text[index] == '(') {
                    int comment = index;

                    if (!ParseUtils.SkipComment (text, ref index, endIndex)) {
                        if (throwOnError)
                            throw new ParseException (string.Format ("Incomplete comment token at offset {0}", comment), comment, index);

                        return false;
                    }

                    comment++;

                    name = Rfc2047.DecodePhrase (options, text, comment, (index - 1) - comment).Trim ();
                } else {
                    name = string.Empty;
                }

                address = new MailboxAddress (name, addrspec);

                return true;
            }

            if (text[index] == (byte) ':') {
                // rfc2822 group address
                int codepage = -1;
                string name;

                if (length > 0) {
                    name = Rfc2047.DecodePhrase (options, text, startIndex, length, out codepage);
                } else {
                    name = string.Empty;
                }

                if (codepage == -1)
                    codepage = 65001;

                return TryParseGroup (options, text, startIndex, ref index, endIndex, MimeUtils.Unquote (name), codepage, throwOnError, out address);
            }

            if (text[index] == (byte) '<') {
                // rfc2822 angle-addr token
                int codepage = -1;
                string name;

                if (length > 0) {
                    name = Rfc2047.DecodePhrase (options, text, startIndex, length, out codepage);
                } else {
//.........这里部分代码省略.........
开发者ID:richard2753,项目名称:MimeKit,代码行数:101,代码来源:InternetAddress.cs


示例20: ProcessMailFromResponse

 static void ProcessMailFromResponse(SmtpResponse response, MailboxAddress mailbox)
 {
     switch (response.StatusCode) {
     case SmtpStatusCode.Ok:
         break;
     case SmtpStatusCode.MailboxNameNotAllowed:
     case SmtpStatusCode.MailboxUnavailable:
         throw new SmtpCommandException (SmtpErrorCode.SenderNotAccepted, response.StatusCode, mailbox, response.Response);
     case SmtpStatusCode.AuthenticationRequired:
         throw new UnauthorizedAccessException (response.Response);
     default:
         throw new SmtpCommandException (SmtpErrorCode.UnexpectedStatusCode, response.StatusCode, response.Response);
     }
 }
开发者ID:richard2753,项目名称:MailKit,代码行数:14,代码来源:SmtpClient.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MimeKit.MimeMessage类代码示例发布时间:2022-05-26
下一篇:
C# MimeKit.Header类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap