aenetmail icon indicating copy to clipboard operation
aenetmail copied to clipboard

imap GetMessage returns null message

Open psychic-puppy opened this issue 12 years ago • 19 comments

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.

psychic-puppy avatar Nov 08 '11 20:11 psychic-puppy

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.

psychic-puppy avatar Nov 08 '11 21:11 psychic-puppy

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(...)

psychic-puppy avatar Nov 08 '11 22:11 psychic-puppy

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.

petersondrew avatar Dec 30 '11 15:12 petersondrew

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.

petersondrew avatar Dec 30 '11 15:12 petersondrew

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 avatar Jan 07 '12 16:01 piher

@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

petersondrew avatar Jan 07 '12 21:01 petersondrew

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.

jigga-j avatar Jan 13 '12 12:01 jigga-j

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 avatar Jan 14 '12 17:01 piher

@piher Yes, I referenced the pull request that @andyedinborough merged in above. If you pull the latest you should be just fine.

petersondrew avatar Jan 14 '12 18:01 petersondrew

@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.

jigga-j avatar Jan 15 '12 01:01 jigga-j

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 avatar Jan 30 '12 15:01 RaduPoenaru

@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?

petersondrew avatar Jan 30 '12 18:01 petersondrew

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.

RaduPoenaru avatar Feb 01 '12 09:02 RaduPoenaru

The double GetResponse() fixed my issue. The context was getting mail headers in a loop.

AndyClaw avatar Feb 04 '12 22:02 AndyClaw

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.

andyedinborough avatar Feb 05 '12 01:02 andyedinborough

I just opened a new issue on a very similar problem. It's issue #37: https://github.com/andyedinborough/aenetmail/issues/37

pcgeek86 avatar Feb 26 '12 06:02 pcgeek86

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);

nike2 avatar Feb 27 '12 07:02 nike2

Having the exact same issue with same scenario as nike2.

sigh71 avatar Feb 28 '12 07:02 sigh71