// Token: 0x060002FD RID: 765 RVA: 0x000108E8 File Offset: 0x0000EAE8
 public bool TryGetValue(DecodingOptions decodingOptions, out DecodingResults decodingResults, out string value)
 {
     if (decodingOptions.Charset == null)
     {
         decodingOptions.Charset = base.GetDefaultHeaderDecodingCharset(null, null);
     }
     if ((DecodingFlags.Rfc2231 & decodingOptions.DecodingFlags) != DecodingFlags.None)
     {
         if (this.segmentNumber == 0)
         {
             return(this.TryDecodeRfc2231(ref decodingOptions, out decodingResults, out value));
         }
         if (0 < this.segmentNumber)
         {
             throw new NotSupportedException(Strings.CantGetValueOfRfc2231ContinuationSegment);
         }
     }
     if (this.valueFragments.Length == 0)
     {
         decodingResults = default(DecodingResults);
         value           = ((this.decodedValue != null) ? this.decodedValue : string.Empty);
         return(true);
     }
     return(MimeCommon.TryDecodeValue(this.valueFragments, 4026531839U, decodingOptions, out decodingResults, out value));
 }
Пример #2
0
        internal void QueueWrite(byte[] data, int offset, int count)
        {
            this.bytesWritten   += count;
            this.lineTermination = MimeCommon.AdvanceLineTerminationState(this.lineTermination, data, offset, count);
            int num = (this.writeCount == 1) ? (this.currentWrite.Length - this.currentWrite.Count) : ((this.writeCount == 0) ? MimeWriter.QueuedWrite.QueuedWriteSize : 0);

            if (num >= count)
            {
                if (this.writeCount == 0)
                {
                    MimeWriter.QueuedWrite queuedWrite = default(MimeWriter.QueuedWrite);
                    this.PushWrite(ref queuedWrite);
                }
                this.currentWrite.Append(data, offset, count);
                return;
            }
            MimeWriter.QueuedWrite queuedWrite2 = default(MimeWriter.QueuedWrite);
            if (count < MimeWriter.QueuedWrite.QueuedWriteSize && this.writeCount > 0)
            {
                queuedWrite2 = this.currentWrite;
            }
            this.FlushWriteQueue();
            if (count < MimeWriter.QueuedWrite.QueuedWriteSize && queuedWrite2.Length > 0)
            {
                queuedWrite2.Reset();
                queuedWrite2.Append(data, offset, count);
                this.PushWrite(ref queuedWrite2);
                return;
            }
            this.data.Write(data, offset, count);
        }
        // Token: 0x06000309 RID: 777 RVA: 0x00010FCC File Offset: 0x0000F1CC
        private void EncodeRfc2231(EncodingOptions encodingOptions)
        {
            if (!MimeCommon.IsEncodingRequired(this.decodedValue, encodingOptions.AllowUTF8))
            {
                this.valueEncoded  = false;
                this.segmentNumber = -1;
                this.valueFragments.AppendFragment(new MimeString(this.decodedValue));
                return;
            }
            Charset  encodingCharset = encodingOptions.GetEncodingCharset();
            Encoding encoding        = encodingCharset.GetEncoding();
            int      num             = 0;
            int      num2            = 0;
            string   text            = (encodingOptions.CultureName == null) ? string.Empty : encodingOptions.CultureName;

            if ((encodingOptions.AllowUTF8 && encodingCharset.CodePage != 20127 && encodingCharset.CodePage != 65001) || (!encodingOptions.AllowUTF8 && encodingCharset.CodePage != 20127) || "en-us" != text)
            {
                string name  = encodingCharset.Name;
                byte[] array = new byte[name.Length + text.Length + 2];
                num         += ByteString.StringToBytes(name, array, num, false);
                num2        += name.Length;
                array[num++] = 39;
                num2++;
                num         += ByteString.StringToBytes(text, array, num, false);
                num2        += text.Length;
                array[num++] = 39;
                num2++;
                this.valueFragments.AppendFragment(new MimeString(array, 0, num));
                this.valueEncoded = true;
            }
            int num3 = 78 - this.paramName.Length - 6;
            int num4 = 2;

            byte[] bytes = encoding.GetBytes(this.decodedValue);
            int    i     = this.EncodeRfc2231Segment(bytes, 0, num3 - num4 - num2, encodingOptions);

            this.segmentNumber = ((i < bytes.Length) ? 0 : -1);
            int num5 = 1;
            int num6 = 10;

            this.AllowAppend = true;
            while (i < bytes.Length)
            {
                MimeParameter mimeParameter = new MimeParameter(this.paramName);
                if (num6 == num5)
                {
                    num4++;
                    num6 *= 10;
                }
                i = mimeParameter.EncodeRfc2231Segment(bytes, i, num3 - num4, encodingOptions);
                mimeParameter.segmentNumber = num5++;
                base.InternalAppendChild(mimeParameter);
                if (10000 == num5)
                {
                    break;
                }
            }
            this.AllowAppend = false;
        }
Пример #4
0
 // Token: 0x06000552 RID: 1362 RVA: 0x0001D1AB File Offset: 0x0001B3AB
 internal MimeStringList GetEncodedValue(EncodingOptions encodingOptions, ValueEncodingStyle encodingStyle)
 {
     if (string.IsNullOrEmpty(this.decodedValue))
     {
         return(base.Lines);
     }
     return(MimeCommon.EncodeValue(this.decodedValue, encodingOptions, encodingStyle));
 }
Пример #5
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     MimeCommon.CheckBufferArguments(buffer, offset, count);
     if (this.writer.contentWritten)
     {
         throw new InvalidOperationException(Strings.ContentAlreadyWritten);
     }
     this.writer.Write(buffer, offset, count);
 }
Пример #6
0
        // Token: 0x06000256 RID: 598 RVA: 0x0000B710 File Offset: 0x00009910
        private static void CalculateMethodAndChunkSize_Utf8(bool allowQEncoding, ByteEncoder.Tables.CharClasses unsafeCharClassesForQEncoding, Encoding encoding, string value, int valueOffset, int encodedWordSpace, out byte method, out int chunkSize)
        {
            int  num   = encodedWordSpace / 4 * 3;
            int  num2  = 0;
            int  num3  = 0;
            int  num4  = 0;
            int  num5  = 0;
            int  num6  = valueOffset;
            bool flag  = false;
            bool flag2 = false;

            while (num6 != value.Length && (!flag || !flag2))
            {
                int  num7 = 1;
                int  num8 = 1;
                int  num9 = 1;
                char c    = value[num6++];
                if (MimeCommon.QEncodingRequired(c, unsafeCharClassesForQEncoding))
                {
                    if (c > '\u007f')
                    {
                        num9++;
                        if (c > '߿')
                        {
                            num9++;
                            if (MimeCommon.IsAnySurrogate(c) && MimeCommon.IsHighSurrogate(c) && num6 != value.Length && MimeCommon.IsLowSurrogate(value[num6]))
                            {
                                num6++;
                                num7++;
                                num9++;
                            }
                        }
                    }
                    num8 = num9 * 3;
                }
                flag  = (flag || num5 + num9 > num);
                flag2 = (flag2 || num3 + num8 > encodedWordSpace);
                if (!flag)
                {
                    num5 += num9;
                    num4 += num7;
                }
                if (!flag2)
                {
                    num3 += num8;
                    num2 += num7;
                }
            }
            if (num2 >= num4 && num3 < num5 + 3)
            {
                chunkSize = num2;
                method    = 81;
                return;
            }
            chunkSize = MimeCommon.AdjustChunkSize(encoding, num4, value, valueOffset, num);
            method    = 66;
        }
Пример #7
0
        // Token: 0x06000254 RID: 596 RVA: 0x0000B4B0 File Offset: 0x000096B0
        private static void CalculateMethodAndChunkSize_Sbcs(bool allowQEncoding, ByteEncoder.Tables.CharClasses unsafeCharClassesForQEncoding, Encoding encoding, string value, int valueOffset, int encodedWordSpace, out byte method, out int chunkSize)
        {
            int num  = encodedWordSpace / 4 * 3;
            int num2 = Math.Min(num, value.Length - valueOffset);

            if (num2 != value.Length - valueOffset && MimeCommon.IsHighSurrogate(value[valueOffset + num2 - 1]) && MimeCommon.IsLowSurrogate(value[valueOffset + num2]))
            {
                num2--;
            }
            int num3 = (num2 + 2) / 3 * 4;

            if (!allowQEncoding)
            {
                chunkSize = MimeCommon.AdjustChunkSize(encoding, num2, value, valueOffset, num);
                method    = 66;
                return;
            }
            int num4 = 0;
            int num5 = 0;
            int num6 = valueOffset;

            while (num6 != value.Length && num5 < encodedWordSpace)
            {
                int  num7 = 1;
                int  num8 = 1;
                char ch   = value[num6++];
                if (MimeCommon.QEncodingRequired(ch, unsafeCharClassesForQEncoding))
                {
                    num8 = 3;
                    if (MimeCommon.IsHighSurrogate(ch) && num6 != value.Length && MimeCommon.IsLowSurrogate(value[num6]))
                    {
                        num6++;
                        num7++;
                        num8 = 6;
                    }
                }
                if (num5 + num8 > encodedWordSpace)
                {
                    break;
                }
                num5 += num8;
                num4 += num7;
                if (num5 > num3 && num4 <= num2)
                {
                    break;
                }
            }
            if (num4 >= num2 && num5 < num3 + 3)
            {
                chunkSize = num4;
                method    = 81;
                return;
            }
            chunkSize = MimeCommon.AdjustChunkSize(encoding, num2, value, valueOffset, num);
            method    = 66;
        }
Пример #8
0
        // Token: 0x0600025A RID: 602 RVA: 0x0000B9AC File Offset: 0x00009BAC
        private static int AdjustChunkSize(Encoding encoding, int chunkSize, string value, int valueOffset, int targetBytes)
        {
            int i = MimeCommon.GetByteCount(encoding, value, valueOffset, chunkSize);

            if (i > targetBytes)
            {
                int num = chunkSize * targetBytes / i;
                if (num < chunkSize)
                {
                    if (MimeCommon.IsLowSurrogate(value[valueOffset + num]) && MimeCommon.IsHighSurrogate(value[valueOffset + num - 1]))
                    {
                        num--;
                    }
                    chunkSize = num;
                    i         = MimeCommon.GetByteCount(encoding, value, valueOffset, chunkSize);
                }
                while (i > targetBytes)
                {
                    num = chunkSize * targetBytes / i;
                    if (num < chunkSize)
                    {
                        chunkSize = num;
                    }
                    else
                    {
                        chunkSize--;
                    }
                    if (MimeCommon.IsLowSurrogate(value[valueOffset + chunkSize]) && MimeCommon.IsHighSurrogate(value[valueOffset + chunkSize - 1]))
                    {
                        chunkSize--;
                    }
                    i = MimeCommon.GetByteCount(encoding, value, valueOffset, chunkSize);
                }
            }
            if (i < targetBytes - 2 && i != 0)
            {
                int num2 = 0;
                while (valueOffset + chunkSize < value.Length && num2++ < 3)
                {
                    int num3 = 1;
                    if (MimeCommon.IsHighSurrogate(value[valueOffset + chunkSize]) && valueOffset + chunkSize + 1 < value.Length && MimeCommon.IsLowSurrogate(value[valueOffset + chunkSize + 1]))
                    {
                        num3++;
                    }
                    i = MimeCommon.GetByteCount(encoding, value, valueOffset, chunkSize + num3);
                    if (i > targetBytes)
                    {
                        break;
                    }
                    chunkSize += num3;
                }
            }
            return(chunkSize);
        }
        // Token: 0x06000308 RID: 776 RVA: 0x00010F8C File Offset: 0x0000F18C
        private MimeStringList EncodeValue(string value, EncodingOptions encodingOptions)
        {
            this.valueFragments.Reset();
            int count = this.valueFragments.Count;

            if ((byte)(EncodingFlags.EnableRfc2231 & encodingOptions.EncodingFlags) != 0)
            {
                this.EncodeRfc2231(encodingOptions);
                return(this.valueFragments);
            }
            return(MimeCommon.EncodeValue(value, encodingOptions, ValueEncodingStyle.Normal));
        }
Пример #10
0
        // Token: 0x06000259 RID: 601 RVA: 0x0000B934 File Offset: 0x00009B34
        private static void CalculateMethodAndChunkSize_Mbcs(bool allowQEncoding, ByteEncoder.Tables.CharClasses unsafeCharClassesForQEncoding, Encoding encoding, string value, int valueOffset, int encodedWordSpace, out byte method, out int chunkSize)
        {
            int num = encodedWordSpace / 4 * 3;

            chunkSize = Math.Min(num, value.Length - valueOffset);
            if (chunkSize < value.Length - valueOffset && MimeCommon.IsLowSurrogate(value[valueOffset + chunkSize]) && MimeCommon.IsHighSurrogate(value[valueOffset + chunkSize - 1]))
            {
                chunkSize--;
            }
            chunkSize = MimeCommon.AdjustChunkSize(encoding, chunkSize, value, valueOffset, num);
            method    = 66;
        }
Пример #11
0
 // Token: 0x0600019D RID: 413 RVA: 0x00007500 File Offset: 0x00005700
 public bool TryGetDisplayName(DecodingOptions decodingOptions, out DecodingResults decodingResults, out string displayName)
 {
     if (this.displayNameFragments.Count == 0)
     {
         displayName     = this.decodedDisplayName;
         decodingResults = default(DecodingResults);
         return(true);
     }
     if (decodingOptions.Charset == null)
     {
         decodingOptions.Charset = base.GetDefaultHeaderDecodingCharset(null, null);
     }
     return(MimeCommon.TryDecodeValue(this.displayNameFragments, 4026531839U, decodingOptions, out decodingResults, out displayName));
 }
Пример #12
0
        public void WriteRawContent(byte[] buffer, int offset, int count)
        {
            MimeCommon.CheckBufferArguments(buffer, offset, count);
            this.AssertOpen();
            if (this.contentWritten)
            {
                throw new InvalidOperationException(Strings.ContentAlreadyWritten);
            }
            Stream rawContentWriteStream = this.partContent;

            if (rawContentWriteStream == null)
            {
                rawContentWriteStream = this.GetRawContentWriteStream();
            }
            rawContentWriteStream.Write(buffer, offset, count);
        }
Пример #13
0
 public void WriteContent(byte[] buffer, int offset, int count)
 {
     MimeCommon.CheckBufferArguments(buffer, offset, count);
     this.AssertOpen();
     if (this.contentWritten)
     {
         throw new InvalidOperationException(Strings.ContentAlreadyWritten);
     }
     if (this.encodedPartContent != null)
     {
         this.encodedPartContent.Write(buffer, offset, count);
         return;
     }
     using (Stream contentWriteStream = this.GetContentWriteStream())
     {
         contentWriteStream.Write(buffer, offset, count);
     }
 }
Пример #14
0
        // Token: 0x06000551 RID: 1361 RVA: 0x0001D13C File Offset: 0x0001B33C
        internal string GetDecodedValue(DecodingOptions decodingOptions, out DecodingResults decodingResults)
        {
            string result = null;

            if (base.Lines.Length == 0)
            {
                result          = ((this.decodedValue != null) ? this.decodedValue : string.Empty);
                decodingResults = default(DecodingResults);
                return(result);
            }
            if (decodingOptions.Charset == null)
            {
                decodingOptions.Charset = base.GetDefaultHeaderDecodingCharset(null, null);
            }
            if (!MimeCommon.TryDecodeValue(base.Lines, 4026531840U, decodingOptions, out decodingResults, out result))
            {
                result = null;
            }
            return(result);
        }
Пример #15
0
        // Token: 0x060001A3 RID: 419 RVA: 0x00007708 File Offset: 0x00005908
        internal MimeStringList GetDisplayNameToWrite(EncodingOptions encodingOptions)
        {
            MimeStringList result = this.displayNameFragments;

            if (result.GetLength(4026531839U) == 0 && this.decodedDisplayName != null && this.decodedDisplayName.Length != 0)
            {
                string value;
                if ((byte)(encodingOptions.EncodingFlags & EncodingFlags.QuoteDisplayNameBeforeRfc2047Encoding) != 0 && this.IsQuotingRequired(this.decodedDisplayName, encodingOptions.AllowUTF8) && MimeCommon.IsEncodingRequired(this.decodedDisplayName, encodingOptions.AllowUTF8))
                {
                    value = this.QuoteString(this.decodedDisplayName);
                }
                else
                {
                    value = this.decodedDisplayName;
                }
                result = MimeCommon.EncodeValue(value, encodingOptions, ValueEncodingStyle.Phrase);
                this.displayNameFragments = result;
            }
            else if ((byte)(EncodingFlags.ForceReencode & encodingOptions.EncodingFlags) != 0)
            {
                result = MimeCommon.EncodeValue(this.DisplayName, encodingOptions, ValueEncodingStyle.Phrase);
            }
            return(result);
        }
Пример #16
0
        // Token: 0x06000252 RID: 594 RVA: 0x0000AF40 File Offset: 0x00009140
        internal static MimeStringList EncodeValue(string value, EncodingOptions encodingOptions, ValueEncodingStyle style)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(MimeStringList.Empty);
            }
            if (!MimeCommon.IsEncodingRequired(value, encodingOptions.AllowUTF8))
            {
                return(new MimeStringList(new MimeString(value)));
            }
            MimeStringList result = default(MimeStringList);
            Charset        encodingCharset;

            if (encodingOptions.CharsetName != null)
            {
                encodingCharset = encodingOptions.GetEncodingCharset();
            }
            else
            {
                OutboundCodePageDetector outboundCodePageDetector = new OutboundCodePageDetector();
                outboundCodePageDetector.AddText(value);
                int codePage = outboundCodePageDetector.GetCodePage();
                if (!Charset.TryGetCharset(codePage, out encodingCharset))
                {
                    encodingCharset = MimeCommon.DefaultEncodingOptions.GetEncodingCharset();
                }
            }
            ByteEncoder.Tables.CharClasses charClasses = ByteEncoder.Tables.CharClasses.QEncode;
            if (style == ValueEncodingStyle.Phrase)
            {
                charClasses |= ByteEncoder.Tables.CharClasses.QPhraseUnsafe;
            }
            else if (style == ValueEncodingStyle.Comment)
            {
                charClasses |= ByteEncoder.Tables.CharClasses.QCommentUnsafe;
            }
            bool allowQEncoding = false;

            MimeCommon.CalculateMethodAndChunkSize calculateMethodAndChunkSize;
            if (encodingCharset.Kind == CodePageKind.Sbcs)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeSbcs;
                if (encodingCharset.AsciiSupport >= CodePageAsciiSupport.Fine)
                {
                    allowQEncoding = true;
                }
            }
            else if (encodingCharset.Kind == CodePageKind.Dbcs)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeDbcs;
                if (encodingCharset.AsciiSupport >= CodePageAsciiSupport.Fine)
                {
                    allowQEncoding = true;
                }
            }
            else if (encodingCharset.CodePage == 65001)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeUtf8;
                allowQEncoding = true;
            }
            else if (encodingCharset.CodePage == 1200 || encodingCharset.CodePage == 1201)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeUnicode16;
            }
            else if (encodingCharset.CodePage == 12000 || encodingCharset.CodePage == 12001)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeUnicode32;
            }
            else
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeMbcs;
            }
            int num  = 75;
            int num2 = 7 + encodingCharset.Name.Length;
            int num3 = num - num2;

            if (num3 < 32)
            {
                num  = num2 + 32;
                num3 = 32;
            }
            byte[]   byteBuffer = ScratchPad.GetByteBuffer(num3);
            Encoding encoding   = encodingCharset.GetEncoding();

            byte[] array = new byte[5 + encodingCharset.Name.Length];
            int    num4  = 0;

            array[num4++] = 61;
            array[num4++] = 63;
            num4         += ByteString.StringToBytes(encodingCharset.Name, array, num4, false);
            array[num4++] = 63;
            array[num4++] = 88;
            array[num4++] = 63;
            MimeString mimeString = new MimeString(array);
            int        num5       = 0;

            byte[] array2 = null;
            int    num6   = 0;
            int    num7   = num3 / 4;

            while (num5 != value.Length)
            {
                byte b;
                int  num8;
                calculateMethodAndChunkSize(allowQEncoding, charClasses, encoding, value, num5, num3, out b, out num8);
                int bytes;
                int num10;
                for (;;)
                {
                    for (;;)
                    {
                        try
                        {
                            bytes = encoding.GetBytes(value, num5, num8, byteBuffer, 0);
                        }
                        catch (ArgumentException)
                        {
                            if (num8 < 2)
                            {
                                throw;
                            }
                            num8 -= ((num8 > 10) ? 3 : 1);
                            if (MimeCommon.IsLowSurrogate(value[num5 + num8]) && MimeCommon.IsHighSurrogate(value[num5 + num8 - 1]))
                            {
                                num8--;
                            }
                            break;
                        }
                        if (bytes == 0)
                        {
                            goto IL_424;
                        }
                        if (array2 == null || array2.Length - num6 < num + 1)
                        {
                            if (array2 != null)
                            {
                                result.Append(new MimeString(array2, 0, num6));
                                num6 = 0;
                            }
                            int val  = ((value.Length - num5) / num8 + 1) * (num + 1);
                            int num9 = Math.Min(val, 4096 / (num + 1) * (num + 1));
                            array2 = new byte[num9];
                        }
                        num10 = num6;
                        if (result.Count > 0 || num10 > 0)
                        {
                            array2[num10++] = 32;
                        }
                        num10            += mimeString.CopyTo(array2, num10);
                        array2[num10 - 2] = b;
                        if (b != 81)
                        {
                            goto IL_3F5;
                        }
                        int num11 = num10;
                        int num12 = 0;
                        while (num12 < bytes && num10 - num11 + 1 <= num3)
                        {
                            byte b2 = byteBuffer[num12];
                            if (MimeCommon.QEncodingRequired((char)b2, charClasses))
                            {
                                if (num10 - num11 + 3 > num3)
                                {
                                    break;
                                }
                                array2[num10++] = 61;
                                array2[num10++] = ByteEncoder.NibbleToHex[b2 >> 4];
                                array2[num10++] = ByteEncoder.NibbleToHex[(int)(b2 & 15)];
                            }
                            else
                            {
                                if (b2 == 32)
                                {
                                    b2 = 95;
                                }
                                array2[num10++] = b2;
                            }
                            num12++;
                        }
                        if (num12 == bytes)
                        {
                            goto IL_408;
                        }
                        if (num8 < 2)
                        {
                            goto Block_26;
                        }
                        num8 -= ((num8 > 10) ? 3 : 1);
                        if (MimeCommon.IsLowSurrogate(value[num5 + num8]) && MimeCommon.IsHighSurrogate(value[num5 + num8 - 1]))
                        {
                            num8--;
                        }
                    }
                }
IL_424:
                num5 += num8;
                continue;
Block_26:
                throw new InvalidOperationException("unexpected thing just happened");
IL_408:
                array2[num10++] = 63;
                array2[num10++] = 61;
                num6            = num10;
                goto IL_424;
IL_3F5:
                num10 += MimeCommon.Base64EncodeChunk(byteBuffer, 0, bytes, array2, num10);
                goto IL_408;
            }
            if (array2 != null)
            {
                result.Append(new MimeString(array2, 0, num6));
            }
            return(result);
        }