Pop3.BeginListMessages not working correctly

Hi,

could you add a BeginListMessages with a bool closetransaction as well? I am trying this code to regularly fetch and delete messages form a Gmail inbox:

private static Pop3Client pop3 = new Pop3Client("pop.gmail.com", 995, @"****", "****");
private static Timer scanTimer;

public static void Main() {
var license = LicenseProvider.GetAsposeLicense();
License emailLicense = new License();
emailLicense.SetLicense(license);
pop3.EnableSsl = true;
scanTimer = new Timer(Pop3Async, null, 0, -1);
Console.Read();
}

static async void Pop3Async(Object o) {
scanTimer.Change(Timeout.Infinite, Timeout.Infinite);
pop3.Quit();
var messages = await Task.Factory.FromAsync(pop3.BeginListMessages(), pop3.EndListMessages);
var count = messages.Count;
Console.WriteLine("new message count: {0}", count);

foreach (var id in messages.Select(m => m.UniqueId)) {
Console.WriteLine("fetching message with id {0}", id);
var message = pop3.FetchMessage(id);
Console.WriteLine("message with subject {0} fetched, deleting", message.Subject);
pop3.DeleteMessage(id);
}
pop3.Quit();
scanTimer.Change(1000, 1000);
}

As per your earlier advice about transaction state, I put Quit() before the asynchronous ListMessages call, and it does recognize new messages that come into the empty inbox after program start. It then fetches and deletes the message, but then after a few ticks of the Timer with 0 new messages, ListMessages strangely returns the id of that message again, and as the message is already deleted, Fetch throws an exception "Wrong Unique ID".

Using var messages = pop3.ListMessages(true); instead of the asynchronous Begin/End call doesn't have this problem, but I really want these calls asynchronous in my application if possible.

Thanks,
Martin

Hi Martin,


The BeginListMessage already implements this feature by default and the new API code example that I have shared works fine in this case. Could you please try it at your end and let us know your feedback? Also, can you please share why exactly would you like to avoid pop3.ListMessages(true) in this specific case?


Hi Kashif,


The code sample you mentioned uses the synchronous pop3.ListMessages(true);, not BeginListMessages. Have you tried my code? It definitely throws the exception I mentioned, and it shouldn’t.
I would like to use the asynchronous methods exactly because they are asynchronous and don’t block threads, as opposed to ListMessages() which can easily take 8 or more seconds under heavy load and will block my application. Also, I hope the Begin/End methods are truly asynchronous and wait for the response from the server, then callback, and that they aren’t actually synchronous under the covers and just block another thread for seconds…

Martin

Hi Martin,


As mentioned earlier, the enhancements made in the latest version enables one to use an initialized client in different threads without the begin/end methods and that is why the new style code sample was provided for your reference. Considering the requirement of BeginListMessages, I have requested development team’s feedback in this regard and will write back here once the information is available. I would request you to please spare us a little time until then.

Hi Kashif,


any news on this? It has been quite a while… I would like to use the Pop3Client Being/End methods for asynchronous processing of email messages just like with ImapClient, but something is obviously not working correctly here, that straightforward code example still throws and exception.

Martin

Hi Martin,


We are sorry for a delayed response.

The existing implementation of Asynchronous functionality enables to work as shown in the code example earlier. I am afraid but there is no more updates available with respect to its technical implementation as you require. I’ll update you here once there is some information available in this regard.

Hi Kashif,

I repeat, there is NO ASYNCHRONOUS FUNCTIONALITY in that example, you are queuing SYNCHRONOUS Pop3Client methods to a threapool, what is the purpose in the Begin/End methods in Pop3Client if they don't work, I don't see this as something to be dismissed and it has been 2 months, 2 updates with no news.

Martin

Hi Martin,


An investigation ticket with id: NETWORKNET-34428 has been launched to get development team’s feedback in this regard. Development team will investigate the issue soon and we’ll update you here soon about the information available in this regard. We apologize for the inconvenience caused to you.

Hi Martin,


We have thoroughly investigated your code and got the same result (i.e. got the same message id again which was deleted earlier). Your code is faithful however the problem is in the server. Probably server uses cache and needs a bit more time to update it. So if we execute BeginListMessages or ListMessages a bit later we will get correct result. Also please note, that server has to be configured to allow use POP3 delete operation (it concerns public mail servers such like GMail).

Hi Kashif,


OK, although something must be different in
var messages = pop3.LilstMessages(true)
vs
pop3.Quit();
var messages = await Task.Factory.FromAsync(pop3.BeginListMessages(), pop3.EndListMessages);

if the 1st never has this issue, but no big deal I will use the synchronous version, for ListMessages there is not much reason for parallelism etc.

Martin

Hi Martin,

Thank you for your understanding . Please feel free yo write to us in case you have any additional query related to Aspose.Email.

The issues you have found earlier (filed as NETWORKNET-34428) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi Kashif,

This is indeed fixed, thank you, this works just as it shoudl now:
var messages = await Task.Factory.FromAsync(pop3.BeginListMessages(), pop3.EndListMessages);

Althought similarly as for Imap, something seems terribly broken with async Fetch in the latest release, and this just hangs forever:
var message = await Task.Factory.FromAsync(pop3.BeginFetchMessage(id), pop3.EndFetchMessage);

Martin

Hi Martin,

As I mentioned for ImapClient, I was not able to reproduce that issue at my end using the latest version of Aspose.Email. If you have faced any issue with respect to Pop3.BeginFetchMessage, I would request you to please report the issue in a separate thread with sample code for our further investigation. We’ll look into it and assist you further.