// 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)); }
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)); var mimeStringList = new MimeStringList(); Globalization.Charset charset; if (encodingOptions.CharsetName != null) charset = encodingOptions.GetEncodingCharset(); else { var codePageDetector = new Globalization.OutboundCodePageDetector(); codePageDetector.AddText(value); if (!Globalization.Charset.TryGetCharset(codePageDetector.GetCodePage(), out charset)) charset = DefaultEncodingOptions.GetEncodingCharset(); } var charClasses = Schema.Mime.Encoders.ByteEncoder.Tables.CharClasses.QEncode; if (style == ValueEncodingStyle.Phrase) charClasses |= Schema.Mime.Encoders.ByteEncoder.Tables.CharClasses.QPhraseUnsafe; else if (style == ValueEncodingStyle.Comment) charClasses |= Schema.Mime.Encoders.ByteEncoder.Tables.CharClasses.QCommentUnsafe; var allowQEncoding = false; CalculateMethodAndChunkSize methodAndChunkSize; if (charset.Kind == Globalization.CodePageKind.Sbcs) { methodAndChunkSize = calculateMethodAndChunkSizeSbcs; if (charset.AsciiSupport >= Globalization.CodePageAsciiSupport.Fine) allowQEncoding = true; } else if (charset.Kind == Globalization.CodePageKind.Dbcs) { methodAndChunkSize = calculateMethodAndChunkSizeDbcs; if (charset.AsciiSupport >= Globalization.CodePageAsciiSupport.Fine) allowQEncoding = true; } else if (charset.CodePage == 65001) { methodAndChunkSize = calculateMethodAndChunkSizeUtf8; allowQEncoding = true; } else { methodAndChunkSize = charset.CodePage == 1200 || charset.CodePage == 1201 ? calculateMethodAndChunkSizeUnicode16 : (charset.CodePage == 12000 || charset.CodePage == 12001 ? calculateMethodAndChunkSizeUnicode32 : calculateMethodAndChunkSizeMbcs); } var num1 = 75; var num2 = 7 + charset.Name.Length; var num3 = num1 - num2; if (num3 < 32) { num1 = num2 + 32; num3 = 32; } var byteBuffer = Internal.ScratchPad.GetByteBuffer(num3); var encoding = charset.GetEncoding(); var numArray1 = new byte[5 + charset.Name.Length]; var num4 = 0; var numArray2 = numArray1; var index1 = num4; var num5 = 1; var num6 = index1 + num5; var num7 = 61; numArray2[index1] = (byte) num7; var numArray3 = numArray1; var index2 = num6; var num8 = 1; var bytesOffset = index2 + num8; var num9 = 63; numArray3[index2] = (byte) num9; var num10 = bytesOffset + Internal.ByteString.StringToBytes(charset.Name, numArray1, bytesOffset, false); var numArray4 = numArray1; var index3 = num10; var num11 = 1; var num12 = index3 + num11; var num13 = 63; numArray4[index3] = (byte) num13; var numArray5 = numArray1; var index4 = num12; var num14 = 1; var num15 = index4 + num14; var num16 = 88; numArray5[index4] = (byte) num16; var numArray6 = numArray1; var index5 = num15; var num17 = 1; var num18 = index5 + num17; var num19 = 63; numArray6[index5] = (byte) num19; var mimeString = new MimeString(numArray1); var num20 = 0; byte[] numArray7 = null; var count = 0; var num21 = num3/4; while (num20 != value.Length) { byte method; int chunkSize; methodAndChunkSize(allowQEncoding, charClasses, encoding, value, num20, num3, out method, out chunkSize); label_25: int bytes; int outputOffset; while (true) { do { do { try { bytes = encoding.GetBytes(value, num20, chunkSize, byteBuffer, 0); } catch (System.ArgumentException ex) { if (chunkSize < 2) throw; chunkSize -= chunkSize > 10 ? 3 : 1; if (MimeCommon.IsLowSurrogate(value[num20 + chunkSize])) { if (MimeCommon.IsHighSurrogate(value[num20 + chunkSize - 1])) --chunkSize; } goto label_25; } if (bytes != 0) { if (numArray7 == null || numArray7.Length - count < num1 + 1) { if (numArray7 != null) { mimeStringList.Append(new MimeString(numArray7, 0, count)); count = 0; } numArray7 = new byte[System.Math.Min(((value.Length - num20)/chunkSize + 1)*(num1 + 1), 4096/(num1 + 1)*(num1 + 1))]; } var destinationIndex = count; if (mimeStringList.Count > 0 || destinationIndex > 0) numArray7[destinationIndex++] = 32; outputOffset = destinationIndex + mimeString.CopyTo(numArray7, destinationIndex); numArray7[outputOffset - 2] = method; if (method == 81) { var num22 = outputOffset; int index6; for (index6 = 0; index6 < bytes && outputOffset - num22 + 1 <= num3; ++index6) { var num23 = byteBuffer[index6]; if (MimeCommon.QEncodingRequired((char) num23, charClasses)) { if (outputOffset - num22 + 3 <= num3) { var numArray8 = numArray7; var index7 = outputOffset; var num24 = 1; var num25 = index7 + num24; var num26 = 61; numArray8[index7] = (byte) num26; var numArray9 = numArray7; var index8 = num25; var num27 = 1; var num28 = index8 + num27; int num29 = Schema.Mime.Encoders.ByteEncoder.NibbleToHex[num23 >> 4]; numArray9[index8] = (byte) num29; var numArray10 = numArray7; var index9 = num28; var num30 = 1; outputOffset = index9 + num30; int num31 = Schema.Mime.Encoders.ByteEncoder.NibbleToHex[num23 & 15]; numArray10[index9] = (byte) num31; } else break; } else { if (num23 == 32) num23 = 95; numArray7[outputOffset++] = num23; } } if (index6 != bytes) { if (chunkSize < 2) throw new System.InvalidOperationException("unexpected thing just happened"); chunkSize -= chunkSize > 10 ? 3 : 1; } else goto label_56; } else goto label_55; } else goto label_57; } while (!MimeCommon.IsLowSurrogate(value[num20 + chunkSize])); } while (!MimeCommon.IsHighSurrogate(value[num20 + chunkSize - 1])); --chunkSize; } label_55: outputOffset += MimeCommon.Base64EncodeChunk(byteBuffer, 0, bytes, numArray7, outputOffset); label_56: var numArray11 = numArray7; var index10 = outputOffset; var num32 = 1; var num33 = index10 + num32; var num34 = 63; numArray11[index10] = (byte) num34; var numArray12 = numArray7; var index11 = num33; var num35 = 1; var num36 = index11 + num35; var num37 = 61; numArray12[index11] = (byte) num37; count = num36; label_57: num20 += chunkSize; } if (numArray7 != null) mimeStringList.Append(new MimeString(numArray7, 0, count)); return mimeStringList; }
internal MimeStringList GetEncodedValue(EncodingOptions encodingOptions, ValueEncodingStyle encodingStyle) { if (string.IsNullOrEmpty(decodedValue)) return this.Lines; return MimeCommon.EncodeValue(decodedValue, encodingOptions, encodingStyle); }
// 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); }