// Token: 0x060004A2 RID: 1186 RVA: 0x0001A708 File Offset: 0x00018908 public byte[] GetSz(uint mask) { if (mask == 4026531840U) { return(this.GetSz()); } int count = this.Count; if (count == 0) { return(null); } if (count != 1) { byte[] array = new byte[this.GetLength(mask)]; int num = 0; for (int i = 0; i < count; i++) { MimeString mimeString = this[i]; if ((mimeString.Mask & mask) != 0U) { num += mimeString.CopyTo(array, num); } } return(array); } if ((this.first.Mask & mask) == 0U) { return(MimeString.EmptyByteArray); } return(this.first.GetSz()); }
// Token: 0x06000339 RID: 825 RVA: 0x000125A8 File Offset: 0x000107A8 public void SetContentType(MajorContentType contentType, MimeString boundaryValue) { if (contentType == MajorContentType.Multipart) { int srcOffset; int num; byte[] data = boundaryValue.GetData(out srcOffset, out num); int num2 = MimeString.TwoDashes.Length + num + MimeString.TwoDashes.Length; byte[] array = new byte[num2]; int num3 = MimeString.TwoDashes.Length; Buffer.BlockCopy(MimeString.TwoDashes, 0, array, 0, num3); Buffer.BlockCopy(data, srcOffset, array, num3, num); num3 += num; this.boundaryCrc = ByteString.ComputeCrc(array, 0, num3); Buffer.BlockCopy(MimeString.TwoDashes, 0, array, num3, MimeString.TwoDashes.Length); num3 += MimeString.TwoDashes.Length; this.endBoundaryCrc = ByteString.ComputeCrc(array, 0, num3); this.boundaryValue = new MimeString(array, 0, num3); } else { this.boundaryValue = default(MimeString); this.boundaryCrc = 0U; this.endBoundaryCrc = 0U; } this.contentType = contentType; }
internal override void AppendLine(MimeString line, bool markDirty) { if (this.parsed) { this.Reset(); } base.AppendLine(line, markDirty); }
// Token: 0x06000320 RID: 800 RVA: 0x0001172E File Offset: 0x0000F92E public void SetContentType(MajorContentType contentType, MimeString boundaryValue) { this.currentLevel.SetContentType(contentType, boundaryValue); if (contentType != MajorContentType.Multipart) { this.nextBoundaryLevel = -1; } }
// Token: 0x060001DD RID: 477 RVA: 0x000085B4 File Offset: 0x000067B4 internal override void ParseValue(ValueParser parser, bool storeValue) { MimeStringList empty = MimeStringList.Empty; parser.ParseCFWS(false, ref empty, true); MimeString mimeString = parser.ParseToken(); MimeString mimeString2 = MimeString.Empty; parser.ParseCFWS(false, ref empty, true); byte b = parser.ParseGet(); if (b == 47) { parser.ParseCFWS(false, ref empty, true); mimeString2 = parser.ParseToken(); } else if (b != 0) { parser.ParseUnget(); } if (storeValue) { if (mimeString.Length == 0) { this.type = "text"; } else { this.type = Header.NormalizeString(mimeString.Data, mimeString.Offset, mimeString.Length, false); } if (mimeString2.Length == 0) { if (this.type == "multipart") { this.subType = "mixed"; } else if (this.type == "text") { this.subType = "plain"; } else { this.type = "application"; this.subType = "octet-stream"; } } else { this.subType = Header.NormalizeString(mimeString2.Data, mimeString2.Offset, mimeString2.Length, false); } this.value = ContentTypeHeader.ComposeContentTypeValue(this.type, this.subType); } if (this.type == "multipart") { this.handleISO2022 = false; } }
internal bool MergeIfAdjacent(MimeString refString) { if (this.data == refString.data && this.offset + this.Length == refString.offset && this.Mask == refString.Mask) { this.count += (uint)refString.Length; return(true); } return(false); }
internal virtual void AppendLine(MimeString line, bool markDirty) { this.RawValueAboutToChange(); this.lines.Append(line); if (markDirty) { this.SetDirty(); } }
// Token: 0x060004B1 RID: 1201 RVA: 0x0001AA24 File Offset: 0x00018C24 public bool StrMergeIfAdjacent(MimeString refLine) { MimeString str = this.Str; if (!str.MergeIfAdjacent(refLine)) { return(false); } this.Str = str; return(true); }
// Token: 0x060001A0 RID: 416 RVA: 0x00007640 File Offset: 0x00005840 internal bool IsQuotingRequired(MimeStringList displayNameFragments, bool allowUTF8) { for (int num = 0; num != displayNameFragments.Count; num++) { MimeString mimeStr = displayNameFragments[num]; if ((mimeStr.Mask & 4026531839U) != 0U && this.IsQuotingRequired(mimeStr, allowUTF8)) { return(true); } } return(false); }
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; } }
public static bool IsPureASCII(MimeString str) { bool result = true; for (int i = 0; i < str.Length; i++) { byte b = str[i]; if (b >= 128) { result = false; break; } } return(result); }
public static bool IsPureASCII(MimeStringList str) { bool result = true; for (int i = 0; i < str.Count; i++) { MimeString str2 = str[i]; if (!MimeString.IsPureASCII(str2)) { result = false; break; } } return(result); }
// Token: 0x0600019F RID: 415 RVA: 0x00007578 File Offset: 0x00005778 private bool IsQuotingRequired(MimeString mimeStr, bool allowUTF8) { AddressItem.WriteState writeState = AddressItem.WriteState.Begin; MimeString mimeString = new MimeString(AddressItem.WordBreakBytes, 0, AddressItem.WordBreakBytes.Length); int num; int num2; byte[] data = mimeStr.GetData(out num, out num2); while (num2 != 0) { switch (writeState) { case AddressItem.WriteState.Begin: { int num3 = 0; int num4 = MimeScan.FindEndOf(MimeScan.Token.Atom, data, num, num2, out num3, allowUTF8); if (num4 == 0) { if (num2 <= 3 || num != 0 || !mimeString.HasPrefixEq(data, 0, 3)) { return(true); } num += 3; num2 -= 3; writeState = AddressItem.WriteState.Begin; } else { num += num4; num2 -= num4; writeState = AddressItem.WriteState.Atom; } break; } case AddressItem.WriteState.Atom: if ((num2 < 2 || data[num] != 32) && (num2 < 1 || data[num] != 46)) { return(true); } num++; num2--; writeState = AddressItem.WriteState.Begin; break; } } return(false); }
// Token: 0x06000325 RID: 805 RVA: 0x00011B14 File Offset: 0x0000FD14 private static bool IsUUEncodeBegin(byte[] data, int line, int nextNL) { MimeString mimeString = new MimeString(data, line, nextNL - line); if (mimeString.Length < 13 || !mimeString.HasPrefixEq(MimeParser.UUBegin, 0, 6)) { return(false); } int num = 6; while (num < 10 && 48 <= mimeString[num] && 55 >= mimeString[num]) { num++; } return(num != 6 && 32 == mimeString[num]); }
internal static MimeStringList MergeLines(MimeStringList lines) { if (lines.Length != 0) { byte[] array = new byte[lines.Length]; int num = 0; for (int i = 0; i < lines.Count; i++) { MimeString mimeString = lines[i]; mimeString.CopyTo(array, num); num += mimeString.Length; } MimeStringList result = new MimeStringList(array); return(result); } return(lines); }
internal override void ParseValue(ValueParser parser, bool storeValue) { MimeStringList mimeStringList = default(MimeStringList); parser.ParseCFWS(false, ref mimeStringList, true); MimeString mimeString = parser.ParseToken(); if (storeValue) { if (mimeString.Length == 0) { this.disp = string.Empty; return; } this.disp = Header.NormalizeString(mimeString.Data, mimeString.Offset, mimeString.Length, false); } }
// Token: 0x0600049E RID: 1182 RVA: 0x0001A514 File Offset: 0x00018714 public void TakeOverAppend(ref MimeStringList list, uint mask) { if (this.Count == 0 && mask == 4026531840U) { this.TakeOver(ref list, mask); return; } for (int i = 0; i < list.Count; i++) { MimeString refLine = list[i]; if (mask == 4026531840U || (refLine.Mask & mask) != 0U) { this.AppendFragment(refLine); } } list.Reset(); }
// Token: 0x060004A0 RID: 1184 RVA: 0x0001A664 File Offset: 0x00018864 public int GetLength(uint mask) { if (mask == 4026531840U) { return(this.Length); } int num = 0; for (int i = 0; i < this.Count; i++) { MimeString mimeString = this[i]; if ((mimeString.Mask & mask) != 0U) { num += mimeString.Length; } } return(num); }
// Token: 0x060004A4 RID: 1188 RVA: 0x0001A7C4 File Offset: 0x000189C4 public override string ToString() { int count = this.Count; if (count <= 1) { return(this.first.ToString()); } StringBuilder stringBuilder = ScratchPad.GetStringBuilder(this.Length); for (int i = 0; i < count; i++) { MimeString mimeString = this[i]; string value = ByteString.BytesToString(mimeString.Data, mimeString.Offset, mimeString.Length, true); stringBuilder.Append(value); } ScratchPad.ReleaseStringBuilder(); return(stringBuilder.ToString()); }
// Token: 0x0600049F RID: 1183 RVA: 0x0001A574 File Offset: 0x00018774 public void AppendFragment(MimeString refLine) { int num = this.Count; if (num != 0) { num--; if (num == 0) { if (this.first.MergeIfAdjacent(refLine)) { if (this.overflow != null) { MimeStringList.ListEntry[] array = this.overflow; int num2 = 0; array[num2].HeaderTotalLength = array[num2].HeaderTotalLength + refLine.Length; } return; } } else if (num < 4096) { if (this.overflow[num].StrMergeIfAdjacent(refLine)) { MimeStringList.ListEntry[] array2 = this.overflow; int num3 = 0; array2[num3].HeaderTotalLength = array2[num3].HeaderTotalLength + refLine.Length; return; } } else if (this.overflow[4096 + num / 4096 - 1].Secondary[num % 4096].MergeIfAdjacent(refLine)) { MimeStringList.ListEntry[] array3 = this.overflow; int num4 = 0; array3[num4].HeaderTotalLength = array3[num4].HeaderTotalLength + refLine.Length; return; } } this.Append(refLine); }
public ValueIterator(MimeStringList lines, uint linesMask) { this.lines = lines; this.linesMask = linesMask; this.lineStart = (this.lineEnd = (this.currentLine = (this.currentOffset = 0))); this.lineBytes = null; this.endLine = this.lines.Count; this.endOffset = 0; while (this.currentLine != this.endLine) { MimeString mimeString = this.lines[this.currentLine]; if ((mimeString.Mask & this.linesMask) != 0U) { int num; this.lineBytes = mimeString.GetData(out this.lineStart, out num); this.lineEnd = this.lineStart + num; this.currentOffset = this.lineStart; return; } this.currentLine++; } }
private ReceivedHeader.ParseState StateFromToken(MimeString token) { uint num = token.ComputeCrcI(); if (num <= 2556329580U) { if (num == 271896810U) { return(ReceivedHeader.ParseState.OptInfo); } if (num == 2115158205U) { return(ReceivedHeader.ParseState.Domain); } if (num == 2556329580U) { return(ReceivedHeader.ParseState.Domain); } } else { if (num == 3117694226U) { return(ReceivedHeader.ParseState.OptInfo); } if (num == 3740702146U) { return(ReceivedHeader.ParseState.OptInfo); } if (num == 4276123055U) { return(ReceivedHeader.ParseState.OptInfo); } } return(ReceivedHeader.ParseState.None); }
// 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); }
// Token: 0x0600049A RID: 1178 RVA: 0x0001A2AC File Offset: 0x000184AC public void Append(MimeString value) { if (value.Length == 0) { return; } int count = this.Count; if (count == 0) { this.first = value; if (this.overflow != null) { MimeStringList.ListEntry[] array = this.overflow; int num = 0; array[num].HeaderCount = array[num].HeaderCount + 1; MimeStringList.ListEntry[] array2 = this.overflow; int num2 = 0; array2[num2].HeaderTotalLength = array2[num2].HeaderTotalLength + value.Length; return; } } else { if (count < 4096) { if (this.overflow == null) { this.overflow = new MimeStringList.ListEntry[8]; this.overflow[0].HeaderCount = 1; this.overflow[0].HeaderTotalLength = this.first.Length; } else if (count == this.overflow.Length) { int num3 = count * 2; if (num3 >= 4096) { num3 = 4128; } MimeStringList.ListEntry[] destinationArray = new MimeStringList.ListEntry[num3]; Array.Copy(this.overflow, 0, destinationArray, 0, this.overflow.Length); this.overflow = destinationArray; } this.overflow[count].Str = value; MimeStringList.ListEntry[] array3 = this.overflow; int num4 = 0; array3[num4].HeaderCount = array3[num4].HeaderCount + 1; MimeStringList.ListEntry[] array4 = this.overflow; int num5 = 0; array4[num5].HeaderTotalLength = array4[num5].HeaderTotalLength + value.Length; return; } int num6 = 4096 + count / 4096 - 1; int num7 = count % 4096; if (num6 >= this.overflow.Length) { throw new MimeException("MIME is too complex (header value is too long)"); } if (this.overflow[num6].Secondary == null) { this.overflow[num6].Secondary = new MimeString[4096]; } this.overflow[num6].Secondary[num7] = value; MimeStringList.ListEntry[] array5 = this.overflow; int num8 = 0; array5[num8].HeaderCount = array5[num8].HeaderCount + 1; MimeStringList.ListEntry[] array6 = this.overflow; int num9 = 0; array6[num9].HeaderTotalLength = array6[num9].HeaderTotalLength + value.Length; } }
internal void AppendLine(MimeString line) { this.AppendLine(line, true); }
internal static long QuoteAndFold(Stream stream, MimeStringList fragments, uint inputMask, bool quoteOutput, bool addSpaceAtStart, bool allowUTF8, int lastLineReserve, ref MimeStringLength currentLineLength, ref byte[] scratchBuffer) { long num = 0L; Header.LineBuffer lineBuffer = default(Header.LineBuffer); lineBuffer.Length = new MimeStringLength(0); lineBuffer.LengthTillLastLWSP = new MimeStringLength(-1); if (scratchBuffer == null || scratchBuffer.Length < 998) { scratchBuffer = new byte[998]; } lineBuffer.Bytes = scratchBuffer; MimeScan.Token token = quoteOutput ? (MimeScan.Token.Spec | MimeScan.Token.Fwsp) : MimeScan.Token.Fwsp; bool flag = false; if (addSpaceAtStart && currentLineLength.InBytes != 0) { num += Header.WriteToken(Header.Space, 0, new MimeStringLength(1), stream, ref currentLineLength, ref lineBuffer, ref flag, allowUTF8); flag = true; } if (quoteOutput) { num += Header.WriteToken(Header.DoubleQuote, 0, new MimeStringLength(1), stream, ref currentLineLength, ref lineBuffer, ref flag, allowUTF8); } for (int i = 0; i < fragments.Count; i++) { MimeString mimeString = fragments[i]; int num2 = 0; int num3 = 0; byte[] data = mimeString.GetData(out num2, out num3); if ((mimeString.Mask & inputMask) != 0U) { do { int valueInChars = 0; int num4 = MimeScan.FindNextOf(token, data, num2, num3, out valueInChars, allowUTF8); if (num4 > 0) { num += Header.WriteToken(data, num2, new MimeStringLength(valueInChars, num4), stream, ref currentLineLength, ref lineBuffer, ref flag, allowUTF8); num2 += num4; num3 -= num4; } if (num3 != 0) { byte b = data[num2]; if ((b == 34 || b == 92) && (mimeString.Mask & 3758096383U) != 0U) { num += Header.WriteToken(new byte[] { 92, data[num2] }, 0, new MimeStringLength(2), stream, ref currentLineLength, ref lineBuffer, ref flag, allowUTF8); num2++; num3--; } else { num += Header.WriteToken(new byte[] { data[num2] }, 0, new MimeStringLength(1), stream, ref currentLineLength, ref lineBuffer, ref flag, allowUTF8); num2++; num3--; } } }while (num3 != 0); } } if (quoteOutput) { num += Header.WriteToken(Header.DoubleQuote, 0, new MimeStringLength(1), stream, ref currentLineLength, ref lineBuffer, ref flag, allowUTF8); } if (lastLineReserve > 0) { num += Header.WriteToken(null, 0, new MimeStringLength(lastLineReserve), stream, ref currentLineLength, ref lineBuffer, ref flag, allowUTF8); } if (lineBuffer.Length.InBytes > 0) { stream.Write(lineBuffer.Bytes, 0, lineBuffer.Length.InBytes); num += (long)lineBuffer.Length.InBytes; currentLineLength.IncrementBy(lineBuffer.Length); } return(num); }
// Token: 0x06000495 RID: 1173 RVA: 0x0001A149 File Offset: 0x00018349 public MimeStringList(MimeString str) { this.first = str; this.overflow = null; }
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); }
private static void ParseValue(MimeStringList list, out DateTime utcDateTime, out TimeSpan timeZoneOffset) { MimeStringList mimeStringList = default(MimeStringList); ValueParser valueParser = new ValueParser(list, false); DateHeader.ParseStage parseStage = DateHeader.ParseStage.DayOfWeek; int[] array = new int[8]; byte b = 32; while (parseStage != DateHeader.ParseStage.Count) { valueParser.ParseCFWS(false, ref mimeStringList, true); byte b2 = valueParser.ParseGet(); if (b2 == 0) { break; } if (!MimeScan.IsToken(b2) || b2 == 45 || b2 == 43) { b = b2; valueParser.ParseCFWS(false, ref mimeStringList, true); } else { if (MimeScan.IsDigit(b2)) { if (parseStage == DateHeader.ParseStage.DayOfWeek) { parseStage = DateHeader.ParseStage.DayOfMonth; } if (parseStage == DateHeader.ParseStage.Second && b != 58) { parseStage = DateHeader.ParseStage.Zone; } int num = 0; do { num++; array[(int)parseStage] *= 10; array[(int)parseStage] += (int)(b2 - 48); b2 = valueParser.ParseGet(); }while (b2 != 0 && MimeScan.IsDigit(b2)); if (b2 != 0) { valueParser.ParseUnget(); } if (parseStage == DateHeader.ParseStage.Year && num <= 2) { array[(int)parseStage] += ((array[(int)parseStage] < 30) ? 2000 : 1900); } if (parseStage == DateHeader.ParseStage.Zone && num <= 2) { array[(int)parseStage] *= 100; } if (parseStage == DateHeader.ParseStage.Zone && b == 45) { array[(int)parseStage] = -array[(int)parseStage]; } parseStage++; } else if (MimeScan.IsAlpha(b2)) { valueParser.ParseUnget(); MimeString mimeString = valueParser.ParseToken(MimeScan.Token.Alpha); if (parseStage == DateHeader.ParseStage.DayOfWeek) { parseStage = DateHeader.ParseStage.DayOfMonth; } else if (parseStage == DateHeader.ParseStage.Month) { array[(int)parseStage] = DateHeader.MapMonthToInt(mimeString.Data, mimeString.Offset, mimeString.Length); parseStage = DateHeader.ParseStage.Year; } else if (parseStage >= DateHeader.ParseStage.Second) { if (mimeString.Length == 2 && 65 == DateHeader.MakeUpper(mimeString[0]) && 77 == DateHeader.MakeUpper(mimeString[1])) { if (array[4] == 12) { array[4] = 0; } parseStage = DateHeader.ParseStage.Zone; } else if (mimeString.Length == 2 && 80 == DateHeader.MakeUpper(mimeString[0]) && 77 == DateHeader.MakeUpper(mimeString[1])) { if (array[4] < 12) { array[4] += 12; } parseStage = DateHeader.ParseStage.Zone; } else { array[7] = (int)DateHeader.MapZoneToInt(mimeString.Data, mimeString.Offset, mimeString.Length); parseStage = DateHeader.ParseStage.Count; } } } b = 32; } } if (parseStage > DateHeader.ParseStage.Year) { int num2 = array[3]; int num3 = array[2]; int num4 = array[1]; int num5 = array[4]; int num6 = array[5]; int num7 = array[6]; if (num5 == 23 && num6 == 59 && num7 == 60) { num7 = 59; } if (num2 >= 1900 && num2 <= 9999 && num3 >= 1 && num3 <= 12 && num4 >= 1 && num4 <= DateTime.DaysInMonth(num2, num3) && num5 >= 0 && num5 < 24 && num6 >= 0 && num6 < 60 && num7 >= 0 && num7 < 60) { try { utcDateTime = new DateTime(num2, num3, num4, num5, num6, num7, 0, DateTimeKind.Utc); goto IL_319; } catch (ArgumentException) { utcDateTime = DateHeader.minDateTime; goto IL_319; } } utcDateTime = DateHeader.minDateTime; } else { utcDateTime = DateHeader.minDateTime; } IL_319: if (parseStage != DateHeader.ParseStage.Count || !(utcDateTime > DateHeader.minDateTime)) { timeZoneOffset = TimeSpan.Zero; return; } int num8 = array[7] / 100; int num9 = array[7] % 100; if (num8 > 99 || num8 < -99) { num8 = 0; num9 = 0; } if (num9 > 59 || num9 < -59) { num9 = 0; } timeZoneOffset = new TimeSpan(num8, num9, 0); if (utcDateTime.Ticks >= timeZoneOffset.Ticks && DateTime.MaxValue.Ticks >= utcDateTime.Ticks - timeZoneOffset.Ticks) { utcDateTime -= timeZoneOffset; return; } utcDateTime = DateHeader.minDateTime; timeZoneOffset = TimeSpan.Zero; }
public static int ParseToken(MimeString str, out int characterCount, bool allowUTF8) { return(MimeScan.FindEndOf(MimeScan.Token.Token, str.Data, str.Offset, str.Length, out characterCount, allowUTF8)); }