Exemplo n.º 1
0
 /// <summary>
 /// Send Logout command to IMAP server.
 /// </summary>
 /// <returns></returns>
 public ImapCommandResult ExecuteLogout()
 {
     this.ValidateState(ImapConnectionState.Authenticated);
     ImapCommandResult rs = this.Execute(this.Tag + " Logout");
     if (rs.Status == ImapCommandResultStatus.Ok)
     {
         this._State = ImapConnectionState.Connected;
     }
     return rs;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Send IDLE command to IMAP server.
 /// You can receive message from server by register event handler to MessageReceived event of ImapIdleCommand object
 /// </summary>
 /// <returns></returns>
 public void ExecuteIdle(ImapIdleCommand command)
 {
     this.ValidateState(ImapConnectionState.Authenticated);
     this.Send(this.Tag + " IDLE");
     var bb = command.Buffer;
     command.IAsyncResult = this.Stream.BeginRead(bb, 0, bb.Length, this.ExecuteIdleCallback, command);
     this._State = ImapConnectionState.Idle;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public ImapCommandResult ExecuteLogin()
        {
            if (this.EnsureOpen() == ImapConnectionState.Disconnected) { throw new MailClientException("Connection is not available."); }

            String commandText = String.Format(this.Tag + " LOGIN {0} \"{1}\"", this.UserName, this.Password);
            ImapCommandResult rs = this.Execute(commandText);
            if (rs.Status == ImapCommandResultStatus.Ok)
            {
                this._State = ImapConnectionState.Authenticated;
            }
            else
            {
                this._State = ImapConnectionState.Connected;
            }
            return rs;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Send done command to IMAP server.
 /// </summary>
 /// <returns></returns>
 public ImapCommandResult ExecuteDone(ImapIdleCommand command)
 {
     this.ValidateState(ImapConnectionState.Idle);
     if (command.IAsyncResult != null)
     {
         var x = this.Stream.EndRead(command.IAsyncResult);
     }
     var rs = this.Execute("DONE");
     this._State = ImapConnectionState.Authenticated;
     return rs;
 }
Exemplo n.º 5
0
 /// <summary>
 /// disconnect connection to IMAP server.
 /// </summary>
 public override void Close()
 {
     base.Close();
     this._State = ImapConnectionState.Disconnected;
 }
Exemplo n.º 6
0
 private void ValidateState(ImapConnectionState state, Boolean folderSelected)
 {
     if (this._State != state)
     {
         switch (state)
         {
             case ImapConnectionState.Disconnected: throw new MailClientException("You can execute this command only when State is Disconnected");
             case ImapConnectionState.Connected: throw new MailClientException("You can execute this command only when State is Connected");
             case ImapConnectionState.Authenticated: throw new MailClientException("You can execute this command only when State is Authenticated");
             default: throw new MailClientException();
         }
     }
     if (folderSelected == true && this.CurrentFolder == null)
     {
         throw new MailClientException("You must select folder before executing this command."
           + "You can select folder by calling SelectFolder,ExecuteSelect,ExecuteExamine method of this object.");
     }
 }
Exemplo n.º 7
0
 private void ValidateState(ImapConnectionState state)
 {
     this.ValidateState(state, false);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Open connection to a server.
 /// </summary>
 public ImapConnectionState Open()
 {
     if (this.Connect() == true)
     {
         this._State = ImapConnectionState.Connected;
     }
     else
     {
         this._State = ImapConnectionState.Disconnected;
     }
     return this._State;
 }