// 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; }
// 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); }
// 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); }