Skip to content

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

Description

@bob-dawson

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibilityCompatibility with existing softwareserver-bugThe bug appears to be in the server

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions