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

allow fetch from some bad imap server, which give envelope without the messageid field #669

Closed
bob-dawson opened this issue Mar 9, 2018 · 4 comments
Labels
compatibility Compatibility with existing software server-bug The bug appears to be in the server

Comments

@bob-dawson
Copy link

Some imap server response envelop wrong when the mail has no messageid, for example:

("Mon, 30 Oct 2017 11:05:21 +0800" "=?GBK?B?u7bTrcq508PM2tG2xvPStdPKz+Q=?=" (("=?GBK?B?zNrRtsbz0rXTys/k?=" NIL "10000" "qq.com")) (("=?GBK?B?zNrRtsbz0rXTys/k?=" NIL "10000" "qq.com")) (("=?GBK?B?zNrRtsbz0rXTys/k?=" NIL "10000" "qq.com")) NIL NIL NIL NIL)

which should be

("Mon, 30 Oct 2017 11:05:21 +0800" "=?GBK?B?u7bTrcq508PM2tG2xvPStdPKz+Q=?=" (("=?GBK?B?zNrRtsbz0rXTys/k?=" NIL "10000" "qq.com")) (("=?GBK?B?zNrRtsbz0rXTys/k?=" NIL "10000" "qq.com")) (("=?GBK?B?zNrRtsbz0rXTys/k?=" NIL "10000" "qq.com")) NIL NIL NIL NIL NIL)

Because these server just exists, MailKit users may just encounter one, and these will cause fetch operation fail. I think we can make a little change to allow fetch from thes bad servers.

Code in Envelope.cs line 512:

if (!TryParse (text, ref index, out messageid))
    return false;

We can change to

//allow parse response from some bad server which have no messageid for some message
var oldIndex = index;
if (!TryParse(text, ref index, out messageid))
{
    index = oldIndex;
}

And I make a new test for this:

[Test]
public void TestSerialization2()
{

	var text =
	    "('Mon, 30 Oct 2017 11:05:21 +0800' '=?GBK?B?u7bTrcq508PM2tG2xvPStdPKz+Q=?=' (('=?GBK?B?zNrRtsbz0rXTys/k?=' NIL '10000' 'qq.com')) (('=?GBK?B?zNrRtsbz0rXTys/k?=' NIL '10000' 'qq.com')) (('=?GBK?B?zNrRtsbz0rXTys/k?=' NIL '10000' 'qq.com')) NIL NIL NIL NIL)";
	text = text.Replace("'", "\"");
          

	var result = Envelope.TryParse(text, out var envelope);

        Assert.IsTrue(result);
        Assert.IsNull(envelope.MessageId);
	var text2 = envelope.ToString();

	Assert.AreNotEqual(text, text2);
}
   
@jstedfast
Copy link
Owner

This is why we can't have nice things :-\

jstedfast added a commit that referenced this issue Mar 9, 2018
@bob-dawson
Copy link
Author

Wow, your response is so fast, that's great!

@jstedfast jstedfast added the compatibility Compatibility with existing software label Mar 18, 2018
@jstedfast
Copy link
Owner

MailKit 2.0.2 has been released with this work-around.

@bob-dawson
Copy link
Author

Thanks, I've upgraded, and it's work perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with existing software server-bug The bug appears to be in the server
Projects
None yet
Development

No branches or pull requests

2 participants