Beispiel #1
0
        // Token: 0x06000544 RID: 1348 RVA: 0x0001CD90 File Offset: 0x0001AF90
        internal override long WriteTo(Stream stream, EncodingOptions encodingOptions, MimeOutputFilter filter, ref MimeStringLength currentLineLength, ref byte[] scratchBuffer)
        {
            MimeStringList displayNameToWrite = base.GetDisplayNameToWrite(encodingOptions);
            long           num  = 0L;
            int            num2 = 0;

            if (base.NextSibling != null)
            {
                num2++;
            }
            else if (base.Parent is MimeGroup)
            {
                num2++;
                if (base.Parent.NextSibling != null)
                {
                    num2++;
                }
            }
            byte[] sz   = this.emailAddressFragments.GetSz();
            int    num3 = ByteString.BytesToCharCount(sz, encodingOptions.AllowUTF8);

            if (displayNameToWrite.GetLength(4026531839U) != 0)
            {
                num += Header.QuoteAndFold(stream, displayNameToWrite, 4026531839U, base.IsQuotingRequired(displayNameToWrite, encodingOptions.AllowUTF8), true, encodingOptions.AllowUTF8, (num3 == 0) ? num2 : 0, ref currentLineLength, ref scratchBuffer);
            }
            if (num3 != 0)
            {
                int num4 = (1 < currentLineLength.InChars) ? 1 : 0;
                if (1 < currentLineLength.InChars)
                {
                    if (currentLineLength.InChars + num3 + 2 + num2 + num4 > 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);
                    }
                }
                stream.Write(MimeString.LessThan, 0, MimeString.LessThan.Length);
                num += (long)MimeString.LessThan.Length;
                currentLineLength.IncrementBy(MimeString.LessThan.Length);
                stream.Write(sz, 0, sz.Length);
                num += (long)sz.Length;
                currentLineLength.IncrementBy(num3, sz.Length);
                stream.Write(MimeString.GreaterThan, 0, MimeString.GreaterThan.Length);
                num += (long)MimeString.GreaterThan.Length;
                currentLineLength.IncrementBy(MimeString.GreaterThan.Length);
            }
            return(num);
        }
        // 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);
        }