You can execute this command only when State is Authenticated

Oct 2, 2013 at 3:17 PM
I'm reading an IMAP folder.
My code is quite this:

Dim inbox As Imap.ImapFolder = _imapClient.SelectFolder("INBOX")
        For jj = 1 To inbox.MailCount
            Dim message = _imapClient.GetMessage(jj)
' do some stuff using the message

_imapClient.DeleteMail(jj)
        Next
The mailbox has currently 3 messsages. After the DeleteMail, the next loop throw the exception "You can execute this command only when State is Authenticated"
Why?

thanks
Coordinator
Oct 3, 2013 at 4:45 PM
See this article.
You must reauthenticate required.
http://www.codeproject.com/Articles/411018/Understanding-the-insides-of-the-IMAP-mail-protoco

(This article is old. I changed method name from DeleteEMail to DeleteMail early this year or more before)
Oct 4, 2013 at 10:08 AM
Thank you
but why do you execute an "ExecuteLogout" in DeleteMail method?

As user of the library it seems more normal:
  • create a cliente
  • logon
  • read
  • delete
  • read
  • delete
  • move, copy, insert, etc.
  • logout
Why delete has a forced logout inside? Is this required by IMAP to complete deletion?
Coordinator
Oct 4, 2013 at 11:48 AM
You are completely right.
DeleteMail method should be

public Boolean DeleteMail(params Int64[] mailIndex)
{
if (this.EnsureOpen() == ImapConnectionState.Disconnected) { return false; }
if (this.Authenticate() == false) { return false; }

for (int i = 0; i < mailIndex.Length; i++)
{
    var rs = this.ExecuteStore(mailIndex[i], StoreItem.FlagsAdd, @"\Deleted");
    if (rs.Status != ImapCommandResultStatus.Ok) { return false; }
}
this.ExecuteExpunge();
return true;
}

I'll modify it in next version.
Thank you for your catching up!