Deleting Mail doesn't work

Mar 11, 2013 at 11:41 AM
Iv'e wrote a routine to move a certain mail, but since there is no Move function (yet)
So I'm forced to first copy the mail and then delete the sourcemail, but the deleteion part doesn't work, the mail doesn't get deleted??? No errors are generated as well.

Any idea how to fix this or another option to move mails?
        public void MarkMail(string sMessageID, string sSourceFolder, string sDestinationFolder)
        {
            ImapClient cl = new ImapClient(sMailServer, iMailPort, sMailAccountname, Program.WFACryptor.Decrypt(sMailEncryptedPassword));
            cl.Ssl = bMailSSL;

            if (cl.Authenticate() == true)
            {
                ImapFolder rFolder = cl.SelectFolder(sSourceFolder);
                MailMessage mg; string sOut = "";
                for (int mailindex = 1; mailindex <= cl.ExecuteExamine(sSourceFolder).Exists; mailindex++)
                {
                    mg = cl.GetMessage(mailindex);
                    if (mg.MessageID.Contains(sMessageID))
                    {
                        cl.ExecuteCopy(mailindex, mailindex, sDestinationFolder);
                        cl.DeleteMail(sSourceFolder, mailindex);
                    }
                }
            }
        }
Regards
Nicci
Mar 14, 2013 at 12:03 PM
Is there no one with the same issue?

I also notice I can't store any flags as well :(
Coordinator
Mar 14, 2013 at 12:27 PM
Edited Mar 14, 2013 at 12:27 PM
The connection is closed when DeleteMail method executed.
This method is a facade method to provide easy deletion to developer.
Inside this method, ImapClient object send a number of commands Store,Expunge and Logout.
Here is a detail of Imap protocol.
http://www.codeproject.com/Articles/411018/Understanding-the-insides-of-the-IMAP-mail-protoco

Change this line
cl.DeleteMail(sSourceFolder, mailindex);
To below
var rs = cl.ExecuteStore(mailIndex, StoreItem.FlagsAdd, @"\Deleted");

And call these method after processing all mail.
for (...)
{
}
cl.ExecuteExpunge();
cl.ExecuteLogout();

It may be solve your problem.
Please try.

regards.
Mar 14, 2013 at 1:43 PM
Hi Higty

thx for the reply,

But sadly enough still no improvement, I already played around with the expunge (I digged into the DeleteMail method source code))
        public void MarkMail(string sMessageID, string sSourceFolder, string sDestinationFolder)
        {
            bool bDel = new bool(); int x = 0;
            ImapClient cl = new ImapClient(sMailServer, iMailPort, sMailAccountname, Program.WFACryptor.Decrypt(sMailEncryptedPassword));
            cl.Ssl = bMailSSL;

            if (cl.Authenticate() == true)
            {
                ImapFolder rFolder = cl.SelectFolder(sSourceFolder);
                MailMessage mg; string sOut = "";
                for (int mailindex = 1; mailindex <= cl.ExecuteExamine(sSourceFolder).Exists; mailindex++)
                {
                    mg = cl.GetMessage(mailindex);
                    if (mg.MessageID.Contains(sMessageID))
                    {
                        cl.ExecuteCopy(mailindex, mailindex, sDestinationFolder);
                        var rs = cl.ExecuteStore(mailindex, StoreItem.FlagsAdd, @"\Deleted");
                        if (rs.Status != ImapCommandResultStatus.Ok)
                            System.Windows.MessageBox.Show(rs.Status.ToString() + ": " + rs.Text);
                    }
                }
                cl.ExecuteExpunge();
                cl.ExecuteLogout();
            }
        }
I caught the ExecuteStore status message "tag1 NO Command received in Invalid state.\r\n"
Maybe that can point to a sollution?

regards
Coordinator
Mar 21, 2013 at 12:43 AM
In my environment, GMail server return response on line of
var rs = cl.ExecuteStore();
Returned response is
"tag1 NO STORE attempt on READ-ONLY folder (Failure)"

Is there any other information?