Aspose.Email upgrade from Aspose.Network NO EXPUNGE error

We're upgrading our application from using Aspose.Network to Aspose.Email

The application uses IMAP to interact with Exchange. After the code and reference changes need to utilize Aspose.Email, our first production deployment started to randomly error out when trying to delete a message from the Inbox.

The error message reads as follows:

003 NO EXPUNGE

The number highlighted in yellow differs on every failures.

Here the code used to delete from the Inbox:

using(ImapClient imapClient=GetClient()) {
imapClient.CopyMessage(pendingMessage.MessageId, config.DestinationFolder); // copy to another folder
imapClient.AddMessageFlags(pendingMessage.MessageId, ImapMessageFlags.Deleted); // Add the deleted flag
imapClient.ExpungeMessages(); // delete all the delete flagged messages
imapClient.Disconnect();
}

I've tested in our Dev environment a scenario where the application would accidently delete the same message multiple times with the old version (using Aspose.Network) and the new version (Aspose.Email) without getting a Exception thrown.

Can you please guide me to a potential reason in the change of behavior.

Thanks,

Jm

Hi Jm,


Thanks for sharing your concern.

I have tried to reproduce this issue at my end using ImapClient with my exchange server, but could not get success to face any such error. I populated the messages pool with a number of messages and tried it a number of times, but could not succeed. Does this happen for every single message that you mark as selected for deletion? Please share any other details about this issue that can help us reproduce it at our end for assisting you further.

Kashif,

Thanks for your prompt response.

I have not been able to reproduce the error with a test harness against my development environment.

However, we are able to reproduce the symptoms using the application itself (not a test harness) against the development environment.

The failure appears random and sporadic in nature.

The fact that I can duplicate the behavior (deleting the same item multiple times) and not cause an error to occur is troublesome.

Is it possible that with the separation from Aspose.Network and the rollout of the Aspose.Email assembly, some exception that used to be caught and "swallowed" by the Aspose.Network assembly is now bubbling up and surfaces all the way to the calling clients?

Just trying to get some understanding of the error message itself and what causes it.

Thanks,

Jm

Hi Jm,


Thank you for the feedback.

Could you please try the DeleteMessage(UniqueId) method instead of setting the Delete flag at your end and let us know if the behavior is same? Also, please share your environment details with us e.g. Exchange server and the OS version. As this issue is not reproducible at our end, we may need a test account on your server to further investigate this issue. Please let us know if this is possible at your end to arrange such a test account for our testing? We will look into it and assist you further.

Hi,

thanks for your suggestion.

My code looks like this now:

public void RemoveMessageFromInbox(IPendingMessage pendingMessage) {
using(ImapClient imapClient=GetClient()) {
imapClient.CopyMessage(pendingMessage.MessageId, config.DestinationFolder);
imapClient.DeleteMessage(pendingMessage.MessageId);
imapClient.ExpungeMessages(); // delete all the delete flagged messages
imapClient.Disconnect();
}
}

We're on Exchange 2010.

Test account and access to our environment would be difficult.

Do you see anything in this code that would cause such error?

Thanks,

Jm


Hi Jm,

I used your code and regret to inform that I I could not reproduce the error. It works fine and messages are copied to other folder before deleting them permanently. It seems that without the test account credentials, it is quite difficult to identify the problem. Please arrange some test account which can be used to re-produce the issue here. Also, could you please give a try to the following code and let us know your feedback?

public static bool CheckCertificate(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
static public void RemoveMessageFromInbox()
{
Aspose.Email.Imap.ImapClient imapClient = new Aspose.Email.Imap.ImapClient(“[exchange.aspose.com](http://exchange.aspose.com/)”, 993, "user@exchangedomain.com", “password”, CheckCertificate);
imapClient.SecurityMode = ImapSslSecurityMode.Implicit;
imapClient.EnableSsl = true;
imapClient.Connect();
imapClient.SelectFolder(“Inbox”);
ImapMessageInfoCollection messages = imapClient.ListMessages(5);
Console.WriteLine(“Imap: " + messages.Count + " message(s) found.”);

foreach (ImapMessageInfo info in messages)
{
MailMessage mail = imapClient.FetchMessage(info.UniqueId);
Console.WriteLine("Sequence No = " + info.SequenceNumber);
imapClient.CopyMessage(info.SequenceNumber, “TestFolder”);
Console.WriteLine("Deleted Subject = " + mail.Subject);
imapClient.AddMessageFlags(info.SequenceNumber, ImapMessageFlags.Deleted);
}
imapClient.ExpungeMessages();
imapClient.Disconnect();
}