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

GetMessage endless loop #66

Closed
SaphuA opened this issue Jun 26, 2014 · 18 comments
Closed

GetMessage endless loop #66

SaphuA opened this issue Jun 26, 2014 · 18 comments

Comments

@SaphuA
Copy link

SaphuA commented Jun 26, 2014

Hello,

This is the first time I'm using MailKit and I'm trying to get the IMAP sample to work.
Unfortunatly something seems to be going wrong during the GetMessage call. It seems to be in an endless loop and never returns out of the method.

I added a ProtocolLogger to the ImapClient and according to the log it does actually download the entire message properly. The last thing logged is the retrieval of an image:

S: --002_2A8DFCCDD7437146AA5EE829D9FC63918384E934HVMSGWP25troika
S: Content-Type: image/png; name="image001.png"
S: Content-Description: image001.png
S: Content-Disposition: inline; filename="image001.png"; size=8154;
S: creation-date="Tue, 17 Jun 2014 12:53:40 GMT";
S: modification-date="Tue, 17 Jun 2014 12:53:40 GMT"
S: Content-ID: image001.png@01CF8A3B.ED0D5050
S: Content-Transfer-Encoding: base64
S:
S: iVBORw0KGgoAAAANSUhEUgAAAIEAAAArCAYAAABfJ+vYAAAABGdBTUEAALGOfPtRkwAAACBjSFJN
S: AACHDwAAjA8AAP1SAACBQAAAfXkAAOmLAAA85QAAGcxzPIV3AAAKL2lDQ1BJQ0MgUHJvZmlsZQAA
S: SMedlndUVNcWh8+9d3qhzTACUobeu8AA0nuTXkVhmBlgKAMOMzSxIaICEUVEmiJIUMSA0VAkVkSx
S: EBRUsAckCCgxGEVULG9G1ouurLz38vL746xv7bP3ufvsvc9aFwCSpy+XlwZLAZDKE/CDPJzpEZFR
S: dOwAgAEeYIApAExWRrpfsHsIEMnLzYWeIXICXwQB8HpYvAJw09AzgE4H/5+kWel8geiYABGbszkZ
S: LBEXiDglS5Auts+KmBqXLGYYJWa+KEERy4k5YZENPvsssqOY2ak8tojFOaezU9li7hXxtkwhR8SI
etc. etc. etc.

What could be going wrong that causes the GetMessage to be in an endess loop? What other information can I share?

My guess is that MailEngine.Wait is pretty dangerous. Guess I will have to download the source to do some debugging.

Thanks!

@jstedfast
Copy link
Owner

What are the last few lines of the log? My guess is that the server response is not complete.

@SaphuA
Copy link
Author

SaphuA commented Jun 26, 2014

So I just downloaded the source. Here's the call-stack of where it's stuck. It's in the do-while of the Poll method.

[External Code] 

MailKit.dll!MailKit.Net.Imap.ImapStream.Poll(System.Net.Sockets.SelectMode mode, System.Threading.CancellationToken cancellationToken) Line 259 + 0x1e bytes C#
MailKit.dll!MailKit.Net.Imap.ImapStream.ReadAhead(byte* inbuf, int atleast, System.Threading.CancellationToken cancellationToken) Line 308 + 0xf bytes C#
MailKit.dll!MailKit.Net.Imap.ImapStream.Read(byte[] buffer, int offset, int count, System.Threading.CancellationToken cancellationToken) Line 390 + 0x27 bytes C#
MailKit.dll!MailKit.Net.Imap.ImapFolder.FetchMessageBody(MailKit.Net.Imap.ImapEngine engine, MailKit.Net.Imap.ImapCommand ic, int index, MailKit.Net.Imap.ImapToken tok) Line 2717 + 0x65 bytes C#
MailKit.dll!MailKit.Net.Imap.ImapEngine.ProcessUntaggedResponse(System.Threading.CancellationToken cancellationToken) Line 1266 + 0x1c bytes C#
MailKit.dll!MailKit.Net.Imap.ImapCommand.Step() Line 497 + 0x2f bytes C#
MailKit.dll!MailKit.Net.Imap.ImapEngine.Iterate() Line 1340 + 0xf bytes C#
MailKit.dll!MailKit.Net.Imap.ImapEngine.Wait(MailKit.Net.Imap.ImapCommand ic) Line 1368 + 0xa bytes C#
MailKit.dll!MailKit.Net.Imap.ImapFolder.GetMessage(int index, System.Threading.CancellationToken cancellationToken) Line 2878 + 0x1e bytes C#
ClientWish.exe!ClientWish.Robot.Execute() Line 39 + 0x3c bytes C#
ClientWish.exe!ClientWish.Program.Main(string[] args) Line 25 + 0xa bytes C#
[External Code]

@jstedfast
Copy link
Owner

Right, that just means that it expects more data from the server... the question is: why? :-)

@SaphuA
Copy link
Author

SaphuA commented Jun 26, 2014

And these are the last lines of the log. They are part of the base64 encoded image.

S: /ErV8M0HO9OzWX9PP07vTf3Te/FxNw1Kv4ceTetNAzJ600/4+6iNPWh+3t9SYUVYABF/oC/duqpG
S: 21vxAXnDksQavLhyXzurMbROrasXbhvREbsDopi4Ag0D2X+D2IWZ2P3rxngRPsz+ksJbKWpdT1/g
S: j6b1oQHpfVn4eu1HGX38ewDJpOy7aPvhToYv9GVrADLJ5HHWfgO2BDpVf7adBAdXaNK2YbxGvWlF
S: 2VxVd150cQpthBN5MM1+fD+vTIR1W3IlZZZ2EQAk7/uaaDqEi2NtzRJ/IviCe4+m92RQ9JH7+D2A
S: rQTcBNwHXMnT217SyIKtS/jxtWwNltGUhAMRa+DuUcD3tdVLpa/qM4ciFkvWjf+R/KXLsm3autXC
S: XonoR9iIIcLSp0RGbvnb5E341hVTRtemtWHbvJ41k2oiP7kiwnUioLqz7/nKMm13tEQIV7llv+La

@jstedfast
Copy link
Owner

If those are the last few lines, then the server response is incomplete.

There should be a response like:

S: A0000016 OK ...

Until that line is received, the server response is incomplete.

@SaphuA
Copy link
Author

SaphuA commented Jun 26, 2014

Hmm, I guess you are right. I just copy/pasted the base64 string to a website that can decode base64 and only got halve the expected image as a result.

So I guess the next question is; what is the cause of the incomplete response?

Btw, thanks a lot for your quick responses!

@jstedfast
Copy link
Owner

No prob, you mostly just got lucky that I was just checking for new bug reports minutes after you filed it :p

There are a couple possibilities off the top of my head:

  1. the server is broken and thinks it sent the complete response
  2. your network connection dropped
  3. there's a bug in MailKit somewhere (but I can't even imagine where it could be since ImapStream logs to the log file immediately after reading data from the socket)

Does the log file end in the same place every time you run it? If so, that might indicate 1 (or 3). It could still be 2, but less likely.

If it ends in different places, that could indicate any of the above.

@SaphuA
Copy link
Author

SaphuA commented Jun 26, 2014

Yes it keeps loggin the exact same response on every try.

I will go and experiment with the fetch-methods to see if they yield the same results.

Update:

  • So far I don't have any problems with the fetch-methods.
  • The GetMessage method works on other e-mails.

What would you recommend is the best way to figure out where the problem is?

@jstedfast
Copy link
Owner

Ok, so I guess that means we can rule out flaky network (probably, anyway).

Can you test another client downloading that particular message? Just trying to rule out a bug in MailKit. If other clients break in the same way on that message, then it suggests it's probably a bug in the server.

What server is this, btw?

@jstedfast
Copy link
Owner

This is another IMAP client library you could try: https://imapx.codeplex.com/

@SaphuA
Copy link
Author

SaphuA commented Jun 26, 2014

It's an exchange server. I'm not sure about the version, but I guess either 2007 or 2010.

I'm having issues retrieving the folders using ImapX, will let you know when I get further. I'm about to call it a day ;)

Edit: Oops pressed close issue.

@SaphuA SaphuA closed this as completed Jun 26, 2014
@SaphuA SaphuA reopened this Jun 26, 2014
@jstedfast
Copy link
Owner

I may have an idea what is causing the problem. Are you using SSL by chance?

It might be that the SslStream has already buffered the remainder of the data and so the Poll() would block forever waiting for data that has already been read from the socket by the SslStream.

@jstedfast
Copy link
Owner

I committed a patch that may fix your issue if this is the case...

@SaphuA
Copy link
Author

SaphuA commented Jun 27, 2014

Excellent, it's working now!

i'm not 100% sure if exchange is configured to use SSL, but I'm pretty sure you've guessed right.

Thanks a lot!

Edit: Will you be releasing an update to nuget any time soon? Would rather use nuget than include the source in my project.

@jstedfast
Copy link
Owner

Yea, I'll be releasing a new version soon (by Monday morning the latest - which is my usual release date), but possibly today. I'd like to try to clean up the new logic a bit first.

Thanks for testing it out and getting back to me.

@jstedfast
Copy link
Owner

Just released MailKit 0.21 on nuget

@SaphuA
Copy link
Author

SaphuA commented Jun 30, 2014

You're the best!

@jstedfast
Copy link
Owner

I try :-)

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

2 participants