public MimeString ParseToken(MimeScan.Token token) { MimeStringList mimeStringList = default(MimeStringList); while (this.position != this.end || this.ParseNextLine()) { int num = 0; int num2 = MimeScan.FindEndOf(token, this.bytes, this.position, this.end - this.position, out num, this.allowUTF8); if (num2 == 0) { break; } mimeStringList.AppendFragment(new MimeString(this.bytes, this.position, num2)); this.position += num2; } if (mimeStringList.Count == 0) { return(default(MimeString)); } if (mimeStringList.Count == 1) { return(mimeStringList[0]); } byte[] sz = mimeStringList.GetSz(); return(new MimeString(sz, 0, sz.Length)); }
// Token: 0x06000542 RID: 1346 RVA: 0x0001CD50 File Offset: 0x0001AF50 internal static void ConvertDisplayNameBack(AddressItem addressItem, MimeStringList displayNameFragments, bool allowUTF8) { byte[] sz = displayNameFragments.GetSz(4026531839U); if (sz == null) { addressItem.DecodedDisplayName = null; return; } string decodedDisplayName = ByteString.BytesToString(sz, allowUTF8); addressItem.DecodedDisplayName = decodedDisplayName; }
private void FinishClause(ref MimeString param, ref MimeStringList value, bool allowUTF8) { if (param.Length != 0) { byte[] sz = value.GetSz(); string text = (sz == null) ? null : ByteString.BytesToString(sz, allowUTF8); uint num = param.ComputeCrcI(); if (num <= 2556329580U) { if (num != 271896810U) { if (num != 2115158205U) { if (num == 2556329580U) { this.fromValue = text; } } else { this.byValue = text; } } else { this.forValue = text; } } else if (num != 3117694226U) { if (num != 3740702146U) { if (num == 4276123055U) { this.idValue = text; } } else { this.viaValue = text; } } else { this.withValue = text; } value.Reset(); param = MimeString.Empty; } }
// Token: 0x06000302 RID: 770 RVA: 0x00010A58 File Offset: 0x0000EC58 internal override long WriteTo(Stream stream, EncodingOptions encodingOptions, MimeOutputFilter filter, ref MimeStringLength currentLineLength, ref byte[] scratchBuffer) { MimeStringList fragments = this.valueFragments; long num = 0L; if (this.valueFragments.Length == 0 && this.decodedValue != null && 0 < this.decodedValue.Length) { fragments = this.EncodeValue(this.decodedValue, encodingOptions); this.valueFragments = fragments; } else if ((byte)(EncodingFlags.ForceReencode & encodingOptions.EncodingFlags) != 0 && 0 >= this.segmentNumber) { fragments = this.EncodeValue(this.Value, encodingOptions); } bool flag = false; if (this.IsQuotingReqired() || fragments.Length == 0) { flag = true; } else { for (int i = 0; i < fragments.Count; i++) { MimeString str = fragments[i]; int num2 = 0; int num3 = ValueParser.ParseToken(str, out num2, encodingOptions.AllowUTF8); if (268435456U != str.Mask && str.Length != num3) { flag = true; break; } } } MimeNode mimeNode = null; if (this.segmentNumber == 0) { mimeNode = base.FirstChild; while (mimeNode != null && !(mimeNode is MimeParameter)) { mimeNode = mimeNode.NextSibling; } } MimeString mimeString = ((this.segmentNumber == 0 && mimeNode != null) || 0 < this.segmentNumber) ? new MimeString(this.segmentNumber.ToString()) : default(MimeString); if (1 < currentLineLength.InChars) { int num4 = 1 + this.paramName.Length + 1; byte[] sz = fragments.GetSz(); int num5 = ByteString.BytesToCharCount(sz, encodingOptions.AllowUTF8); if (mimeString.Length != 0) { num4 += 1 + mimeString.Length; } if (this.valueEncoded) { num4++; } int num6 = num5; if (flag) { num6 += 2; } if (base.NextSibling != null) { if (num5 == 0) { num4++; } else { num6++; } } num6 += num4; if (currentLineLength.InChars + num6 > 78) { num += Header.WriteLineEnd(stream, ref currentLineLength); stream.Write(Header.LineStartWhitespace, 0, Header.LineStartWhitespace.Length); num += (long)Header.LineStartWhitespace.Length; currentLineLength.IncrementBy(Header.LineStartWhitespace.Length); } else { stream.Write(MimeString.Space, 0, MimeString.Space.Length); num += (long)MimeString.Space.Length; currentLineLength.IncrementBy(MimeString.Space.Length); } } int num7 = ByteString.StringToBytesCount(this.paramName, false); if (scratchBuffer == null || scratchBuffer.Length < num7) { scratchBuffer = new byte[Math.Max(998, num7)]; } int num8 = ByteString.StringToBytes(this.paramName, scratchBuffer, 0, false); stream.Write(scratchBuffer, 0, num8); num += (long)num8; currentLineLength.IncrementBy(this.paramName.Length, num8); if (mimeString.Length != 0) { stream.Write(MimeString.Asterisk, 0, MimeString.Asterisk.Length); num += (long)MimeString.Asterisk.Length; currentLineLength.IncrementBy(MimeString.Asterisk.Length); mimeString.WriteTo(stream); num += (long)mimeString.Length; currentLineLength.IncrementBy(mimeString.Length); } if (this.valueEncoded) { stream.Write(MimeString.Asterisk, 0, MimeString.Asterisk.Length); num += (long)MimeString.Asterisk.Length; currentLineLength.IncrementBy(MimeString.Asterisk.Length); } stream.Write(MimeString.EqualTo, 0, MimeString.EqualTo.Length); num += (long)MimeString.EqualTo.Length; currentLineLength.IncrementBy(MimeString.EqualTo.Length); int num9 = 0; if (base.NextSibling != null) { num9++; } num += Header.QuoteAndFold(stream, fragments, 4026531839U, flag, false, encodingOptions.AllowUTF8, num9, ref currentLineLength, ref scratchBuffer); int num10 = 0; while (mimeNode != null) { MimeParameter mimeParameter = mimeNode as MimeParameter; if (mimeParameter != null) { num10++; mimeParameter.segmentNumber = num10; stream.Write(MimeString.Semicolon, 0, MimeString.Semicolon.Length); num += (long)MimeString.Semicolon.Length; currentLineLength.IncrementBy(MimeString.Semicolon.Length); num += Header.WriteLineEnd(stream, ref currentLineLength); stream.Write(Header.LineStartWhitespace, 0, Header.LineStartWhitespace.Length); num += (long)Header.LineStartWhitespace.Length; currentLineLength.IncrementBy(Header.LineStartWhitespace.Length); num += mimeNode.WriteTo(stream, encodingOptions, null, ref currentLineLength, ref scratchBuffer); } mimeNode = mimeNode.NextSibling; } return(num); }
private void Parse() { this.Reset(); this.parsed = true; DecodingOptions headerDecodingOptions = base.GetHeaderDecodingOptions(); ValueParser valueParser = new ValueParser(base.Lines, headerDecodingOptions.AllowUTF8); MimeStringList mimeStringList = default(MimeStringList); MimeStringList mimeStringList2 = default(MimeStringList); MimeString mimeString = default(MimeString); MimeString mimeString2 = MimeString.Empty; ReceivedHeader.ParseState parseState = ReceivedHeader.ParseState.None; for (;;) { valueParser.ParseWhitespace(true, ref mimeStringList); byte b = valueParser.ParseGet(); if (b == 0) { break; } if (59 == b) { parseState = ReceivedHeader.ParseState.Date; } else if (40 == b && parseState == ReceivedHeader.ParseState.DomainValue) { parseState = ReceivedHeader.ParseState.DomainAddress; } else { valueParser.ParseUnget(); mimeString = valueParser.ParseToken(); if (mimeString.Length == 0) { valueParser.ParseGet(); mimeStringList2.TakeOverAppend(ref mimeStringList); valueParser.ParseAppendLastByte(ref mimeStringList2); continue; } ReceivedHeader.ParseState parseState2 = this.StateFromToken(mimeString); if (ReceivedHeader.ParseState.None != parseState2) { parseState = parseState2; } } switch (parseState) { case ReceivedHeader.ParseState.Domain: case ReceivedHeader.ParseState.OptInfo: if (mimeString2.Length != 0) { this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8); } else { mimeStringList2.Reset(); } mimeString2 = mimeString; valueParser.ParseWhitespace(false, ref mimeStringList); mimeStringList.Reset(); parseState++; break; case ReceivedHeader.ParseState.DomainValue: mimeStringList2.TakeOverAppend(ref mimeStringList); mimeStringList2.AppendFragment(mimeString); break; case ReceivedHeader.ParseState.DomainAddress: { bool flag = mimeString2.CompareEqI(ReceivedHeader.ParamFrom); this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8); mimeStringList.Reset(); valueParser.ParseUnget(); valueParser.ParseComment(true, false, ref mimeStringList2, true); byte[] sz = mimeStringList2.GetSz(); string text = (sz == null) ? null : ByteString.BytesToString(sz, headerDecodingOptions.AllowUTF8); if (flag) { this.fromTcpInfoValue = text; } else { this.byTcpInfoValue = text; } mimeStringList2.Reset(); parseState = ReceivedHeader.ParseState.None; break; } case ReceivedHeader.ParseState.OptInfoValue: mimeStringList2.TakeOverAppend(ref mimeStringList); mimeStringList2.AppendFragment(mimeString); break; case ReceivedHeader.ParseState.Date: { this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8); mimeStringList.Reset(); valueParser.ParseWhitespace(false, ref mimeStringList); valueParser.ParseToEnd(ref mimeStringList2); byte[] sz2 = mimeStringList2.GetSz(); this.dateValue = ((sz2 == null) ? null : ByteString.BytesToString(sz2, false)); break; } case ReceivedHeader.ParseState.None: mimeStringList2.Reset(); break; } } this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8); }