Created
May 29, 2014 17:08
-
-
Save jstedfast/6ea6d03ce10d239e886e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/MailKit/Net/Imap/ImapFolder.cs b/MailKit/Net/Imap/ImapFolder.cs | |
index 3de9c2f..9667d2f 100644 | |
--- a/MailKit/Net/Imap/ImapFolder.cs | |
+++ b/MailKit/Net/Imap/ImapFolder.cs | |
@@ -2009,7 +2009,8 @@ namespace MailKit.Net.Imap { | |
if (token.Type != ImapTokenType.OpenParen) | |
throw ImapEngine.UnexpectedToken (token, false); | |
- token = engine.ReadToken (ic.CancellationToken); | |
+ // Note: GMail's IMAP implementation is broken and does not quote strings with square brackets like it should | |
+ token = engine.Stream.ReadToken (ImapStream.AtomSpecialsAllowSquareBrackets, ic.CancellationToken); | |
summary.GMailLabels = new List<string> (); | |
@@ -2018,7 +2019,7 @@ namespace MailKit.Net.Imap { | |
summary.GMailLabels.Add (label); | |
- token = engine.ReadToken (ic.CancellationToken); | |
+ token = engine.Stream.ReadToken (ImapStream.AtomSpecialsAllowSquareBrackets, ic.CancellationToken); | |
} | |
if (token.Type != ImapTokenType.CloseParen) | |
diff --git a/MailKit/Net/Imap/ImapStream.cs b/MailKit/Net/Imap/ImapStream.cs | |
index e0df9dc..ccfba0d 100644 | |
--- a/MailKit/Net/Imap/ImapStream.cs | |
+++ b/MailKit/Net/Imap/ImapStream.cs | |
@@ -57,7 +57,8 @@ namespace MailKit.Net.Imap { | |
class ImapStream : Stream | |
{ | |
- const string AtomSpecials = "()[]{%*\\\"\n"; | |
+ public const string AtomSpecialsAllowSquareBrackets = "(){%*\\\"\n"; | |
+ public const string AtomSpecials = "()[]{%*\\\"\n"; | |
const int ReadAheadSize = 128; | |
const int BlockSize = 4096; | |
const int PadSize = 4; | |
@@ -354,9 +355,9 @@ namespace MailKit.Net.Imap { | |
return n; | |
} | |
- static bool IsAtom (byte c) | |
+ static bool IsAtom (byte c, string specials) | |
{ | |
- return !IsCtrl (c) && !IsWhiteSpace (c) && AtomSpecials.IndexOf ((char) c) == -1; | |
+ return !IsCtrl (c) && !IsWhiteSpace (c) && specials.IndexOf ((char) c) == -1; | |
} | |
static bool IsCtrl (byte c) | |
@@ -421,7 +422,7 @@ namespace MailKit.Net.Imap { | |
} | |
} | |
- unsafe string ReadAtomString (byte* inbuf, bool flag, CancellationToken cancellationToken) | |
+ unsafe string ReadAtomString (byte* inbuf, bool flag, string specials, CancellationToken cancellationToken) | |
{ | |
var builder = new StringBuilder (); | |
byte* inptr = inbuf + inputIndex; | |
@@ -436,7 +437,7 @@ namespace MailKit.Net.Imap { | |
return "*"; | |
} | |
- while (IsAtom (*inptr)) | |
+ while (IsAtom (*inptr, specials)) | |
builder.Append ((char) *inptr++); | |
if (inptr < inend) | |
@@ -456,9 +457,9 @@ namespace MailKit.Net.Imap { | |
return builder.ToString (); | |
} | |
- unsafe ImapToken ReadAtomToken (byte* inbuf, CancellationToken cancellationToken) | |
+ unsafe ImapToken ReadAtomToken (byte* inbuf, string specials, CancellationToken cancellationToken) | |
{ | |
- var atom = ReadAtomString (inbuf, false, cancellationToken); | |
+ var atom = ReadAtomString (inbuf, false, specials, cancellationToken); | |
return atom == "NIL" ? new ImapToken (ImapTokenType.Nil, atom) : new ImapToken (ImapTokenType.Atom, atom); | |
} | |
@@ -467,7 +468,7 @@ namespace MailKit.Net.Imap { | |
{ | |
inputIndex++; | |
- var flag = "\\" + ReadAtomString (inbuf, true, cancellationToken); | |
+ var flag = "\\" + ReadAtomString (inbuf, true, AtomSpecials, cancellationToken); | |
return new ImapToken (ImapTokenType.Flag, flag); | |
} | |
@@ -583,6 +584,11 @@ namespace MailKit.Net.Imap { | |
/// </exception> | |
public ImapToken ReadToken (CancellationToken cancellationToken) | |
{ | |
+ return ReadToken (AtomSpecials, cancellationToken); | |
+ } | |
+ | |
+ internal ImapToken ReadToken (string specials, CancellationToken cancellationToken) | |
+ { | |
CheckDisposed (); | |
if (nextToken != null) { | |
@@ -629,8 +635,8 @@ namespace MailKit.Net.Imap { | |
if (c == '\\') | |
return ReadFlagToken (inbuf, cancellationToken); | |
- if (c != '+' && IsAtom (*inptr)) | |
- return ReadAtomToken (inbuf, cancellationToken); | |
+ if (c != '+' && IsAtom (*inptr, specials)) | |
+ return ReadAtomToken (inbuf, specials, cancellationToken); | |
// special character token | |
inputIndex++; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment