Beispiel #1
0
 private void ZeroExpandFragment(ValuePosition start, ValuePosition end, bool allowControlCharacters, System.Text.StringBuilder sb)
 {
     var valueIterator = new ValueIterator(iterator.Lines, iterator.LinesMask, start, end);
     while (!valueIterator.Eof) {
         var num = (byte) valueIterator.Get();
         if (!allowControlCharacters && num < 32)
             num = (byte) ValueDecoder.ReplaceProhibitedControlCharacter((char) num);
         sb.Append((char) num);
     }
 }
Beispiel #2
0
 private void DecodeEncodedWord(
     byte bOrQ, System.Text.Decoder decoder, ValuePosition encodedWordContentStart, ValuePosition encodedWordContentEnd, bool allowControlCharacters, ref byte[] byteBuffer, ref char[] charBuffer, System.Text.StringBuilder sb)
 {
     var valueIterator = new ValueIterator(iterator.Lines, iterator.LinesMask, encodedWordContentStart, encodedWordContentEnd);
     if (charBuffer == null)
         charBuffer = Internal.ScratchPad.GetCharBuffer(System.Math.Min(1024, iterator.TotalLength));
     if (byteBuffer == null)
         byteBuffer = Internal.ScratchPad.GetByteBuffer(System.Math.Max(maxCharsetNameLength + 1, System.Math.Min(1024, iterator.TotalLength)));
     var byteBufferLength = 0;
     if (bOrQ == 66) {
         var num1 = 0;
         var num2 = 0;
         while (!valueIterator.Eof) {
             var num3 = (byte) (valueIterator.Get() - 32);
             if (num3 < Schema.Mime.Encoders.ByteEncoder.Tables.Base64ToByte.Length) {
                 var num4 = Schema.Mime.Encoders.ByteEncoder.Tables.Base64ToByte[num3];
                 if (num4 < 64) {
                     num2 = num2 << 6 | num4;
                     ++num1;
                     if (num1 == 4) {
                         var numArray1 = byteBuffer;
                         var index1 = byteBufferLength;
                         var num5 = 1;
                         var num6 = index1 + num5;
                         int num7 = (byte) (num2 >> 16);
                         numArray1[index1] = (byte) num7;
                         var numArray2 = byteBuffer;
                         var index2 = num6;
                         var num8 = 1;
                         var num9 = index2 + num8;
                         int num10 = (byte) (num2 >> 8);
                         numArray2[index2] = (byte) num10;
                         var numArray3 = byteBuffer;
                         var index3 = num9;
                         var num11 = 1;
                         byteBufferLength = index3 + num11;
                         int num12 = (byte) num2;
                         numArray3[index3] = (byte) num12;
                         num1 = 0;
                         if (byteBufferLength + 3 >= byteBuffer.Length) {
                             this.FlushDecodedBytes(byteBuffer, byteBufferLength, decoder, allowControlCharacters, charBuffer, sb);
                             byteBufferLength = 0;
                         }
                     }
                 }
             }
         }
         if (num1 != 0) {
             if (num1 == 2) {
                 var num3 = num2 << 12;
                 byteBuffer[byteBufferLength++] = (byte) (num3 >> 16);
             } else if (num1 == 3) {
                 var num3 = num2 << 6;
                 var numArray1 = byteBuffer;
                 var index1 = byteBufferLength;
                 var num4 = 1;
                 var num5 = index1 + num4;
                 int num6 = (byte) (num3 >> 16);
                 numArray1[index1] = (byte) num6;
                 var numArray2 = byteBuffer;
                 var index2 = num5;
                 var num7 = 1;
                 byteBufferLength = index2 + num7;
                 int num8 = (byte) (num3 >> 8);
                 numArray2[index2] = (byte) num8;
             }
         }
     } else {
         while (!valueIterator.Eof) {
             var num1 = (byte) valueIterator.Get();
             switch (num1) {
                 case 61:
                     var index1 = valueIterator.Get();
                     var index2 = valueIterator.Get();
                     int num2 = index1 < 0 ? byte.MaxValue : Schema.Mime.Encoders.ByteEncoder.Tables.NumFromHex[index1];
                     int num3 = index2 < 0 ? byte.MaxValue : Schema.Mime.Encoders.ByteEncoder.Tables.NumFromHex[index2];
                     num1 = num2 == (int) byte.MaxValue || num3 == (int) byte.MaxValue ? (byte) 61 : (byte) (num2 << 4 | num3);
                     break;
                 case 95:
                     num1 = 32;
                     break;
             }
             byteBuffer[byteBufferLength++] = num1;
             if (byteBufferLength >= byteBuffer.Length) {
                 this.FlushDecodedBytes(byteBuffer, byteBufferLength, decoder, allowControlCharacters, charBuffer, sb);
                 byteBufferLength = 0;
             }
         }
     }
     if (byteBufferLength == 0)
         return;
     this.FlushDecodedBytes(byteBuffer, byteBufferLength, decoder, allowControlCharacters, charBuffer, sb);
 }
Beispiel #3
0
        //    private bool ParseEncodedWord(string lastEncodedWordCharsetName, string lastEncodedWordLanguage, ref byte[] byteBuffer, out string encodedWordCharsetName, out string encodedWordLanguage, out byte bOrQ, out ValuePosition encodedWordContentStart, out ValuePosition encodedWordContentEnd)
        //    {
        //      encodedWordCharsetName = (string) null;
        //      encodedWordLanguage = (string) null;
        //      bOrQ = (byte) 0;
        //      // ISSUE: explicit reference operation
        //      // ISSUE: variable of a reference type
        //      ValuePosition& local1 = @encodedWordContentStart;
        //      // ISSUE: explicit reference operation
        //      // ISSUE: variable of a reference type
        //      ValuePosition& local2 = @encodedWordContentEnd;
        //      // ISSUE: explicit reference operation
        //      // ISSUE: variable of a reference type
        //      ValuePosition& local3 = @encodedWordContentEnd;
        //      ValuePosition valuePosition1 = new ValuePosition();
        //      ValuePosition valuePosition2 = valuePosition1;
        //      // ISSUE: explicit reference operation
        //      ^local3 = valuePosition2;
        //      ValuePosition valuePosition3;
        //      ValuePosition valuePosition4 = valuePosition3 = valuePosition1;
        //      // ISSUE: explicit reference operation
        //      ^local2 = valuePosition3;
        //      ValuePosition valuePosition5 = valuePosition4;
        //      // ISSUE: explicit reference operation
        //      ^local1 = valuePosition5;
        //      int num1 = this.iterator.Get();
        //      if (this.iterator.Get() != 63)
        //        return false;
        //      if (byteBuffer == null)
        //        byteBuffer = ScratchPad.GetByteBuffer(Math.Max(this.maxCharsetNameLength + 1, Math.Min(1024, this.iterator.TotalLength)));
        //      int num2 = -1;
        //      int count1;
        //      for (count1 = 0; count1 < this.maxCharsetNameLength + 1; ++count1)
        //      {
        //        num1 = this.iterator.Get();
        //        if (ValueDecoder.Is2047Token((byte) num1))
        //        {
        //          byteBuffer[count1] = (byte) num1;
        //          if (num2 == -1 && num1 == 42)
        //            num2 = count1;
        //        }
        //        else
        //          break;
        //      }
        //      if (count1 == this.maxCharsetNameLength + 1 || num1 != 63 || (count1 == 0 || num2 == 0))
        //        return false;
        //      int num3 = this.iterator.Get();
        //      bOrQ = num3 == 66 || num3 == 98 ? (byte) 66 : (num3 == 81 || num3 == 113 ? (byte) 81 : (byte) 0);
        //      if ((int) bOrQ == 0 || this.iterator.Get() != 63)
        //        return false;
        //      if (num2 != -1)
        //      {
        //        int offset = num2 + 1;
        //        int count2 = count1 - (num2 + 1);
        //        count1 = num2;
        //        if (count2 != 0)
        //        {
        //          if (lastEncodedWordLanguage != null && count2 == lastEncodedWordLanguage.Length)
        //          {
        //            int index = 0;
        //            while (index < count2 && (int) lastEncodedWordLanguage[index] == (int) byteBuffer[offset + index])
        //              ++index;
        //            encodedWordLanguage = index == count2 ? lastEncodedWordLanguage : ByteString.BytesToString(byteBuffer, offset, count2, false);
        //          }
        //          else
        //            encodedWordLanguage = ByteString.BytesToString(byteBuffer, offset, count2, false);
        //        }
        //      }
        //      if (lastEncodedWordCharsetName != null && count1 == lastEncodedWordCharsetName.Length)
        //      {
        //        int index = 0;
        //        while (index < count1 && (int) lastEncodedWordCharsetName[index] == (int) byteBuffer[index])
        //          ++index;
        //        encodedWordCharsetName = index == count1 ? lastEncodedWordCharsetName : ByteString.BytesToString(byteBuffer, 0, count1, false);
        //      }
        //      else
        //        encodedWordCharsetName = ByteString.BytesToString(byteBuffer, 0, count1, false);
        //      encodedWordContentStart = this.iterator.CurrentPosition;
        //      bool flag = false;
        //      while (true)
        //      {
        //        encodedWordContentEnd = this.iterator.CurrentPosition;
        //        int num4 = this.iterator.Get();
        //        if (num4 != -1)
        //        {
        //          if (MimeScan.IsLWSP((byte) num4))
        //          {
        //            flag = true;
        //          }
        //          else
        //          {
        //            if (num4 == 63)
        //            {
        //              switch (this.iterator.Get())
        //              {
        //                case -1:
        //                  goto label_35;
        //                case 61:
        //                  goto label_44;
        //                default:
        //                  this.iterator.Unget();
        //                  if ((int) bOrQ == 81)
        //                    break;
        //                  goto label_37;
        //              }
        //            }
        //            else if (num4 == 61 && flag)
        //            {
        //              switch (this.iterator.Get())
        //              {
        //                case -1:
        //                  goto label_40;
        //                case 63:
        //                  goto label_41;
        //                default:
        //                  this.iterator.Unget();
        //                  break;
        //              }
        //            }
        //            flag = false;
        //          }
        //        }
        //        else
        //          break;
        //      }
        //      return false;
        //label_35:
        //      return false;
        //label_37:
        //      return false;
        //label_40:
        //      return false;
        //label_41:
        //      this.iterator.Unget();
        //      this.iterator.Unget();
        //      return false;
        //label_44:
        //      return true;
        //    }
        private bool ParseEncodedWord(
            string lastEncodedWordCharsetName, string lastEncodedWordLanguage, ref byte[] byteBuffer, out string encodedWordCharsetName, out string encodedWordLanguage, out byte bOrQ, out ValuePosition encodedWordContentStart,
            out ValuePosition encodedWordContentEnd)
        {
            encodedWordCharsetName = null;
            encodedWordLanguage = null;
            bOrQ = 0;
            var position = new ValuePosition();
            encodedWordContentEnd = position;
            encodedWordContentStart = encodedWordContentEnd = position;
            var num = iterator.Get();
            if (iterator.Get() != 0x3f)
                return false;
            if (byteBuffer == null)
                byteBuffer = Internal.ScratchPad.GetByteBuffer(System.Math.Max(maxCharsetNameLength + 1, System.Math.Min(0x400, iterator.TotalLength)));
            var num3 = -1;
            var index = 0;
            while (index < (maxCharsetNameLength + 1)) {
                num = iterator.Get();
                if (!ValueDecoder.Is2047Token((byte) num))
                    break;
                byteBuffer[index] = (byte) num;
                if ((num3 == -1) && (num == 0x2a))
                    num3 = index;
                index++;
            }
            if (((index == (maxCharsetNameLength + 1)) || (num != 0x3f)) || ((index == 0) || (num3 == 0)))
                return false;
            num = iterator.Get();
            bOrQ = ((num == 0x42) || (num == 0x62)) ? ((byte) 0x42) : (((num == 0x51) || (num == 0x71)) ? ((byte) 0x51) : ((byte) 0));
            if ((bOrQ == 0) || (iterator.Get() != 0x3f))
                return false;
            if (num3 != -1) {
                var offset = num3 + 1;
                var count = index - (num3 + 1);
                index = num3;
                if (count != 0) {
                    if ((lastEncodedWordLanguage == null) || (count != lastEncodedWordLanguage.Length))
                        encodedWordLanguage = Internal.ByteString.BytesToString(byteBuffer, offset, count, false);
                    else {
                        var num6 = 0;
                        while (num6 < count) {
                            if (lastEncodedWordLanguage[num6] != byteBuffer[offset + num6])
                                break;
                            num6++;
                        }
                        if (num6 != count)
                            encodedWordLanguage = Internal.ByteString.BytesToString(byteBuffer, offset, count, false);
                        else
                            encodedWordLanguage = lastEncodedWordLanguage;
                    }
                }
            }
            if ((lastEncodedWordCharsetName == null) || (index != lastEncodedWordCharsetName.Length))
                encodedWordCharsetName = Internal.ByteString.BytesToString(byteBuffer, 0, index, false);
            else {
                var num7 = 0;
                while (num7 < index) {
                    if (lastEncodedWordCharsetName[num7] != byteBuffer[num7])
                        break;
                    num7++;
                }
                if (num7 != index)
                    encodedWordCharsetName = Internal.ByteString.BytesToString(byteBuffer, 0, index, false);
                else
                    encodedWordCharsetName = lastEncodedWordCharsetName;
            }
            encodedWordContentStart = iterator.CurrentPosition;
            var flag = false;
            while (true) {
                encodedWordContentEnd = iterator.CurrentPosition;
                num = iterator.Get();
                if (num == -1)
                    return false;
                if (MimeScan.IsLWSP((byte) num))
                    flag = true;
                else {
                    if (num == 0x3f) {
                        num = iterator.Get();
                        switch (num) {
                            case -1:
                                return false;

                            case 0x3d:
                                return true;
                        }
                        iterator.Unget();
                        if (bOrQ != 0x51)
                            return false;
                    } else if ((num == 0x3d) && flag) {
                        switch (iterator.Get()) {
                            case -1:
                                return false;

                            case 0x3f:
                                iterator.Unget();
                                iterator.Unget();
                                return false;
                        }
                        iterator.Unget();
                    }
                    flag = false;
                }
            }
        }
Beispiel #4
0
 private void ConvertRawFragment(ValuePosition start, ValuePosition end, System.Text.Decoder decoder, bool allowControlCharacters, ref char[] charBuffer, System.Text.StringBuilder sb)
 {
     var valueIterator = new ValueIterator(iterator.Lines, iterator.LinesMask, start, end);
     if (valueIterator.Eof)
         return;
     if (charBuffer == null)
         charBuffer = Internal.ScratchPad.GetCharBuffer(System.Math.Min(1024, iterator.TotalLength));
     int bytesUsed;
     int charsUsed;
     bool completed;
     do {
         decoder.Convert(valueIterator.Bytes, valueIterator.Offset, valueIterator.Length, charBuffer, 0, charBuffer.Length, false, out bytesUsed, out charsUsed, out completed);
         if (charsUsed != 0) {
             if (!allowControlCharacters)
                 ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, charsUsed);
             sb.Append(charBuffer, 0, charsUsed);
         }
         valueIterator.Get(bytesUsed);
     } while (!completed || !valueIterator.Eof);
     decoder.Convert(MimeString.EmptyByteArray, 0, 0, charBuffer, 0, charBuffer.Length, true, out bytesUsed, out charsUsed, out completed);
     if (charsUsed == 0)
         return;
     if (!allowControlCharacters)
         ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, charsUsed);
     sb.Append(charBuffer, 0, charsUsed);
 }