aenetmail
aenetmail copied to clipboard
imap GetMessage returns null message
If there are 3 messages in my gmail account imap GetMessageCount() returns 3 but if I iterate over the messages (starting from index zero) I get two non-null messages and one null message. If the account only has one message in it GetMessageCount() returns 1 and GetMessage(0) returns NULL. GetMessages(0, count - 1, false) appears to work properly. I'm using the latest release as of this posting.
My bad. GetMessages(0, count, false) returns one less message as well. If count is 3 I get 2 messages. I verified that all three messages are actually there via my gmail account.
Ok, I figured it. If I instantiate a new imap client after discovery of a new email message (by looping on GetMessageCount), the new message shows up in GetMessages(...)
I'm now experiencing the same behavior after the 1.5.3 update, though I'm not sure if it's caused by the same issue. After stepping through the debugger I'm finding that the GetMessages function in ImapClient is terminating without returning the mail message.
x.Add(mail); response = _Reader.ReadLine(); // read last line terminated by ) response = _Reader.ReadLine(); // read next line
Immediately after calling the second _Reader.ReadLine(); the function terminates, so I'm assuming there's an exception or something in ReadLine causing it. Essentially, the new mail message is never returned from the function.
After stepping in, it looks like there are no responses left, so Responses.Take() is causing the thread to bomb perhaps and we are not seeing the exception? I noticed that it did not receive NewMessage events after that occurred, even though I sent a few more messages to that inbox, so that would back up my theory that the whole thread is dying.
I am having the same issue. My downloading code worked fine before I upgraded the library to 1.5.3 but now that I did the getMessage returns null. Have you found a solution ? Thank you very much
@piher https://github.com/andyedinborough/aenetmail/pull/17 So if you build your own you'll have the fix until Andy updates the Nuget repo
Does anyone else facing the issue that getMessage() with an option to return full email instead of headerOnly, simply returns null.
For me its reproducable with the following block of code:
IMAPae.MailMessage[] msgHeaders = cl.GetMessages("1", "*", false, true, true); IMAPae.MailMessage fullmsg; foreach(var msg in msgHeaders){ fullmsg = cl.GetMessage(msg.Uid); }
Thanks for any suggestions.
That's what I was talking about. The 1.5.3 returns null messages and the 1.5.0 doesn't but has troubles parsing headers (it cuts off the beginning of some message bodies). And sinced I wasn't sure what to do with the issues described by petersondrew, I just copied the correct parsing methods from the 1.5.3 into the 1.5.0 and it works fine for me. Here's a zip with 1.5.0, 1.5.3 and the fixed 1.5.0
http://www.megaupload.com/?d=N947ESCI
@petersondrew I couldn't spot the double call to getResponse in 1.5.3, has it been corrected ?
@piher Yes, I referenced the pull request that @andyedinborough merged in above. If you pull the latest you should be just fine.
@piher, @petersondrew thanks for your hints and suggestions. Unfortunately no one was helpful for me. @piher I tried my code (which you can see in my first post) with your fixed version. But it wasn't helpful at all.
Also the latest fixed branche of andy is not fixing the issue.
You can try it easily with this line of code:
IMAPae.MailMessage[] msgHeaders = cl.GetMessages("1", "*", false, true, true);
This should only return all headers of the selected mailbox. I was selecting a different mailbox as INBOX for testing purposes. GetMessage() returns only one message although there are 4 messages in the mailbox.
Thanks.
There seems to be a ReadResponse() still missing in TextClient.cs
x.Add(mail);
response = GetResponse(); // read last line terminated by )
response = GetResponse(); //<--- ADDING THIS MADE IT WORK
m = Regex.Match(response, reg);
Seems the line was deleted in some latest push, so it must have made something else break down.. but for now this seems to work for me
@RaduPoenaru yeah if you look at this pull request https://github.com/andyedinborough/aenetmail/pull/17 you'll see that I removed that line because it was causing the original issue in this thread. It seems we've somehow come full circle. Not sure what the solution is, what particular problem were you having that putting the second call to GetResponse back in fixed?
I guess it's all a matter of what usage pattern you have: I use a cycle of GetMessage(i,headersonly=true) followed imediately by GetMessage(i,headersonly=false).. and that combination seems to require the extra GetResponse() there or the response queue was getting out of sync (ie. growning a lot) and every second call the returned MailMessage was null.
The double GetResponse() fixed my issue. The context was getting mail headers in a loop.
It looks like the GetMessages method would return with the closing "{tag} OK" message still in the queue. I've added code to read from the queue until the OK message is found. I'm guessing that sometimes it was returned the first time, and sometimes it wasn't. Please check this fix in all your scenarios and let me know.
I just opened a new issue on a very similar problem. It's issue #37: https://github.com/andyedinborough/aenetmail/issues/37
I've recently downloaded AE.Net and just love it :)
However, I'm facing a problem similar to the other ones in this thread. The code below will result a null 'm' variable. In fact: no matter what index a pass, it comes back with null. I tried to download a fix from andyedinborough (#26 & #1), but it won't compile in my project. Any suggestions?
ic = new ImapClient("imap.gmail.com", "[email protected]", "xxxxxx",
ImapClient.AuthMethods.Login, 993, true);
ic.SelectMailbox("INBOX");
int ix = ic.GetMessageCount();
MailMessage m = ic.GetMessage(ix - 1, false);
Having the exact same issue with same scenario as nike2.