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; }
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(cCommandHookInitial), nameof(ProcessTextCode), pTextContext, pCode, pArguments); if (pTextContext == eResponseTextContext.greetingok || pTextContext == eResponseTextContext.greetingpreauth || pTextContext == eResponseTextContext.success) { if (pCode.Equals(kCapability)) { if (pArguments != null) { cBytesCursor lCursor = new cBytesCursor(pArguments); if (lCursor.ProcessCapability(out var lCapabilities, out var lAuthenticationMechanisms, lContext) && lCursor.Position.AtEnd) { lContext.TraceVerbose("received capabilities: {0} {1}", lCapabilities, lAuthenticationMechanisms); Capabilities = lCapabilities; AuthenticationMechanisms = lAuthenticationMechanisms; return; } } lContext.TraceWarning("likely malformed capability response"); } } }
public override void ProcessTextCode(eResponseTextContext pTextContext, cByteList pCode, cByteList pArguments, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandHookStore), nameof(ProcessTextCode), pTextContext, pCode, pArguments); if (pTextContext == eResponseTextContext.success || pTextContext == eResponseTextContext.failure) { if (pCode.Equals(kModified)) { if (pArguments != null) { cBytesCursor lCursor = new cBytesCursor(pArguments); if (lCursor.GetSequenceSet(out var lSequenceSet) && lCursor.Position.AtEnd && cUIntList.TryConstruct(lSequenceSet, mSelectedMailbox.MessageCache.Count, true, out var lUInts)) { foreach (var lUInt in lUInts) { if (!mFeedbackCollector.WasNotUnchangedSince(lUInt)) { lContext.TraceWarning("likely malformed modified response: message number not recognised: ", lUInt); return; } } return; } } lContext.TraceWarning("likely malformed modified response"); } } }
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"); } }
internal static bool TryConstruct(string pName, IList <byte> pValue, out cHeaderFieldMsgIds rMsgIds) { if (pValue == null) { rMsgIds = null; return(false); } List <string> lMsgIds = new List <string>(); cBytesCursor lCursor = new cBytesCursor(pValue); while (true) { if (!lCursor.GetRFC822MsgId(out var lMsgId)) { break; } lMsgIds.Add(lMsgId); } if (lCursor.Position.AtEnd) { rMsgIds = new cHeaderFieldMsgIds(pName, new cBytes(pValue), new cStrings(lMsgIds)); return(true); } rMsgIds = null; return(false); }
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 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 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 async Task <eIdleProcessResponsesTerminatedBy> ZIdleProcessResponsesAsync(bool pMonitorBackgroundReleaser, Task pCountdownTask, cCommandTag pTag, bool pExpectContinueRequest, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZIdleProcessResponsesAsync), pMonitorBackgroundReleaser, pTag, pExpectContinueRequest); Task lBackgroundReleaserTask; if (pMonitorBackgroundReleaser) { lBackgroundReleaserTask = mBackgroundReleaser.GetAwaitReleaseTask(lContext); } else { lBackgroundReleaserTask = null; } while (true) { Task lBuildResponseTask = mConnection.GetBuildResponseTask(lContext); Task lTask = await mBackgroundAwaiter.AwaitAny(lBuildResponseTask, lBackgroundReleaserTask, pCountdownTask).ConfigureAwait(false); if (ReferenceEquals(lTask, lBackgroundReleaserTask)) { return(eIdleProcessResponsesTerminatedBy.backgroundreleaser); } if (ReferenceEquals(lTask, pCountdownTask)) { return(eIdleProcessResponsesTerminatedBy.countdowntask); } var lResponse = mConnection.GetResponse(lContext); mSynchroniser.InvokeNetworkReceive(lResponse, lContext); var lCursor = new cBytesCursor(lResponse); if (lCursor.SkipBytes(kPlusSpace)) { if (!pExpectContinueRequest) { throw new cUnexpectedServerActionException(fCapabilities.idle, "unexpected continuation request", lContext); } mResponseTextProcessor.Process(eResponseTextContext.continuerequest, lCursor, null, lContext); return(eIdleProcessResponsesTerminatedBy.continuerequest); } if (ZProcessDataResponse(lCursor, lContext)) { continue; } if (pTag != null && ZProcessCommandCompletionResponse(lCursor, pTag, false, null, lContext) != null) { return(eIdleProcessResponsesTerminatedBy.commandcompletion); } lContext.TraceError("unrecognised response: {0}", lResponse); } }
private cURLParts ZGetURLParts(string pURL) { var lCursor = new cBytesCursor(pURL); if (!cURLParts.Process(lCursor, out var lParts, cTrace.cContext.None) || !lCursor.Position.AtEnd) { return(null); } return(lParts); }
private async Task ZBackgroundTaskProcessResponseAsync(cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZBackgroundTaskProcessResponseAsync)); var lResponse = mConnection.GetResponse(lContext); mSynchroniser.InvokeNetworkReceive(lResponse, lContext); var lCursor = new cBytesCursor(lResponse); if (lCursor.SkipBytes(kPlusSpace)) { var lCurrentCommand = mCurrentCommand; if (lCurrentCommand == null || !lCurrentCommand.WaitingForContinuationRequest) { throw new cUnexpectedServerActionException(0, "unexpected continuation request", lContext); } if (lCurrentCommand.IsAuthentication) { await ZProcessChallengeAsync(lCursor, lContext).ConfigureAwait(false); } else { mResponseTextProcessor.Process(eResponseTextContext.continuerequest, lCursor, lCurrentCommand.Hook, lContext); lCurrentCommand.WaitingForContinuationRequest = false; } return; } lock (mPipelineLock) { if (ZProcessDataResponse(lCursor, lContext)) { return; } if (ZBackgroundTaskProcessActiveCommandCompletion(lCursor, lContext)) { return; } if (mCurrentCommand != null && ZBackgroundTaskProcessCommandCompletion(lCursor, mCurrentCommand, lContext)) { if (mCurrentCommand.IsAuthentication) { mCurrentCommand = null; } return; } } lContext.TraceError("unrecognised response: {0}", lResponse); }
private bool ZProcessDataResponse(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZProcessDataResponse)); if (!pCursor.SkipBytes(kProcessResponseAsteriskSpace)) { return(false); } lContext.TraceVerbose("got data"); if (pCursor.SkipBytes(kProcessResponseOKSpace)) { lContext.TraceVerbose("got information"); mResponseTextProcessor.Process(eResponseTextContext.information, pCursor, mActiveCommands, lContext); return(true); } if (pCursor.SkipBytes(kProcessResponseNoSpace)) { lContext.TraceVerbose("got a warning"); mResponseTextProcessor.Process(eResponseTextContext.warning, pCursor, mActiveCommands, lContext); return(true); } if (pCursor.SkipBytes(kProcessResponseBadSpace)) { lContext.TraceVerbose("got a protocol error"); mResponseTextProcessor.Process(eResponseTextContext.protocolerror, pCursor, mActiveCommands, lContext); return(true); } if (pCursor.SkipBytes(kProcessResponseCapabilitySpace)) { if (mState == eState.connected) { if (pCursor.ProcessCapability(out var lCapabilities, out var lAuthenticationMechanisms, lContext) && pCursor.Position.AtEnd) { lContext.TraceVerbose("got capabilities: {0} {1}", lCapabilities, lAuthenticationMechanisms); mCapabilities = lCapabilities; mAuthenticationMechanisms = lAuthenticationMechanisms; } else { lContext.TraceWarning("likely malformed capability"); } } else { lContext.TraceWarning("capability response received at the wrong time - not processed"); } return(true); }
private static void _Tests_MailboxName(string pMailboxPath, bool pExpectFail, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cMailboxName), nameof(_Tests_MailboxName), pMailboxPath); cCommandPartFactory lFactory; cCommandPart lCommandPart; cBytesCursor lCursor; IList <byte> lEncodedMailboxPath; cMailboxName lMailboxName; lFactory = new cCommandPartFactory(false, null); if (!lFactory.TryAsMailbox(pMailboxPath, '/', out lCommandPart, out _)) { throw new cTestsException($"mailboxname conversion failed on '{pMailboxPath}'"); } cTextCommandPart lTCP = lCommandPart as cTextCommandPart; lCursor = new cBytesCursor(lTCP.Bytes); lCursor.GetAString(out lEncodedMailboxPath); if (cMailboxName.TryConstruct(lEncodedMailboxPath, cASCII.SLASH, false, out lMailboxName)) { if (pExpectFail) { throw new cTestsException($"mailboxname construction succeeded on '{pMailboxPath}' and it shouldn't have"); } } else { if (!pExpectFail) { throw new cTestsException($"mailboxname construction failed on '{pMailboxPath}' and it shouldn't have"); } return; } if (lMailboxName.Path != pMailboxPath) { throw new cTestsException($"mailboxname conversion failed on '{pMailboxPath}' -> {lTCP.Bytes} -> '{lMailboxName}'", lContext); } lFactory = new cCommandPartFactory(true, null); lFactory.TryAsMailbox(pMailboxPath, '/', out lCommandPart, out _); lTCP = lCommandPart as cTextCommandPart; lCursor = new cBytesCursor(lTCP.Bytes); lCursor.GetAString(out lEncodedMailboxPath); cMailboxName.TryConstruct(lEncodedMailboxPath, cASCII.SLASH, true, out lMailboxName); if (lMailboxName.Path != pMailboxPath) { throw new cTestsException($"mailboxname conversion failed on '{pMailboxPath}' -> {lTCP.Bytes} -> '{lMailboxName}'", lContext); } }
public eProcessDataResult ProcessData(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cSelectedMailboxCache), nameof(ProcessData)); if (pCursor.GetNZNumber(out _, out var lNumber) && pCursor.SkipBytes(kSpaceExpunge) && pCursor.Position.AtEnd) { lContext.TraceVerbose("got expunge: {0}", lNumber); ZExpunge((int)lNumber, lContext); return(eProcessDataResult.processed); } return(eProcessDataResult.notprocessed); }
private async Task ZProcessChallengeAsync(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZProcessChallengeAsync)); IList <byte> lResponse; if (cBase64.TryDecode(pCursor.GetRestAsBytes(), out var lChallenge, out var lError)) { try { lResponse = mCurrentCommand.GetAuthenticationResponse(lChallenge); } catch (Exception e) { lContext.TraceException("SASL authentication object threw", e); lResponse = null; } }
/// <summary> /// Initialises a new instance from the specified string. Will throw if the string cannot be parsed. /// </summary> /// <param name="pURL"></param> public cURL(string pURL) { if (string.IsNullOrEmpty(pURL)) { throw new ArgumentOutOfRangeException(nameof(pURL)); } var lCursor = new cBytesCursor(pURL); if (!cURLParts.Process(lCursor, out mParts, cTrace.cContext.None) || !lCursor.Position.AtEnd) { throw new ArgumentOutOfRangeException(nameof(pURL)); } OriginalString = pURL; }
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 ZBackgroundTaskProcessActiveCommandCompletion(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZBackgroundTaskProcessActiveCommandCompletion)); for (int i = 0; i < mActiveCommands.Count; i++) { var lCommand = mActiveCommands[i]; if (ZBackgroundTaskProcessCommandCompletion(pCursor, lCommand, lContext)) { mActiveCommands.RemoveAt(i); return(true); } } return(false); }
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 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); }
internal static bool TryConstruct(string pName, IList <byte> pValue, out cHeaderFieldMsgId rMsgId) { if (pValue == null) { rMsgId = null; return(false); } cBytesCursor lCursor = new cBytesCursor(pValue); if (!lCursor.GetRFC822MsgId(out var lMsgId) || !lCursor.Position.AtEnd) { rMsgId = null; return(false); } rMsgId = new cHeaderFieldMsgId(pName, new cBytes(pValue), lMsgId); return(true); }
/// <summary> /// Tries to parse a string as a URI. /// </summary> /// <param name="pURI"></param> /// <param name="rURI"></param> /// <returns></returns> public static bool TryParse(string pURI, out cURI rURI) { if (string.IsNullOrWhiteSpace(pURI)) { rURI = null; return(false); } var lCursor = new cBytesCursor(pURI); if (!cURIParts.Process(lCursor, out var lParts, cTrace.cContext.None) || !lCursor.Position.AtEnd) { rURI = null; return(false); } ; rURI = new cURI(pURI, lParts); return(true); }
public bool Process(cBytesCursor pCursor, out cResponseData rResponseData, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cResponseDataParserSelect), nameof(Process)); if (pCursor.SkipBytes(kFlagsSpace)) { if (pCursor.GetFlags(out var lRawFlags) && pCursor.Position.AtEnd && cFetchableFlags.TryConstruct(lRawFlags, out var lFlags)) { rResponseData = new cResponseDataFlags(lFlags); } else { lContext.TraceWarning("likely malformed flags response"); rResponseData = null; } return(true); }
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 override eProcessDataResult ProcessData(cBytesCursor pCursor, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cIdDataProcessor), nameof(ProcessData)); if (pCursor.SkipBytes(kIdSpace)) { if (ZGetId(pCursor, out var lServerId, lContext) && pCursor.Position.AtEnd) { lContext.TraceVerbose("got id: {0}", lServerId); mServerId = lServerId; mSynchroniser.InvokePropertyChanged(nameof(cIMAPClient.ServerId), lContext); return(eProcessDataResult.processed); } lContext.TraceWarning("likely malformed id response"); } return(eProcessDataResult.notprocessed); }
internal static bool TryConstruct(IList <byte> pValue, out cHeaderFieldImportance rImportance) { if (pValue == null) { rImportance = null; return(false); } eImportance lImportance; cBytesCursor lCursor = new cBytesCursor(pValue); lCursor.SkipRFC822CFWS(); if (lCursor.SkipBytes(kLow)) { lImportance = eImportance.low; } else if (lCursor.SkipBytes(kNormal)) { lImportance = eImportance.normal; } else if (lCursor.SkipBytes(kHigh)) { lImportance = eImportance.high; } else { rImportance = null; return(false); } lCursor.SkipRFC822CFWS(); if (lCursor.Position.AtEnd) { rImportance = new cHeaderFieldImportance(new cBytes(pValue), lImportance); return(true); } rImportance = null; return(false); }
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); }
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); }
private bool ZBackgroundTaskProcessCommandCompletion(cBytesCursor pCursor, cCommand pCommand, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZBackgroundTaskProcessCommandCompletion), pCommand); var lResult = ZProcessCommandCompletionResponse(pCursor, pCommand.Tag, pCommand.IsAuthentication, pCommand.Hook, lContext); if (lResult == null) { return(false); } if (pCommand.UIDValidity != null && pCommand.UIDValidity != mMailboxCache?.SelectedMailboxDetails?.MessageCache.UIDValidity) { pCommand.SetException(new cUIDValidityException(lContext), lContext); } else { pCommand.SetResult(lResult, lContext); } return(true); }