Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imap GetMessage returns null message #1

Open
psychic-puppy opened this issue Nov 8, 2011 · 19 comments
Open

imap GetMessage returns null message #1

psychic-puppy opened this issue Nov 8, 2011 · 19 comments

Comments

@psychic-puppy
Copy link

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
Copy link
Author

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
Copy link
Author

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

@petersondrew
Copy link
Contributor

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
Copy link
Contributor

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.

@piher
Copy link
Contributor

piher commented Jan 7, 2012

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

@petersondrew
Copy link
Contributor

@piher #17
So if you build your own you'll have the fix until Andy updates the Nuget repo

@jigga-j
Copy link
Contributor

jigga-j commented Jan 13, 2012

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.

@piher
Copy link
Contributor

piher commented Jan 14, 2012

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 ?

@petersondrew
Copy link
Contributor

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

@jigga-j
Copy link
Contributor

jigga-j commented Jan 15, 2012

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

@RaduPoenaru
Copy link

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

@petersondrew
Copy link
Contributor

@RaduPoenaru yeah if you look at this pull request #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?

@RaduPoenaru
Copy link

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.

@AndyClaw
Copy link

AndyClaw commented Feb 4, 2012

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

andyedinborough added a commit that referenced this issue Feb 5, 2012
@andyedinborough
Copy link
Owner

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.

@pcgeek86
Copy link

I just opened a new issue on a very similar problem. It's issue #37: #37

@nike2
Copy link

nike2 commented Feb 27, 2012

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

@sigh71
Copy link

sigh71 commented Feb 28, 2012

Having the exact same issue with same scenario as nike2.

andyedinborough added a commit that referenced this issue Feb 29, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

11 participants