public override eProcessDataResult ProcessData(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cNamespaceDataProcessor), nameof(ProcessData)); if (!pCursor.SkipBytes(kNamespaceSpace)) { return(eProcessDataResult.notprocessed); } if (ZProcessData(pCursor, out var lPersonal, lContext) && pCursor.SkipByte(cASCII.SPACE) && ZProcessData(pCursor, out var lOtherUsers, lContext) && pCursor.SkipByte(cASCII.SPACE) && ZProcessData(pCursor, out var lShared, lContext) && pCursor.Position.AtEnd ) { lContext.TraceVerbose("got namespaces"); NamespaceNames = new cNamespaceNames(lPersonal, lOtherUsers, lShared); mSynchroniser.InvokePropertyChanged(nameof(cIMAPClient.Namespaces), lContext); return(eProcessDataResult.processed); } lContext.TraceWarning("likely malformed namespace"); return(eProcessDataResult.notprocessed); }
public override void ProcessTextCode(eResponseTextContext pTextContext, cByteList pCode, cByteList pArguments, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandHookCopy), nameof(ProcessTextCode), pTextContext, pCode, pArguments); if (pTextContext == eResponseTextContext.success && pCode.Equals(kCopyUID)) { if (pArguments != null) { cBytesCursor lCursor = new cBytesCursor(pArguments); if (lCursor.GetNZNumber(out _, out var lDestinationUIDValidity) && lCursor.SkipByte(cASCII.SPACE) && lCursor.GetSequenceSet(out var lSourceUIDSet) && lCursor.SkipByte(cASCII.SPACE) && lCursor.GetSequenceSet(out var lCreatedUIDSet) && lCursor.Position.AtEnd && cUIntList.TryConstruct(lSourceUIDSet, -1, false, out var lSourceUIDs) && cUIntList.TryConstruct(lCreatedUIDSet, -1, false, out var lCreatedUIDs) && lSourceUIDs.Count == lCreatedUIDs.Count) { Feedback = new cCopyFeedback(mSourceUIDValidity, lSourceUIDs, lDestinationUIDValidity, lCreatedUIDs); return; } } lContext.TraceWarning("likely malformed copyuid response"); } }
public bool Process(cBytesCursor pCursor, out cResponseData rResponseData, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cResponseDataParserLSub), nameof(Process)); if (!pCursor.SkipBytes(kLSubSpace)) { rResponseData = null; return(false); } if (!pCursor.GetFlags(out var lFlags) || !pCursor.SkipByte(cASCII.SPACE) || !pCursor.GetMailboxDelimiter(out var lDelimiter) || !pCursor.SkipByte(cASCII.SPACE) || !pCursor.GetAString(out IList <byte> lEncodedMailboxPath) || !pCursor.Position.AtEnd || !cMailboxName.TryConstruct(lEncodedMailboxPath, lDelimiter, mUTF8Enabled, out var lMailboxName)) { lContext.TraceWarning("likely malformed lsub response"); rResponseData = null; return(true); } rResponseData = new cResponseDataLSub(lMailboxName, !lFlags.Contains(@"\Noselect", StringComparer.InvariantCultureIgnoreCase)); return(true); }
private static bool ZGetId(cBytesCursor pCursor, out cId rServerId, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cIdDataProcessor), nameof(ZGetId)); if (pCursor.SkipBytes(cBytesCursor.Nil)) { rServerId = null; return(true); } if (!pCursor.SkipByte(cASCII.LPAREN)) { rServerId = null; return(false); } Dictionary <string, string> lDictionary = new Dictionary <string, string>(); try { bool lFirst = true; while (true) { if (pCursor.SkipByte(cASCII.RPAREN)) { break; } if (lFirst) { lFirst = false; } else if (!pCursor.SkipByte(cASCII.SPACE)) { rServerId = null; return(false); } if (!pCursor.GetString(out string lField) || !pCursor.SkipByte(cASCII.SPACE)) { rServerId = null; return(false); } if (!pCursor.GetNString(out string lValue)) { rServerId = null; return(false); } lDictionary[lField] = lValue; } rServerId = new cId(lDictionary); return(true); } catch (Exception e) { lContext.TraceException("error when constructing the id dictionary", e); rServerId = null; return(false); } }
private bool ZProcessDataStatusAttributes(cBytesCursor pCursor, out cStatus rStatus, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cMailboxCache), nameof(ZProcessDataStatusAttributes)); uint? lMessages = null; uint? lRecent = null; uint? lUIDNext = null; uint? lUIDValidity = null; uint? lUnseen = null; ulong?lHighestModSeq = null; while (true) { eProcessStatusAttributeResult lResult; lResult = ZProcessDataStatusAttribute(pCursor, kMessagesSpace, ref lMessages, lContext); if (lResult == eProcessStatusAttributeResult.notprocessed) { lResult = ZProcessDataStatusAttribute(pCursor, kRecentSpace, ref lRecent, lContext); if (lResult == eProcessStatusAttributeResult.notprocessed) { lResult = ZProcessDataStatusAttribute(pCursor, kUIDNextSpace, ref lUIDNext, lContext); if (lResult == eProcessStatusAttributeResult.notprocessed) { lResult = ZProcessDataStatusAttribute(pCursor, kUIDValiditySpace, ref lUIDValidity, lContext); if (lResult == eProcessStatusAttributeResult.notprocessed) { lResult = ZProcessDataStatusAttribute(pCursor, kUnseenSpace, ref lUnseen, lContext); if (lResult == eProcessStatusAttributeResult.notprocessed) { lResult = ZProcessDataStatusAttribute(pCursor, kHighestModSeqSpace, ref lHighestModSeq, lContext); } } } } } if (lResult != eProcessStatusAttributeResult.processed) { rStatus = null; return(false); } if (!pCursor.SkipByte(cASCII.SPACE)) { if (!mCapabilities.CondStore) { lHighestModSeq = 0; } rStatus = new cStatus(mSequence++, lMessages, lRecent, lUIDNext, lUIDValidity, lUnseen, lHighestModSeq); return(true); } } }
private bool ZProcessData(cBytesCursor pCursor, out List <cNamespaceName> rNames, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cNamespaceDataProcessor), nameof(ZProcessData)); if (pCursor.SkipBytes(cBytesCursor.Nil)) { rNames = null; return(true); } if (!pCursor.SkipByte(cASCII.LPAREN)) { rNames = null; return(false); } rNames = new List <cNamespaceName>(); while (true) { if (!pCursor.SkipByte(cASCII.LPAREN) || !pCursor.GetString(out IList <byte> lEncodedPrefix) || !pCursor.SkipByte(cASCII.SPACE) || !pCursor.GetMailboxDelimiter(out var lDelimiter) || !ZProcessNamespaceExtension(pCursor) || !pCursor.SkipByte(cASCII.RPAREN) ) { rNames = null; return(false); } if (!cNamespaceName.TryConstruct(lEncodedPrefix, lDelimiter, mUTF8Enabled, out var lNamespaceName)) { rNames = null; return(false); } rNames.Add(lNamespaceName); if (pCursor.SkipByte(cASCII.RPAREN)) { return(true); } } }
private static bool ZProcessExtendedItems(cBytesCursor pCursor, out cListExtendedItems rItems) { rItems = new cListExtendedItems(); if (!pCursor.SkipByte(cASCII.SPACE)) { return(true); } if (!pCursor.SkipByte(cASCII.LPAREN)) { return(false); } while (true) { if (!pCursor.GetAString(out string lTag)) { break; } if (!pCursor.SkipByte(cASCII.SPACE)) { return(false); } if (!pCursor.ProcessExtendedValue(out var lValue)) { return(false); } rItems.Add(new cListExtendedItem(lTag, lValue)); if (!pCursor.SkipByte(cASCII.SPACE)) { break; } } if (!pCursor.SkipByte(cASCII.RPAREN)) { return(false); } return(true); }
private bool ZProcessNamespaceExtension(cBytesCursor pCursor) { while (true) { if (!pCursor.SkipByte(cASCII.SPACE)) { return(true); } if (!pCursor.GetString(out IList <byte> _) || !pCursor.SkipByte(cASCII.SPACE) || !pCursor.SkipByte(cASCII.LPAREN) || !pCursor.GetString(out IList <byte> _) ) { return(false); } while (true) { if (!pCursor.SkipByte(cASCII.SPACE)) { break; } if (!pCursor.GetString(out IList <byte> _)) { return(false); } } if (!pCursor.SkipByte(cASCII.RPAREN)) { return(false); } } }
public override eProcessDataResult ProcessData(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cEnableCommandHook), nameof(ProcessData)); if (!pCursor.SkipBytes(kEnabled)) { return(eProcessDataResult.notprocessed); } fEnableableExtensions lEnabledExtensions = fEnableableExtensions.none; while (true) { if (!pCursor.SkipByte(cASCII.SPACE)) { break; } if (!pCursor.GetToken(cCharset.Atom, null, null, out cByteList lAtom)) { lContext.TraceWarning("likely malformed enabled: not an atom list?"); return(eProcessDataResult.notprocessed); } lContext.TraceVerbose("got an enabled for {0}", lAtom); if (cASCII.Compare(lAtom, kEnableExtensionUTF8, false)) { lEnabledExtensions = lEnabledExtensions | fEnableableExtensions.utf8; } // more here as required else { lContext.TraceError("unknown extension enabled: {0}", lAtom); } } if (!pCursor.Position.AtEnd) { lContext.TraceWarning("likely malformed enabled: not at end?"); return(eProcessDataResult.notprocessed); } mEnabledExtensions |= lEnabledExtensions; return(eProcessDataResult.processed); }
private bool ZValidPart(string pPart) { var lCursor = new cBytesCursor(pPart); while (true) { if (!lCursor.GetNZNumber(out _, out _)) { return(false); } if (!lCursor.SkipByte(cASCII.DOT)) { break; } } return(lCursor.Position.AtEnd); }
public override eProcessDataResult ProcessData(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandHookBaseSearch), nameof(ProcessData)); if (!pCursor.SkipBytes(kSearch)) { return(eProcessDataResult.notprocessed); } cUIntList lMSNs = new cUIntList(); while (true) { if (!pCursor.SkipByte(cASCII.SPACE)) { break; } if (!pCursor.GetNZNumber(out _, out var lMSN)) { lContext.TraceWarning("likely malformed search: not an nz-number list?"); return(eProcessDataResult.notprocessed); } lMSNs.Add(lMSN); } if (!pCursor.Position.AtEnd) { lContext.TraceWarning("likely malformed search: not at end?"); return(eProcessDataResult.notprocessed); } if (mMSNs == null) { mMSNs = lMSNs; } else { mMSNs.AddRange(lMSNs); } return(eProcessDataResult.processed); }
public eProcessDataResult ProcessData(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cMailboxCache), nameof(ProcessData)); if (mSelectedMailbox != null) { var lBookmark = pCursor.Position; var lResult = mSelectedMailbox.ProcessData(pCursor, lContext); if (lResult != eProcessDataResult.notprocessed) { return(lResult); } pCursor.Position = lBookmark; } if (pCursor.SkipBytes(kStatusSpace)) { if (!pCursor.GetAString(out string lEncodedMailboxPath) || !pCursor.SkipBytes(cBytesCursor.SpaceLParen) || !ZProcessDataStatusAttributes(pCursor, out var lStatus, lContext) || !pCursor.SkipByte(cASCII.RPAREN) || !pCursor.Position.AtEnd) { lContext.TraceWarning("likely malformed status response"); return(eProcessDataResult.notprocessed); } var lItem = ZItem(lEncodedMailboxPath); lItem.UpdateStatus(lStatus, lContext); if (!ReferenceEquals(mSelectedMailbox?.MailboxHandle, lItem)) { lItem.UpdateMailboxStatus(lContext); } return(eProcessDataResult.processed); } return(eProcessDataResult.notprocessed); }
internal static void _Tests(cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cBytesCursor), nameof(_Tests)); cBytesCursor lCursor; sPosition lBookmark; IList <byte> lBytes; lCursor = MakeCursor("", "", ""); if (!lCursor.Position.AtEnd) { throw new cTestsException("responsecursor - not at end"); } lCursor = MakeCursor("", "", "{ ", ""); if (lCursor.Position.AtEnd) { throw new cTestsException("responsecursor - not at end"); } if (lCursor.SkipByte(cASCII.SPACE)) { throw new cTestsException("responsecursor - shouldn't skip literal"); } lCursor = MakeCursor("", "", " ", ""); if (!lCursor.SkipByte(cASCII.SPACE)) { throw new cTestsException("responsecursor - didn't skip space"); } if (!lCursor.Position.AtEnd) { throw new cTestsException("responsecursor - not at end"); } lCursor = MakeCursor("", "AB", "CD", ""); if (lCursor.SkipBytes(new cBytes("ABCDE"))) { throw new cTestsException("responsecursor - found ABCDE"); } if (!lCursor.SkipBytes(new cBytes("ABCD"))) { throw new cTestsException("responsecursor - no ABCD"); } if (!lCursor.Position.AtEnd) { throw new cTestsException("responsecursor - not at end"); } lCursor = MakeCursor("ABCD", "{ABCD", ""); lBookmark = lCursor.Position; if (!lCursor.SkipByte(cASCII.A)) { throw new cTestsException("responsecursor - no A"); } lCursor.Position = lBookmark; if (!lCursor.SkipByte(cASCII.a)) { throw new cTestsException("responsecursor - no a"); } lCursor.Position = lBookmark; if (lCursor.SkipByte(cASCII.a, true)) { throw new cTestsException("responsecursor - a isn't A"); } if (!lCursor.SkipByte(cASCII.A) || !lCursor.SkipByte(cASCII.B)) { throw new cTestsException("responsecursor - no AB"); } lCursor.Position = lBookmark; if (lCursor.SkipBytes(new cBytes("ABX"))) { throw new cTestsException("responsecursor - found ABX"); } if (lCursor.SkipBytes(new cBytes("ABCDA"))) { throw new cTestsException("responsecursor - found ABCDA"); } if (!lCursor.SkipBytes(new cBytes("AB")) || !lCursor.SkipBytes(new cBytes("CD"))) { throw new cTestsException("responsecursor - no A"); } if (lCursor.SkipBytes(null)) { throw new cTestsException("responsecursor - skip literal"); } if (lCursor.SkipByte(cASCII.A)) { throw new cTestsException("responsecursor - skip literal"); } if (lCursor.GetString(out lBytes)) { if (!cASCII.Compare(lBytes, new cBytes("ABCD"), false)) { throw new cTestsException("responsecursor - not ABCD"); } if (!lCursor.Position.AtEnd) { throw new cTestsException("responsecursor - not at end"); } if (lCursor.GetString(out lBytes)) { throw new cTestsException("responsecursor - not at end"); } } else { throw new cTestsException("responsecursor - no string"); } lCursor = MakeCursor("A", "B"); if (!lCursor.SkipByte(cASCII.A) || !lCursor.SkipByte(cASCII.B)) { throw new cTestsException("responsecursor - no AB"); } lCursor = MakeCursor("", "A", "", "B"); if (!lCursor.SkipByte(cASCII.A) || !lCursor.SkipByte(cASCII.B)) { throw new cTestsException("responsecursor - no AB"); } lCursor = MakeCursor("\"AB\\\\CD\\\"EF\" "); if (lCursor.GetString(out lBytes)) { if (!cASCII.Compare(lBytes, new cBytes("AB\\CD\"EF"), false)) { throw new cTestsException("responsecursor - not AB\\CD\"EF"); } if (lCursor.Position.AtEnd) { throw new cTestsException("responsecursor - at end"); } if (lCursor.GetString(out lBytes)) { throw new cTestsException("responsecursor - not at end"); } if (!lCursor.SkipByte(cASCII.SPACE)) { throw new cTestsException("responsecursor - no space"); } if (!lCursor.Position.AtEnd) { throw new cTestsException("responsecursor - not at end"); } } else { throw new cTestsException("responsecursor - no string"); } lCursor = MakeCursor("\"AB\\\\CD\\\"EF"); if (lCursor.GetString(out lBytes)) { throw new cTestsException("responsecursor - found a string"); } if (!lCursor.SkipByte(cASCII.DQUOTE) || !lCursor.SkipByte(cASCII.A)) { throw new cTestsException("responsecursor - no \"A"); } lCursor = MakeCursor("AT", "OM]ATOM(", "{literal", "ATOM)ATOM{ATOM%ATOM*ATOM\"ATOM\\ATOM ASTRIN]G"); cByteList lToken; lBookmark = lCursor.Position; if (!lCursor.GetToken(cCharset.Atom, null, null, out lToken) || !cASCII.Compare(lToken, new cBytes("aToM"), false) || !lCursor.SkipByte(cASCII.RBRACKET)) { throw new cTestsException("responsecursor - not atom"); } lCursor.Position = lBookmark; if (!lCursor.GetToken(cCharset.AString, null, null, out lToken) || !cASCII.Compare(lToken, new cBytes("aToM]atom"), false) || !lCursor.SkipByte(cASCII.LPAREN)) { throw new cTestsException("responsecursor - not atom"); } if (lCursor.GetToken(cCharset.TextNotRBRACKET, null, null, out lToken)) { throw new cTestsException("responsecursor - literal"); } if (!lCursor.GetString(out lBytes) || !cASCII.Compare(lBytes, new cBytes("literal"), false)) { throw new cTestsException("responsecursor - literal"); } if (lCursor.GetToken(cCharset.Atom, null, null, out lToken, 5)) { throw new cTestsException("min length"); } if (!lCursor.GetToken(cCharset.Atom, null, null, out lToken, 1, 2) || !cASCII.Compare(lToken, new cBytes("AT"), false)) { throw new cTestsException("max length"); } lCursor = MakeCursor("fr%E2%82%acd"); lBookmark = lCursor.Position; string lString; if (!lCursor.GetToken(cCharset.TextNotRBRACKET, null, null, out lString)) { throw new cTestsException("didn't get string 1"); } if (lString != "fr%E2%82%acd") { throw new cTestsException("didn't get right string 1"); } lCursor.Position = lBookmark; if (!lCursor.GetToken(cCharset.TextNotRBRACKET, cASCII.PERCENT, null, out lToken)) { throw new cTestsException("didn't get string 2"); } if (lToken.Count != 6 || lToken[0] != cASCII.f || lToken[1] != cASCII.r || lToken[2] != 226 || lToken[3] != 130 || lToken[4] != 172 || lToken[5] != cASCII.d) { throw new cTestsException("didn't get right string 2"); } lCursor.Position = lBookmark; if (!lCursor.GetToken(cCharset.TextNotRBRACKET, cASCII.PERCENT, null, out lString)) { throw new cTestsException("didn't get string 3"); } if (lString != "fr€d") { throw new cTestsException("didn't get right string 3"); } lCursor = MakeCursor("A1", "2345", "", "67890123"); uint lNumber; if (lCursor.GetNumber(out _, out lNumber)) { throw new cTestsException("A is not a digit"); } if (!lCursor.SkipByte(cASCII.A)) { throw new cTestsException("A not skipped"); } if (lCursor.GetNumber(out _, out lNumber)) { throw new cTestsException("number should be too big"); } if (!lCursor.GetNumber(out _, out lNumber, 1, 9) || lNumber != 123456789) { throw new cTestsException("number max length"); } if (lCursor.GetNZNumber(out _, out lNumber)) { throw new cTestsException("nznumber 1"); } if (!lCursor.SkipByte(cASCII.ZERO) || !lCursor.GetNZNumber(out _, out lNumber) || lNumber != 123) { throw new cTestsException("nznumber 2"); } lCursor = MakeCursor("04-Apr-1968\"5-APR-1968\"\"5-APR-1968x32-apr-1968014-Apr-196830-Apx-1968\"30-April-1968\"\"30-Apr-68\"\"31-Feb-1968\""); DateTime lDate; if (!lCursor.GetDate(out lDate) || lDate != new DateTime(1968, 4, 4, 0, 0, 0, DateTimeKind.Utc)) { throw new cTestsException("date form 1"); } if (!lCursor.GetDate(out lDate) || lDate != new DateTime(1968, 4, 5, 0, 0, 0, DateTimeKind.Utc)) { throw new cTestsException("date form 2"); } if (lCursor.GetDate(out lDate)) { throw new cTestsException("date should have failed on no terminating quote"); } if (!lCursor.SkipBytes(new cBytes("\"5-aPr-1968X"))) { throw new cTestsException("date skip"); } if (lCursor.GetDate(out lDate)) { throw new cTestsException("date should have failed on days > 31"); } if (!lCursor.SkipBytes(new cBytes("32-apr-1968"))) { throw new cTestsException("date skip 2"); } if (lCursor.GetDate(out lDate)) { throw new cTestsException("date should have failed on no hypen"); } if (!lCursor.SkipBytes(new cBytes("014-Apr-1968"))) { throw new cTestsException("date skip 3"); } if (lCursor.GetDate(out lDate)) { throw new cTestsException("date should have failed on invalid month"); } if (!lCursor.SkipBytes(new cBytes("30-Apx-1968"))) { throw new cTestsException("date skip 4"); } if (lCursor.GetDate(out lDate)) { throw new cTestsException("date should have failed on no hypen (2)"); } if (!lCursor.SkipBytes(new cBytes("\"30-April-1968\""))) { throw new cTestsException("date skip 5"); } if (lCursor.GetDate(out lDate)) { throw new cTestsException("date should have failed on 4 digit year"); } if (!lCursor.SkipBytes(new cBytes("\"30-Apr-68\""))) { throw new cTestsException("date skip 6"); } if (lCursor.GetDate(out lDate)) { throw new cTestsException("date should have failed on invalid days per month"); } if (!lCursor.SkipBytes(new cBytes("\"31-Feb-1968\""))) { throw new cTestsException("date skip 7"); } lCursor = MakeCursor("\" 4-apr-1968 23:59:59 +0000\"\"04-apr-1968 23:59:59 +1200\"\"28-apr-1968 23:59:59 +1130\"\"28-apr-1968 11:59:59 -1000\""); if (!lCursor.GetDateTime(out lDate) || lDate != new DateTime(1968, 4, 4, 23, 59, 59, DateTimeKind.Utc)) { throw new cTestsException("datetime 1"); } if (!lCursor.GetDateTime(out lDate) || lDate != new DateTime(1968, 4, 4, 11, 59, 59, DateTimeKind.Utc)) { throw new cTestsException("datetime 2"); } if (!lCursor.GetDateTime(out lDate) || lDate != new DateTime(1968, 4, 28, 12, 29, 59, DateTimeKind.Utc)) { throw new cTestsException("datetime 3"); } if (!lCursor.GetDateTime(out lDate) || lDate != new DateTime(1968, 4, 28, 21, 59, 59, DateTimeKind.Utc)) { throw new cTestsException("datetime 4"); } // more to do ... lCursor = MakeCursor("1968-04-04T23:59:59Z,1968-04-04T23:59:59+12:00,1968-04-28T23:59:59+11:30,1968-04-28T11:59:59-10:00"); if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1968, 4, 4, 23, 59, 59, DateTimeKind.Utc) || !lCursor.SkipByte(cASCII.COMMA)) { throw new cTestsException("timestamp 1.1"); } if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1968, 4, 4, 11, 59, 59, DateTimeKind.Utc) || !lCursor.SkipByte(cASCII.COMMA)) { throw new cTestsException("timestamp 1.2"); } if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1968, 4, 28, 12, 29, 59, DateTimeKind.Utc) || !lCursor.SkipByte(cASCII.COMMA)) { throw new cTestsException("timestamp 1.3"); } if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1968, 4, 28, 21, 59, 59, DateTimeKind.Utc)) { throw new cTestsException("timestamp 1.4"); } // examples from rfc3339 lCursor = new cBytesCursor("1985-04-12T23:20:50.52Z,1996-12-19T16:39:57-08:00,1990-12-31T23:59:60Z,1990-12-31T15:59:60-08:00,1937-01-01T12:00:27.87+00:20"); if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1985, 04, 12, 23, 20, 50, 520, DateTimeKind.Utc) || !lCursor.SkipByte(cASCII.COMMA)) { throw new cTestsException("timestamp 2.1"); } if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1996, 12, 20, 00, 39, 57, DateTimeKind.Utc) || !lCursor.SkipByte(cASCII.COMMA)) { throw new cTestsException("timestamp 2.2"); } if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1990, 12, 31, 23, 59, 59, DateTimeKind.Utc) || !lCursor.SkipByte(cASCII.COMMA)) { throw new cTestsException("timestamp 2.3"); } if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1990, 12, 31, 23, 59, 59, DateTimeKind.Utc) || !lCursor.SkipByte(cASCII.COMMA)) { throw new cTestsException("timestamp 2.4"); } //if (!lCursor.GetTimeStamp(out lDate) || lDate != new DateTime(1937, 01, 01, 12, 19, 32, 130, DateTimeKind.Utc)) throw new cTestsException("timestamp 2.5"); _Tests_Capability(lContext); _Tests_SequenceSet(lContext); _Tests_RFC822(lContext); // <todo: getastring cBytesCursor MakeCursor(params string[] pLines) { List <cResponseLine> lLines = new List <cResponseLine>(); foreach (var lLine in pLines) { if (lLine.Length > 0 && lLine[0] == '{') { lLines.Add(new cResponseLine(true, new cBytes(lLine.TrimStart('{')))); } else { lLines.Add(new cResponseLine(false, new cBytes(lLine))); } } return(new cBytesCursor(new cResponse(lLines))); } }
public static void _Tests_RFC822(cTrace.cContext pParentContext) { cBytesCursor lCursor; string lString; DateTime lDate; cByteList lByteList; // tests for WSP lCursor = new cBytesCursor("x \t y \t\r\n\tz"); if (!lCursor.SkipByte(cASCII.x) || !lCursor.SkipRFC822WSP() || lCursor.SkipRFC822WSP() || !lCursor.SkipByte(cASCII.y) || !lCursor.SkipRFC822FWS() || lCursor.SkipRFC822FWS() || !lCursor.SkipByte(cASCII.z)) { throw new cTestsException("skip wsp 1"); } lCursor = new cBytesCursor("x \t y \t\r\n\tz"); if (!lCursor.SkipByte(cASCII.x) || !lCursor.SkipRFC822FWS() || lCursor.SkipRFC822FWS() || !lCursor.SkipByte(cASCII.y) || !lCursor.SkipRFC822FWS() || !lCursor.SkipByte(cASCII.z)) { throw new cTestsException("skip wsp 2"); } lCursor = new cBytesCursor("x \t\r\ny \t\r\n\t\r\n z"); if (!lCursor.SkipByte(cASCII.x) || !lCursor.SkipRFC822FWS() || lCursor.SkipRFC822FWS() || !lCursor.SkipBytes(new cBytes("\r\ny")) || !lCursor.SkipRFC822FWS() || !lCursor.SkipByte(cASCII.z)) { throw new cTestsException("skip wsp 3"); } lCursor = new cBytesCursor("Muhammed.(I am the greatest) Ali\r\n @(the)Vegas.WBA"); if (!lCursor.GetToken(cCharset.Atom, null, null, out lString) || lString != "Muhammed." || !lCursor.SkipRFC822CFWS() || !lCursor.GetToken(cCharset.Atom, null, null, out lString) || lString != "Ali" || !lCursor.SkipRFC822CFWS() || !lCursor.SkipByte(cASCII.AT) || !lCursor.SkipRFC822CFWS() || !lCursor.GetToken(cCharset.Atom, null, null, out lString) || lString != "Vegas.WBA") { throw new cTestsException("skip cfws 1"); } lCursor = new cBytesCursor("(I am \r\n the(xx\\)\\\\\\() gre \t() \tatest)"); if (!lCursor.SkipRFC822CFWS() || !lCursor.Position.AtEnd) { throw new cTestsException("skip cfws 2"); } // TODO: more tests for failure cases // tests for IMF date (these examples from rfc 5322) lCursor = new cBytesCursor("Fri, 21 Nov 1997 09:55:06 -0600 x Tue, 1 Jul 2003 10:52:37 +0200 x Thu, 13 Feb 1969 23:32:54 -0330 x Thu,\r\n\t13\r\n\t Feb\r\n\t 1969\r\n\t23:32\r\n\t\t\t-0330 (Newfoundland Time) x 21 Nov 97 09:55:06 GMT x Fri, 21 Nov 1997 09(comment): 55 : 06 -0600 x"); if (!lCursor.GetRFC822DateTime(out lDate) || lDate != new DateTime(1997, 11, 21, 15, 55, 06) || !lCursor.SkipByte(cASCII.x)) { throw new cTestsException("imf date 1"); } if (!lCursor.GetRFC822DateTime(out lDate) || lDate != new DateTime(2003, 7, 1, 8, 52, 37) || !lCursor.SkipByte(cASCII.x)) { throw new cTestsException("imf date 2"); } if (!lCursor.GetRFC822DateTime(out lDate) || lDate != new DateTime(1969, 2, 14, 3, 02, 54) || !lCursor.SkipByte(cASCII.x)) { throw new cTestsException("imf date 3"); } if (!lCursor.GetRFC822DateTime(out lDate) || lDate != new DateTime(1969, 2, 14, 3, 02, 00) || !lCursor.SkipByte(cASCII.x)) { throw new cTestsException("imf date 4"); } if (!lCursor.GetRFC822DateTime(out lDate) || lDate != new DateTime(1997, 11, 21, 9, 55, 06) || !lCursor.SkipByte(cASCII.x)) { throw new cTestsException("imf date 5"); } if (!lCursor.GetRFC822DateTime(out lDate) || lDate != new DateTime(1997, 11, 21, 15, 55, 06) || !lCursor.SkipByte(cASCII.x)) { throw new cTestsException("imf date 6"); } // TODO: more tests for failure cases and alphanumeric zones // Wed, 17 Jul 1996 02:23:25 -0700 (PDT) // header values lCursor = new cBytesCursor(" \t \r\nHeader \t: \r\n\t \t\r\n\r\n"); if (lCursor.GetRFC822FieldName(out lString) || !lCursor.GetRFC822FieldValue(out lByteList) || cTools.UTF8BytesToString(lByteList) != " \t ") { throw new cTestsException("header 1.1"); } if (!lCursor.GetRFC822FieldName(out lString) || lString != "Header" || !lCursor.SkipRFC822WSP() || !lCursor.SkipByte(cASCII.COLON) || !lCursor.GetRFC822FieldValue(out lByteList) || cTools.UTF8BytesToString(lByteList) != " \t \t") { throw new cTestsException("header 1.2"); } lCursor = new cBytesCursor("Header \t : \r\n \t\r\nFred"); if (!lCursor.GetRFC822FieldName(out lString) || lString != "Header" || !lCursor.SkipRFC822WSP() || !lCursor.SkipByte(cASCII.COLON) || !lCursor.GetRFC822FieldValue(out lByteList) || cTools.UTF8BytesToString(lByteList) != " \t") { throw new cTestsException("header 2.1"); } lCursor = new cBytesCursor("Header:\r\n this is \r\n the\tvalue \t\r\n"); if (!lCursor.GetRFC822FieldName(out lString) || lString != "Header" || lCursor.SkipRFC822WSP() || !lCursor.SkipByte(cASCII.COLON) || !lCursor.GetRFC822FieldValue(out lByteList) || cTools.UTF8BytesToString(lByteList) != " this is the\tvalue \t") { throw new cTestsException("header 3.1"); } lCursor = new cBytesCursor("Header:\r\n should \r\n fail \t\r\n more stuff"); if (!lCursor.GetRFC822FieldName(out lString) || lString != "Header" || lCursor.SkipRFC822WSP() || !lCursor.SkipByte(cASCII.COLON) || lCursor.GetRFC822FieldValue(out lByteList)) { throw new cTestsException("header 4.1"); } // atoms lCursor = new cBytesCursor(" \t \r\n Header \tAtom(comment) \r\nAt?Om\tAt!om:{Atom} \t\r\n\r\n"); if (!lCursor.GetRFC822Atom(out lString) || lString != "Header" || !lCursor.GetRFC822Atom(out lString) || lString != "Atom") { throw new cTestsException("atom 1.1"); } if (!lCursor.SkipByte(cASCII.CR) || !lCursor.SkipByte(cASCII.LF)) { throw new cTestsException("atom 1.2"); } if (!lCursor.GetRFC822Atom(out lString) || lString != "At?Om") { throw new cTestsException("atom 1.3"); } if (!lCursor.GetRFC822Atom(out lString) || lString != "At!om") { throw new cTestsException("atom 1.4"); } if (lCursor.GetRFC822Atom(out lString)) { throw new cTestsException("atom 1.5.1"); } if (!lCursor.SkipByte(cASCII.COLON)) { throw new cTestsException("atom 1.5.2"); } if (!lCursor.GetRFC822Atom(out lString) || lString != "{Atom}") { throw new cTestsException("atom 1.6"); } if (!lCursor.SkipByte(cASCII.CR) || !lCursor.SkipByte(cASCII.LF) || !lCursor.SkipByte(cASCII.CR) || !lCursor.SkipByte(cASCII.LF) || !lCursor.Position.AtEnd) { throw new cTestsException("atom 1.7"); } // quoted strings lCursor = new cBytesCursor(" \t \r\n \"Header\r\n with FWS\" \t\"Atom(not a \\\"comment\\\")\" \r\n\"At?Om\"\t\"At!om:{Atom}\" \"\r\n\tFWS beginning and end\r\n\t\" \t\r\n\r\n"); if (!lCursor.GetRFC822QuotedString(out lString) || lString != "Header with FWS" || !lCursor.GetRFC822QuotedString(out lString) || lString != "Atom(not a \"comment\")") { throw new cTestsException("quoted string 1.1"); } if (!lCursor.SkipByte(cASCII.CR) || !lCursor.SkipByte(cASCII.LF)) { throw new cTestsException("quoted string 1.2"); } if (!lCursor.GetRFC822QuotedString(out lString) || lString != "At?Om") { throw new cTestsException("quoted string 1.3"); } if (!lCursor.GetRFC822QuotedString(out lString) || lString != "At!om:{Atom}") { throw new cTestsException("quoted string 1.4"); } if (!lCursor.GetRFC822QuotedString(out lString) || lString != "\tFWS beginning and end\t") { throw new cTestsException("quoted string 1.5"); } if (lCursor.GetRFC822QuotedString(out lString)) { throw new cTestsException("quoted string 1.6.1"); } if (!lCursor.SkipByte(cASCII.CR) || !lCursor.SkipByte(cASCII.LF) || !lCursor.SkipByte(cASCII.CR) || !lCursor.SkipByte(cASCII.LF) || !lCursor.Position.AtEnd) { throw new cTestsException("quoted string 1.6.2"); } // mix lCursor = new cBytesCursor(" \t \r\n Header \tA"); if (lCursor.GetRFC822QuotedString(out lString) || lCursor.Position.Byte != 0 || !lCursor.GetRFC822Atom(out lString) || lString != "Header" || !lCursor.SkipByte(cASCII.A)) { throw new cTestsException("mix 1.1"); } lCursor = new cBytesCursor(" \t \r\n \"Header\" \tA"); if (lCursor.GetRFC822Atom(out lString) || lCursor.Position.Byte != 0 || !lCursor.GetRFC822QuotedString(out lString) || lString != "Header" || !lCursor.SkipByte(cASCII.A)) { throw new cTestsException("mix 1.2"); } // domain literal lCursor = new cBytesCursor(" \t (there is a domain\r\n literal coming up(and\tit'll\r\n\tbe a good one)) \r\n [Header] \r\n ( now with with FWS ) [ \t \r\n\t the.name.com \r\n ] (now with embedded FWS) [ \t \r\n\t the \t name \r\n com \r\n ] (with quotes and utf8) [ \\[ fr€d ] (something invalid) [ [ ] \r\n"); if (!lCursor.GetDomainLiteral(out lString) || lString != "[Header]") { throw new cTestsException("domain literal 1.1"); } if (!lCursor.GetDomainLiteral(out lString) || lString != "[the.name.com]") { throw new cTestsException("domain literal 1.2"); } if (!lCursor.GetDomainLiteral(out lString) || lString != "[the name com]") { throw new cTestsException("domain literal 1.3"); } if (!lCursor.GetDomainLiteral(out lString) || lString != "[[ fr€d]") { throw new cTestsException("domain literal 1.4"); } if (lCursor.GetDomainLiteral(out lString)) { throw new cTestsException("domain literal 1.5"); } if (!lCursor.GetRFC822FieldValue(out lByteList) || cTools.UTF8BytesToString(lByteList) != "[ [ ] ") { throw new cTestsException("domain literal 1.6"); } // domain lCursor = new cBytesCursor(" \t (first a dot-atom form) fred.angus.bart (now a obs form) frxd \t . angxs . \t bxrt (now a\r\n literal) [ 192.168.1.1 ] \r\nNextHeader"); if (!lCursor.GetRFC822Domain(out lString) || lString != "fred.angus.bart") { throw new cTestsException("domain 1.1"); } if (!lCursor.GetRFC822Domain(out lString) || lString != "frxd.angxs.bxrt") { throw new cTestsException("domain 1.2"); } if (!lCursor.GetRFC822Domain(out lString) || lString != "[192.168.1.1]") { throw new cTestsException("domain 1.3"); } if (!lCursor.GetRFC822FieldValue(out lByteList) || lByteList.Count != 0) { throw new cTestsException("domain 1.4"); } if (lCursor.GetRestAsString() != "NextHeader") { throw new cTestsException("domain 1.5"); } // local part lCursor = new cBytesCursor(" \t (first a dot-atom form) fred.angus.bart (now a obs form) frxd \t . angxs . \t bxrt (now a\r\n quoted string) \"th€ local part as a string\" (then a second obsolete form) \"fr€d\" \t . angxs . \t \"bzrt\" \r\n "); if (!lCursor.GetRFC822LocalPart(out lString) || lString != "fred.angus.bart") { throw new cTestsException("local part 1.1"); } if (!lCursor.GetRFC822LocalPart(out lString) || lString != "frxd.angxs.bxrt") { throw new cTestsException("local part 1.2"); } if (!lCursor.GetRFC822LocalPart(out lString) || lString != "th€ local part as a string") { throw new cTestsException("local part 1.3"); } if (!lCursor.GetRFC822LocalPart(out lString) || lString != "fr€d.angxs.bzrt") { throw new cTestsException("local part 1.4"); } if (!lCursor.Position.AtEnd) { throw new cTestsException("local part 1.5"); } lCursor = new cBytesCursor(" \t (edge case) fred.angus.bart . [] \r\nNextHeader"); if (!lCursor.GetRFC822LocalPart(out lString) || lString != "fred.angus.bart") { throw new cTestsException("local part 2.1"); } if (!lCursor.GetRFC822FieldValue(out lByteList) || cTools.UTF8BytesToString(lByteList) != ". [] ") { throw new cTestsException("local part 2.2"); } // message id lCursor = new cBytesCursor(" \r\n\t (one) <*****@*****.**> <*****@*****.**> <*****@*****.**> <1234 @ local(blah) .machine .example> "); if (!lCursor.GetRFC822MsgId(out lString) || lString != "*****@*****.**") { throw new cTestsException("msgid 1.1"); } if (!lCursor.GetRFC822MsgId(out lString) || lString != "*****@*****.**") { throw new cTestsException("msgid 1.2"); } if (!lCursor.GetRFC822MsgId(out lString) || lString != "*****@*****.**") { throw new cTestsException("msgid 1.3"); } if (!lCursor.GetRFC822MsgId(out lString) || lString != "*****@*****.**") { throw new cTestsException("msgid 1.4"); } }
public cResponseText Process(eResponseTextContext pTextContext, cBytesCursor pCursor, iTextCodeProcessor pTextCodeProcessor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cResponseTextProcessor), nameof(Process), pTextContext); cResponseText lResponseText; var lBookmarkBeforeLBRACET = pCursor.Position; if (pCursor.SkipByte(cASCII.LBRACKET)) { if (ZTryGetCodeAndArguments(pCursor, out var lCodeBytes, out var lArgumentsBytes)) { string lText = pCursor.GetRestAsString(); if (lArgumentsBytes == null) { eResponseTextCode lCode; if (lCodeBytes.Equals(kAlert)) { lCode = eResponseTextCode.alert; } else if (lCodeBytes.Equals(kParse)) { lCode = eResponseTextCode.parse; } else if (lCodeBytes.Equals(kTryCreate)) { lCode = eResponseTextCode.trycreate; } else if (lCodeBytes.Equals(kUnavailable)) { lCode = eResponseTextCode.unavailable; } else if (lCodeBytes.Equals(kAuthenticationFailed)) { lCode = eResponseTextCode.authenticationfailed; } else if (lCodeBytes.Equals(kAuthorizationFailed)) { lCode = eResponseTextCode.authorizationfailed; } else if (lCodeBytes.Equals(kExpired)) { lCode = eResponseTextCode.expired; } else if (lCodeBytes.Equals(kPrivacyRequired)) { lCode = eResponseTextCode.privacyrequired; } else if (lCodeBytes.Equals(kContactAdmin)) { lCode = eResponseTextCode.contactadmin; } else if (lCodeBytes.Equals(kNoPerm)) { lCode = eResponseTextCode.noperm; } else if (lCodeBytes.Equals(kInUse)) { lCode = eResponseTextCode.inuse; } else if (lCodeBytes.Equals(kExpungeIssued)) { lCode = eResponseTextCode.expungeissued; } else if (lCodeBytes.Equals(kCorruption)) { lCode = eResponseTextCode.corruption; } else if (lCodeBytes.Equals(kServerBug)) { lCode = eResponseTextCode.serverbug; } else if (lCodeBytes.Equals(kClientBug)) { lCode = eResponseTextCode.clientbug; } else if (lCodeBytes.Equals(kCannot)) { lCode = eResponseTextCode.cannot; } else if (lCodeBytes.Equals(kLimit)) { lCode = eResponseTextCode.limit; } else if (lCodeBytes.Equals(kOverQuota)) { lCode = eResponseTextCode.overquota; } else if (lCodeBytes.Equals(kAlreadyExists)) { lCode = eResponseTextCode.alreadyexists; } else if (lCodeBytes.Equals(kNonExistent)) { lCode = eResponseTextCode.nonexistent; } else if (lCodeBytes.Equals(kBadCharset)) { lCode = eResponseTextCode.badcharset; } else if (lCodeBytes.Equals(kUseAttr)) { lCode = eResponseTextCode.useattr; } else if (lCodeBytes.Equals(kUnknownCTE)) { lCode = eResponseTextCode.unknowncte; } else { lCode = eResponseTextCode.other; ZProcess(pTextContext, lCodeBytes, null, pTextCodeProcessor, lContext); } lResponseText = new cResponseText(lCodeBytes, lCode, lText); } else { eResponseTextCode lCode; cStrings lArguments; if (lCodeBytes.Equals(kBadCharset)) { lCode = eResponseTextCode.badcharset; lArguments = ZProcessCharsets(lArgumentsBytes); } else if (lCodeBytes.Equals(kReferral)) { lCode = eResponseTextCode.referral; lArguments = ZProcessReferrals(lArgumentsBytes, lContext); } else { lCode = eResponseTextCode.other; lArguments = null; ZProcess(pTextContext, lCodeBytes, lArgumentsBytes, pTextCodeProcessor, lContext); } lResponseText = new cResponseText(lCodeBytes, lArgumentsBytes, lCode, lArguments, lText); } } else { lContext.TraceWarning("likely badly formed response text code"); pCursor.Position = lBookmarkBeforeLBRACET; lResponseText = new cResponseText(pCursor.GetRestAsString()); } }
public bool Process(cBytesCursor pCursor, out cResponseData rResponseData, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cResponseDataParserESearch), nameof(Process)); if (!pCursor.SkipBytes(kESearch)) { rResponseData = null; return(false); } if (pCursor.Position.AtEnd) { rResponseData = new cResponseDataESearch(null, false, null); return(true); } bool lSetParsedAs = false; // just in case there is another response that starts with the string "ESEARCH" IList <byte> lTag; if (pCursor.SkipBytes(kSpaceLParenTAGSpace)) { if (!pCursor.GetString(out lTag) || !pCursor.SkipByte(cASCII.RPAREN)) { rResponseData = null; return(true); } lSetParsedAs = true; } else { lTag = null; } bool lUID; if (pCursor.SkipBytes(kSpaceUID)) { lUID = true; lSetParsedAs = true; } else { lUID = false; } cSequenceSet lSequenceSet = null; while (true) { if (!pCursor.SkipByte(cASCII.SPACE)) { break; } lSetParsedAs = true; if (!pCursor.GetToken(cCharset.Atom, null, null, out cByteList lName) || !pCursor.SkipByte(cASCII.SPACE) || !pCursor.ProcessExtendedValue(out var lValue) ) { rResponseData = null; return(true); } if (cASCII.Compare(lName, kAll, false) && lValue is cExtendedValue.cSequenceSetEV lSequenceSetEV) { lSequenceSet = lSequenceSetEV.SequenceSet; } } if (!pCursor.Position.AtEnd) { rResponseData = null; return(lSetParsedAs); } rResponseData = new cResponseDataESearch(lTag, lUID, lSequenceSet); return(true); }
internal cCulturedString(IList <byte> pBytes) { if (pBytes == null) { throw new ArgumentNullException(nameof(pBytes)); } if (pBytes.Count == 0) { Parts = null; return; } cBytesCursor lCursor = new cBytesCursor(pBytes); List <cCulturedStringPart> lParts = new List <cCulturedStringPart>(); cByteList lBytes = new cByteList(); bool lPendingSpace = false; while (!lCursor.Position.AtEnd) { var lBookmark = lCursor.Position; if (lCursor.ProcessEncodedWord(out var lString, out var lLanguageTag) && (lCursor.Position.AtEnd || lCursor.SkipByte(cASCII.SPACE))) { if (lBytes.Count > 0) { lParts.Add(new cCulturedStringPart(cTools.UTF8BytesToString(lBytes), null)); lBytes = new cByteList(); } lParts.Add(new cCulturedStringPart(lString, lLanguageTag)); lPendingSpace = true; }
private static bool ZTryConstruct(cHeaderFieldNames pNames, bool pNot, IList <byte> pBytes, out cHeaderFields rFields) { if (pBytes == null) { rFields = null; return(false); } cBytesCursor lCursor = new cBytesCursor(pBytes); List <cHeaderField> lFields = new List <cHeaderField>(); while (true) { if (!lCursor.GetRFC822FieldName(out var lName)) { break; } lCursor.SkipRFC822WSP(); if (!lCursor.SkipByte(cASCII.COLON)) { rFields = null; return(false); } if (!lCursor.GetRFC822FieldValue(out var lValue)) { rFields = null; return(false); } if (lName.Equals(kHeaderFieldName.References, StringComparison.InvariantCultureIgnoreCase)) { if (cHeaderFieldMsgIds.TryConstruct(lName, lValue, out var lReferences)) { lFields.Add(lReferences); } else { lFields.Add(new cHeaderField(lName, new cBytes(lValue))); } } else if (lName.Equals(kHeaderFieldName.Importance, StringComparison.InvariantCultureIgnoreCase)) { if (cHeaderFieldImportance.TryConstruct(lValue, out var lImportance)) { lFields.Add(lImportance); } else { lFields.Add(new cHeaderField(lName, new cBytes(lValue))); } } else { lFields.Add(new cHeaderField(lName, new cBytes(lValue))); } } if (!lCursor.Position.AtEnd && !lCursor.SkipBytes(cBytesCursor.CRLF)) { rFields = null; return(false); } rFields = new cHeaderFields(pNames, pNot, lFields); return(true); }
public bool Process(cBytesCursor pCursor, out cResponseData rResponseData, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cResponseDataParserList), nameof(Process)); if (!pCursor.SkipBytes(kListSpace)) { rResponseData = null; return(false); } if (!pCursor.GetFlags(out var lFlags) || !pCursor.SkipByte(cASCII.SPACE) || !pCursor.GetMailboxDelimiter(out var lDelimiter) || !pCursor.SkipByte(cASCII.SPACE) || !pCursor.GetAString(out IList <byte> lEncodedMailboxPath) || !ZProcessExtendedItems(pCursor, out var lExtendedItems) || !pCursor.Position.AtEnd) { lContext.TraceWarning("likely malformed list response"); rResponseData = null; return(true); } if (lEncodedMailboxPath.Count == 0) { if (lFlags.Count == 0 && lExtendedItems.Count == 0) { if (lDelimiter == null) { rResponseData = new cResponseDataListDelimiter(); } else { rResponseData = new cResponseDataListDelimiter((char)lDelimiter.Value); } } else { lContext.TraceWarning("likely malformed list delimiter response"); rResponseData = null; } } else { if (cMailboxName.TryConstruct(lEncodedMailboxPath, lDelimiter, mUTF8Enabled, out var lMailboxName)) { fListFlags lListFlags = 0; if (lFlags.Contains(@"\Noinferiors", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.noinferiors | fListFlags.hasnochildren; } if (lFlags.Contains(@"\Noselect", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.noselect; } if (lFlags.Contains(@"\Marked", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.marked; } if (lFlags.Contains(@"\Unmarked", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.unmarked; } if (lFlags.Contains(@"\NonExistent", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.noselect | fListFlags.nonexistent; } if (lFlags.Contains(@"\Subscribed", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.subscribed; } if (lFlags.Contains(@"\Remote", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.remote; } if (lFlags.Contains(@"\HasChildren", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.haschildren; } if (lFlags.Contains(@"\HasNoChildren", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.hasnochildren; } if (lFlags.Contains(@"\All", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.all; } if (lFlags.Contains(@"\Archive", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.archive; } if (lFlags.Contains(@"\Drafts", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.drafts; } if (lFlags.Contains(@"\Flagged", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.flagged; } if (lFlags.Contains(@"\Junk", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.junk; } if (lFlags.Contains(@"\Sent", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.sent; } if (lFlags.Contains(@"\Trash", StringComparer.InvariantCultureIgnoreCase)) { lListFlags |= fListFlags.trash; } bool lHasSubscribedChildren = false; foreach (var lItem in lExtendedItems) { if (lItem.Tag.Equals("childinfo", StringComparison.InvariantCultureIgnoreCase) && lItem.Value.Contains("subscribed", StringComparison.InvariantCultureIgnoreCase)) { lHasSubscribedChildren = true; break; } } rResponseData = new cResponseDataListMailbox(lMailboxName, lListFlags, lHasSubscribedChildren); } else { lContext.TraceWarning("likely malformed list mailbox response"); rResponseData = null; } } return(true); }