Ejemplo n.º 1
0
        internal override long WriteTo(Stream stream, EncodingOptions encodingOptions, MimeOutputFilter filter, ref MimeStringLength currentLineLength, ref byte[] scratchBuffer)
        {
            long num = base.WriteName(stream, ref scratchBuffer);

            currentLineLength.IncrementBy((int)num);
            if (!base.IsDirty && base.RawLength != 0 && base.IsProtected)
            {
                long num2 = Header.WriteLines(base.Lines, stream);
                num += num2;
                currentLineLength.SetAs(0);
                return(num);
            }
            if (!this.parsed)
            {
                this.Parse();
            }
            num += this.WriteValue(stream, encodingOptions, filter, ref currentLineLength, ref scratchBuffer);
            for (MimeNode mimeNode = base.FirstChild; mimeNode != null; mimeNode = mimeNode.NextSibling)
            {
                stream.Write(MimeString.Semicolon, 0, MimeString.Semicolon.Length);
                num += (long)MimeString.Semicolon.Length;
                currentLineLength.IncrementBy(MimeString.Semicolon.Length);
                num += mimeNode.WriteTo(stream, encodingOptions, filter, ref currentLineLength, ref scratchBuffer);
            }
            return(num + Header.WriteLineEnd(stream, ref currentLineLength));
        }
Ejemplo n.º 2
0
        // Token: 0x06000238 RID: 568 RVA: 0x00009D80 File Offset: 0x00007F80
        internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
        {
            Header header = newChild as Header;

            if (header == null)
            {
                throw new ArgumentException(Strings.NewChildNotMimeHeader, "newChild");
            }
            HeaderId headerId = header.HeaderId;

            if (Header.IsRestrictedHeader(headerId))
            {
                if (this.headerMap[(int)headerId] != 0)
                {
                    Header header2 = this.FindFirst(headerId);
                    if (header2 == refChild)
                    {
                        refChild = header2.PreviousSibling;
                    }
                    base.InternalRemoveChild(header2);
                }
                byte[]   array     = this.headerMap;
                HeaderId headerId2 = headerId;
                array[(int)headerId2] = array[(int)headerId2] + 1;
            }
            else if (this.headerMap[(int)headerId] != 255)
            {
                byte[]   array2    = this.headerMap;
                HeaderId headerId3 = headerId;
                array2[(int)headerId3] = array2[(int)headerId3] + 1;
            }
            return(refChild);
        }
 // Token: 0x06000304 RID: 772 RVA: 0x00010EDF File Offset: 0x0000F0DF
 internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
 {
     if (this.allowAppend)
     {
         return(refChild);
     }
     throw new NotSupportedException(Strings.ParametersCannotHaveChildNodes);
 }
Ejemplo n.º 4
0
 internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
 {
     if (!(newChild is MimeRecipient))
     {
         throw new ArgumentException(Strings.NewChildIsNotARecipient);
     }
     return(refChild);
 }
Ejemplo n.º 5
0
 // Token: 0x0600018F RID: 399 RVA: 0x00007271 File Offset: 0x00005471
 internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
 {
     if (!(newChild is MimeRecipient) && !(newChild is MimeGroup))
     {
         throw new ArgumentException(Strings.NewChildNotRecipientOrGroup, "newChild");
     }
     return(refChild);
 }
Ejemplo n.º 6
0
        internal void WriteMimeNode(MimeNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            Header header = node as Header;

            if (header != null)
            {
                this.WriteHeader(header);
                this.FlushHeader();
                return;
            }
            MimePart mimePart = node as MimePart;

            if (mimePart != null)
            {
                this.StartPart();
                mimePart.WriteTo(this.shimStream, this.encodingOptions);
                this.EndPart();
                return;
            }
            HeaderList headerList = node as HeaderList;

            if (headerList != null)
            {
                foreach (Header header2 in headerList)
                {
                    this.WriteHeader(header);
                }
                this.FlushHeader();
                return;
            }
            node = node.Clone();
            MimeRecipient mimeRecipient = node as MimeRecipient;

            if (mimeRecipient != null)
            {
                this.WriteRecipient(mimeRecipient);
                return;
            }
            MimeParameter mimeParameter = node as MimeParameter;

            if (mimeParameter != null)
            {
                this.WriteParameter(mimeParameter);
                return;
            }
            MimeGroup mimeGroup = node as MimeGroup;

            if (mimeGroup != null)
            {
                this.StartGroup(mimeGroup);
                this.EndGroup();
            }
        }
Ejemplo n.º 7
0
        // Token: 0x06000239 RID: 569 RVA: 0x00009E24 File Offset: 0x00008024
        internal override void ChildRemoved(MimeNode oldChild)
        {
            Header   header   = oldChild as Header;
            HeaderId headerId = header.HeaderId;

            if (this.headerMap[(int)headerId] != 255)
            {
                byte[]   array     = this.headerMap;
                HeaderId headerId2 = headerId;
                array[(int)headerId2] = array[(int)headerId2] - 1;
            }
        }
Ejemplo n.º 8
0
        internal override MimeNode ParseNextChild()
        {
            if (this.parsed)
            {
                return(null);
            }
            MimeNode internalLastChild = base.InternalLastChild;

            this.Parse();
            if (internalLastChild != null)
            {
                return(internalLastChild.NextSibling);
            }
            return(base.FirstChild);
        }
        // Token: 0x06000303 RID: 771 RVA: 0x00010E84 File Offset: 0x0000F084
        internal override MimeNode ParseNextChild()
        {
            if (this.valueFragments.Length != 0 || this.decodedValue == null || this.decodedValue.Length == 0)
            {
                return(null);
            }
            MimeNode internalLastChild = base.InternalLastChild;

            if (internalLastChild != null)
            {
                return(null);
            }
            this.valueFragments = this.EncodeValue(this.decodedValue, base.GetDocumentEncodingOptions());
            return(base.FirstChild);
        }
Ejemplo n.º 10
0
        internal override MimeNode ParseNextChild()
        {
            MimeNode mimeNode = null;

            if (!this.parsed && base.Parent != null)
            {
                AddressHeader addressHeader = base.Parent as AddressHeader;
                if (addressHeader != null)
                {
                    mimeNode = addressHeader.ParseNextMailBox(true);
                }
            }
            this.parsed = (mimeNode == null);
            return(mimeNode);
        }
Ejemplo n.º 11
0
        // Token: 0x0600018B RID: 395 RVA: 0x00007074 File Offset: 0x00005274
        internal override long WriteTo(Stream stream, EncodingOptions encodingOptions, MimeOutputFilter filter, ref MimeStringLength currentLineLength, ref byte[] scratchBuffer)
        {
            long num = base.WriteName(stream, ref scratchBuffer);

            currentLineLength.IncrementBy((int)num);
            if (!base.IsDirty && base.RawLength != 0)
            {
                if (base.IsProtected)
                {
                    num += Header.WriteLines(base.Lines, stream);
                    currentLineLength.SetAs(0);
                    return(num);
                }
                if (base.InternalLastChild == null)
                {
                    bool flag = false;
                    if (!base.IsHeaderLineTooLong(num, out flag))
                    {
                        num += Header.WriteLines(base.Lines, stream);
                        currentLineLength.SetAs(0);
                        return(num);
                    }
                }
            }
            if (!this.parsed)
            {
                this.Parse();
            }
            MimeNode mimeNode = base.FirstChild;
            int      num2     = 0;

            while (mimeNode != null)
            {
                if (1 < ++num2)
                {
                    stream.Write(MimeString.Comma, 0, MimeString.Comma.Length);
                    num += (long)MimeString.Comma.Length;
                    currentLineLength.IncrementBy(MimeString.Comma.Length);
                }
                num     += mimeNode.WriteTo(stream, encodingOptions, filter, ref currentLineLength, ref scratchBuffer);
                mimeNode = mimeNode.NextSibling;
            }
            return(num + Header.WriteLineEnd(stream, ref currentLineLength));
        }
Ejemplo n.º 12
0
 public MimeParameter this[string name]
 {
     get
     {
         if (name == null)
         {
             throw new ArgumentNullException("name");
         }
         for (MimeNode mimeNode = base.FirstChild; mimeNode != null; mimeNode = mimeNode.NextSibling)
         {
             MimeParameter mimeParameter = mimeNode as MimeParameter;
             if (mimeParameter.IsName(name))
             {
                 return(mimeParameter);
             }
         }
         return(null);
     }
 }
Ejemplo n.º 13
0
        internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
        {
            MimeParameter mimeParameter = newChild as MimeParameter;

            if (mimeParameter == null)
            {
                throw new ArgumentException(Strings.NewChildNotMimeParameter, "newChild");
            }
            MimeParameter mimeParameter2 = this[mimeParameter.Name];

            if (mimeParameter2 != null)
            {
                if (mimeParameter2 == refChild)
                {
                    refChild = mimeParameter2.PreviousSibling;
                }
                base.InternalRemoveChild(mimeParameter2);
            }
            return(refChild);
        }
Ejemplo n.º 14
0
        internal override long WriteTo(Stream stream, EncodingOptions encodingOptions, MimeOutputFilter filter, ref MimeStringLength currentLineLength, ref byte[] scratchBuffer)
        {
            MimeNode       nextSibling        = base.NextSibling;
            MimeStringList displayNameToWrite = base.GetDisplayNameToWrite(encodingOptions);
            long           num = 0L;

            if (displayNameToWrite.GetLength(4026531839U) != 0)
            {
                int num2 = 1;
                if (base.FirstChild == null)
                {
                    num2++;
                }
                if (base.NextSibling != null)
                {
                    num2++;
                }
                num += Header.QuoteAndFold(stream, displayNameToWrite, 4026531839U, base.IsQuotingRequired(displayNameToWrite, encodingOptions.AllowUTF8), true, encodingOptions.AllowUTF8, num2, ref currentLineLength, ref scratchBuffer);
                stream.Write(MimeString.Colon, 0, MimeString.Colon.Length);
                num += (long)MimeString.Colon.Length;
                currentLineLength.IncrementBy(MimeString.Colon.Length);
            }
            MimeNode mimeNode = base.FirstChild;
            int      num3     = 0;

            while (mimeNode != null)
            {
                if (1 < ++num3)
                {
                    stream.Write(MimeString.Comma, 0, MimeString.Comma.Length);
                    num += (long)MimeString.Comma.Length;
                    currentLineLength.IncrementBy(MimeString.Comma.Length);
                }
                num     += mimeNode.WriteTo(stream, encodingOptions, filter, ref currentLineLength, ref scratchBuffer);
                mimeNode = mimeNode.NextSibling;
            }
            stream.Write(MimeString.Semicolon, 0, MimeString.Semicolon.Length);
            num += (long)MimeString.Semicolon.Length;
            currentLineLength.IncrementBy(MimeString.Semicolon.Length);
            return(num);
        }
Ejemplo n.º 15
0
        // Token: 0x0600018D RID: 397 RVA: 0x00007174 File Offset: 0x00005374
        internal override MimeNode ParseNextChild()
        {
            if (this.parsed)
            {
                return(null);
            }
            MimeNode internalLastChild = base.InternalLastChild;
            MimeNode mimeNode;

            if (internalLastChild is MimeGroup)
            {
                while (internalLastChild.ParseNextChild() != null)
                {
                }
                mimeNode = internalLastChild.InternalNextSibling;
            }
            else
            {
                mimeNode = this.ParseNextMailBox(false);
            }
            this.parsed = (mimeNode == null);
            return(mimeNode);
        }
Ejemplo n.º 16
0
        // Token: 0x06000237 RID: 567 RVA: 0x00009CEC File Offset: 0x00007EEC
        internal override long WriteTo(Stream stream, EncodingOptions encodingOptions, MimeOutputFilter filter, ref MimeStringLength currentLineLength, ref byte[] scratchBuffer)
        {
            MimePart.CountingWriteStream countingWriteStream  = null;
            MimePart.CountingWriteStream countingWriteStream2 = null;
            long num  = 0L;
            long num2 = 0L;

            if (filter != null)
            {
                countingWriteStream = (stream as MimePart.CountingWriteStream);
                if (countingWriteStream == null)
                {
                    countingWriteStream2 = new MimePart.CountingWriteStream(stream);
                    countingWriteStream  = countingWriteStream2;
                    stream = countingWriteStream;
                }
                num = countingWriteStream.Count;
            }
            for (MimeNode mimeNode = base.FirstChild; mimeNode != null; mimeNode = mimeNode.NextSibling)
            {
                if (filter == null || !filter.FilterHeader(mimeNode as Header, countingWriteStream))
                {
                    num2 += mimeNode.WriteTo(stream, encodingOptions, filter, ref currentLineLength, ref scratchBuffer);
                }
            }
            if (countingWriteStream != null)
            {
                num2 = countingWriteStream.Count - num;
                if (countingWriteStream2 != null)
                {
                    countingWriteStream2.Dispose();
                }
            }
            currentLineLength.SetAs(0);
            return(num2);
        }
Ejemplo n.º 17
0
 // Token: 0x06000227 RID: 551 RVA: 0x00009821 File Offset: 0x00007A21
 internal HeaderList(MimeNode parent) : base(parent)
 {
 }
Ejemplo n.º 18
0
 // Token: 0x06000543 RID: 1347 RVA: 0x0001CD84 File Offset: 0x0001AF84
 internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
 {
     throw new NotSupportedException(Strings.RecipientsCannotHaveChildNodes);
 }
Ejemplo n.º 19
0
        // Token: 0x0600030B RID: 779 RVA: 0x000112A8 File Offset: 0x0000F4A8
        private bool TryDecodeRfc2231(ref DecodingOptions decodingOptions, out DecodingResults decodingResults, out string value)
        {
            decodingResults = default(DecodingResults);
            decodingResults.EncodingScheme = EncodingScheme.Rfc2231;
            Charset charset = null;

            byte[] sz  = this.valueFragments.GetSz(4026531839U);
            int    num = 0;

            if (this.valueEncoded)
            {
                int num2 = (sz == null) ? -1 : ByteString.IndexOf(sz, 39, 0, sz.Length);
                if (-1 < num2 && num2 < sz.Length - 1)
                {
                    int num3 = ByteString.IndexOf(sz, 39, ++num2, sz.Length - num2);
                    if (-1 < num3)
                    {
                        decodingResults.CharsetName = ByteString.BytesToString(sz, 0, num2 - 1, false);
                        decodingResults.CultureName = ByteString.BytesToString(sz, num2, num3 - num2, false);
                        if (!Charset.TryGetCharset(decodingResults.CharsetName, out charset))
                        {
                            decodingResults.DecodingFailed = true;
                            return(this.FallBackIfRequired(sz, decodingOptions, out value));
                        }
                        num = num3 + 1;
                    }
                }
            }
            if (charset == null)
            {
                charset = decodingOptions.Charset;
                if (charset == null)
                {
                    charset = DecodingOptions.DefaultCharset;
                }
            }
            decodingResults.CharsetName = charset.Name;
            Encoding encoding;

            if (!charset.TryGetEncoding(out encoding))
            {
                decodingResults.DecodingFailed = true;
                return(this.FallBackIfRequired(sz, decodingOptions, out value));
            }
            int num4 = this.valueFragments.Length - num;

            for (MimeNode mimeNode = base.FirstChild; mimeNode != null; mimeNode = mimeNode.NextSibling)
            {
                MimeParameter mimeParameter = mimeNode as MimeParameter;
                if (mimeParameter != null)
                {
                    num4 += mimeParameter.RawLength;
                }
            }
            byte[] array = new byte[num4];
            int    num5  = 0;

            if (sz != null && num < sz.Length)
            {
                num5 += this.DecodeRfc2231Octets(this.valueEncoded, sz, num, array, 0);
            }
            for (MimeNode mimeNode = base.FirstChild; mimeNode != null; mimeNode = mimeNode.NextSibling)
            {
                MimeParameter mimeParameter2 = mimeNode as MimeParameter;
                if (mimeParameter2 != null)
                {
                    byte[] rawValue = mimeParameter2.RawValue;
                    if (rawValue != null)
                    {
                        num5 += this.DecodeRfc2231Octets(mimeParameter2.valueEncoded, mimeParameter2.RawValue, 0, array, num5);
                    }
                }
            }
            value = ((num5 != 0) ? encoding.GetString(array, 0, num5) : string.Empty);
            if ((DecodingFlags.AllowControlCharacters & decodingOptions.DecodingFlags) == DecodingFlags.None)
            {
                value = MimeParameter.CorrectValue(value);
            }
            return(true);
        }
Ejemplo n.º 20
0
 internal Enumerator(MimeNode node)
 {
     this.node    = node;
     this.current = default(T);
     this.next    = (this.node.FirstChild as T);
 }
Ejemplo n.º 21
0
 internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
 {
     throw new NotSupportedException(Strings.ChildrenCannotBeAddedToReceivedHeader);
 }
Ejemplo n.º 22
0
 internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
 {
     throw new NotSupportedException(Strings.CannotAddChildrenToMimeHeaderDate);
 }
Ejemplo n.º 23
0
        internal void ParseParameters(ref ValueParser parser, DecodingOptions decodingOptions, int countLimit, int bytesLimit)
        {
            MimeStringList mimeStringList  = default(MimeStringList);
            MimeStringList mimeStringList2 = default(MimeStringList);
            bool           flag            = false;
            int            num             = 0;
            bool           flag2           = DecodingFlags.None != (DecodingFlags.Rfc2231 & decodingOptions.DecodingFlags);

            for (;;)
            {
                parser.ParseCFWS(false, ref mimeStringList, this.handleISO2022);
                byte b = parser.ParseGet();
                if (b != 59)
                {
                    if (b == 0)
                    {
                        break;
                    }
                    parser.ParseUnget();
                    parser.ParseSkipToNextDelimiterByte(59);
                }
                else
                {
                    parser.ParseCFWS(false, ref mimeStringList, this.handleISO2022);
                    MimeString mimeString = parser.ParseToken();
                    if (mimeString.Length != 0 && mimeString.Length < 128)
                    {
                        parser.ParseCFWS(false, ref mimeStringList, this.handleISO2022);
                        b = parser.ParseGet();
                        if (b != 61)
                        {
                            if (b == 0)
                            {
                                return;
                            }
                            parser.ParseUnget();
                        }
                        else
                        {
                            parser.ParseCFWS(false, ref mimeStringList, this.handleISO2022);
                            parser.ParseParameterValue(ref mimeStringList2, ref flag, this.handleISO2022);
                            if (2147483647 != countLimit || 2147483647 != bytesLimit)
                            {
                                if (++num > countLimit)
                                {
                                    goto Block_8;
                                }
                                if (mimeStringList2.Length > bytesLimit)
                                {
                                    goto Block_9;
                                }
                            }
                            else
                            {
                                bool valueEncoded = false;
                                int  num2         = -1;
                                if (flag2)
                                {
                                    int num3 = ByteString.IndexOf(mimeString.Data, 42, mimeString.Offset, mimeString.Length);
                                    if (num3 > 0)
                                    {
                                        int num4 = mimeString.Offset + mimeString.Length;
                                        int num5 = num3 + 1;
                                        num2 = 0;
                                        while (num5 != num4 && mimeString.Data[num5] >= 48 && mimeString.Data[num5] <= 57)
                                        {
                                            num2 = num2 * 10 + (int)(mimeString.Data[num5] - 48);
                                            if (10000 < num2)
                                            {
                                                num2 = -1;
                                                break;
                                            }
                                            num5++;
                                        }
                                        if (-1 != num2)
                                        {
                                            bool flag3 = 42 == mimeString.Data[num4 - 1];
                                            if (num5 < num4 - 1 || (num5 < num4 && !flag3))
                                            {
                                                num2 = -1;
                                            }
                                            else
                                            {
                                                valueEncoded = flag3;
                                                mimeString.TrimRight(num4 - num3);
                                            }
                                        }
                                    }
                                }
                                string        text          = Header.NormalizeString(mimeString.Data, mimeString.Offset, mimeString.Length, false);
                                MimeParameter mimeParameter = new MimeParameter(text);
                                mimeParameter.AppendValue(ref mimeStringList2);
                                mimeParameter.SegmentNumber = num2;
                                mimeParameter.ValueEncoded  = valueEncoded;
                                MimeNode mimeNode;
                                MimeNode nextSibling;
                                for (mimeNode = base.FirstChild; mimeNode != null; mimeNode = nextSibling)
                                {
                                    nextSibling = mimeNode.NextSibling;
                                    MimeParameter mimeParameter2 = mimeNode as MimeParameter;
                                    if (mimeParameter2 != null && mimeParameter2.Name == text)
                                    {
                                        break;
                                    }
                                }
                                if (0 >= num2)
                                {
                                    if (mimeNode != null)
                                    {
                                        mimeParameter.AllowAppend = true;
                                        for (MimeNode mimeNode2 = mimeNode.FirstChild; mimeNode2 != null; mimeNode2 = nextSibling)
                                        {
                                            nextSibling = mimeNode2.NextSibling;
                                            if (mimeNode2 is MimeParameter)
                                            {
                                                mimeNode.RemoveChild(mimeNode2);
                                                mimeParameter.InternalAppendChild(mimeNode2);
                                            }
                                        }
                                        mimeParameter.AllowAppend = false;
                                        base.InternalRemoveChild(mimeNode);
                                    }
                                    base.InternalAppendChild(mimeParameter);
                                }
                                else
                                {
                                    if (mimeNode == null)
                                    {
                                        MimeParameter mimeParameter3 = new MimeParameter(text);
                                        mimeParameter3.SegmentNumber = 0;
                                        base.InternalAppendChild(mimeParameter3);
                                        mimeNode = mimeParameter3;
                                    }
                                    MimeNode mimeNode3;
                                    MimeNode previousSibling;
                                    for (mimeNode3 = mimeNode.LastChild; mimeNode3 != null; mimeNode3 = previousSibling)
                                    {
                                        previousSibling = mimeNode3.PreviousSibling;
                                        MimeParameter mimeParameter4 = mimeNode3 as MimeParameter;
                                        if (mimeParameter4 != null && mimeParameter4.SegmentNumber <= num2)
                                        {
                                            break;
                                        }
                                    }
                                    MimeParameter mimeParameter5 = (MimeParameter)mimeNode;
                                    mimeParameter5.AllowAppend = true;
                                    mimeParameter5.InternalInsertAfter(mimeParameter, mimeNode3);
                                    mimeParameter5.AllowAppend = false;
                                }
                            }
                        }
                    }
                }
                if (b == 0)
                {
                    return;
                }
            }
            return;

Block_8:
            throw new MimeException(Strings.TooManyParameters(num, countLimit));
Block_9:
            throw new MimeException(Strings.TooManyTextValueBytes(mimeStringList2.Length, bytesLimit));
        }
Ejemplo n.º 24
0
 internal override MimeNode ValidateNewChild(MimeNode newChild, MimeNode refChild)
 {
     throw new NotSupportedException(Strings.AddingChildrenToAsciiTextHeader);
 }
Ejemplo n.º 25
0
        // 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);
        }