NoOp() публичный Метод

Ping the IMAP server to keep the connection alive.

The NOOP command is typically used to keep the connection with the IMAP server alive. When a client goes too long (typically 30 minutes) without sending any commands to the IMAP server, the IMAP server will close the connection with the client, forcing the client to reconnect before it can send any more commands.

The NOOP command also provides a great way for a client to check for new messages.

When the IMAP server receives a NOOP command, it will reply to the client with a list of pending updates such as EXISTS and RECENT counts on the currently selected folder. To receive these notifications, subscribe to the MailFolder.CountChanged and MailFolder.RecentChanged events, respectively.

For more information about the NOOP command, see rfc3501.

/// The has been disposed. /// /// The is not connected. /// /// The is not authenticated. /// /// The operation was canceled via the cancellation token. /// /// An I/O error occurred. /// /// The server replied to the NOOP command with a NO or BAD response. /// /// The server responded with an unexpected token. ///
public NoOp ( CancellationToken cancellationToken = default(CancellationToken) ) : void
cancellationToken System.Threading.CancellationToken The cancellation token.
Результат void
Пример #1
0
        public void TestMessageCount()
        {
            var commands = new List<ImapReplayCommand> ();
            commands.Add (new ImapReplayCommand ("", "gmail.greeting.txt"));
            commands.Add (new ImapReplayCommand ("A00000000 CAPABILITY\r\n", "gmail.capability.txt"));
            commands.Add (new ImapReplayCommand ("A00000001 AUTHENTICATE PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n", "gmail.authenticate.txt"));
            commands.Add (new ImapReplayCommand ("A00000002 NAMESPACE\r\n", "gmail.namespace.txt"));
            commands.Add (new ImapReplayCommand ("A00000003 LIST \"\" \"INBOX\"\r\n", "gmail.list-inbox.txt"));
            commands.Add (new ImapReplayCommand ("A00000004 XLIST \"\" \"*\"\r\n", "gmail.xlist.txt"));
            //INBOX has 1 message present in this test
            commands.Add (new ImapReplayCommand ("A00000005 EXAMINE INBOX (CONDSTORE)\r\n", "gmail.count.examine.txt"));
            //next command simulates one expunge + one new message
            commands.Add (new ImapReplayCommand ("A00000006 NOOP\r\n", "gmail.count.noop.txt"));

            using (var client = new ImapClient ()) {
                try {
                    client.ReplayConnect ("localhost", new ImapReplayStream (commands, false), CancellationToken.None);
                } catch (Exception ex) {
                    Assert.Fail ("Did not expect an exception in Connect: {0}", ex);
                }

                Assert.IsTrue (client.IsConnected, "Client failed to connect.");

                try {
                    var credentials = new NetworkCredential ("username", "password");

                    // Note: Do not try XOAUTH2
                    client.AuthenticationMechanisms.Remove ("XOAUTH2");

                    client.Authenticate (credentials, CancellationToken.None);
                } catch (Exception ex) {
                    Assert.Fail ("Did not expect an exception in Authenticate: {0}", ex);
                }

                var count = -1;

                client.Inbox.Open(FolderAccess.ReadOnly);

                client.Inbox.CountChanged += delegate {
                    count = client.Inbox.Count;
                };

                client.NoOp();

                Assert.AreEqual(1, count, "Count is not correct");
            }
        }