コード例 #1
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        /// <remarks>
        /// If the main class was marked as sealed, we could just make this a private void Dispose(bool).  Alternatively, we could (in this case) put
        /// all of our logic directly in Dispose().
        /// </remarks>
        public virtual void Dispose(bool disposing)
        {
            // Use our disposed flag to allow us to call this method multiple times safely.
            // This is a requirement when implementing IDisposable.
            if (!this.disposed)
            {
                if (disposing)
                {
                    // If we have any managed, IDisposable resources, Dispose of them here.
                    // In this case, we don't, so this was unneeded.
                    // Later, we will subclass this class, and use this section.

                    if (Pop3 != null)
                    {
                        Pop3.Disconnect(true);
                        Pop3.Dispose();
                        Pop3 = null;
                    }

                    if (Imap != null)
                    {
                        Imap.Disconnect(true);
                        Imap.Dispose();
                        Imap = null;
                    }
                }

                // Always dispose of undisposed unmanaged resources in Dispose(bool).
            }
            // Mark us as disposed, to prevent multiple calls to dispose from having an effect,
            // and to allow us to handle ObjectDisposedException.
            this.disposed = true;
        }
コード例 #2
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         _pop3.Dispose();
     }
 }
コード例 #3
0
 public void Dispose()
 {
     if (_disposed)
     {
         return;
     }
     _disposed = true;
     GC.SuppressFinalize(this);
     _client.Dispose();
     _client = null;
 }
コード例 #4
0
 public void ClosePop3()
 {
     try
     {
         if (Pop3 != null)
         {
             Pop3.Disconnect(true);
             Pop3.Dispose();
             Pop3 = null;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
 }
コード例 #5
0
        private void Connect(Func <Pop3, bool> onConnectFunction)
        {
            Debug.WriteLine("GetAll");

            Pop3.LicenseKey = "MN200-539BA4259BD99BD69B32E3AB96B2-6863";
            var pop = new Pop3();


            if (_ssl)
            {
                pop.SslProtocol = SecurityProtocol.Auto;
                pop.SslMode     = SslStartupMode.OnConnect;
            }

            try
            {
                if (pop.Connect(_server, _port, true))
                {
                    Debug.WriteLine("Connected");

                    if (pop.Login(_login,
                                  _password,
                                  AuthenticationMethods.Auto,
                                  AuthenticationOptions.PreferSimpleMethods,
                                  null))
                    {
                        Debug.WriteLine("Logged in " + pop.InboxMessageCount);
                        onConnectFunction(pop);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("GetAll");
                Debug.WriteLine(ex);
                _lastError = ex.Message;
            }
            finally
            {
                if (pop.IsConnected)
                {
                    pop.Disconnect();
                }
                pop.Dispose();
            }
        }
コード例 #6
0
 /// <summary>
 /// Releases all resources acquired by this object. Closes connection, without issuing any quit commands.
 /// </summary>
 public void Dispose()
 {
     _pop3.Dispose();
 }