// Token: 0x0600030C RID: 780 RVA: 0x00011498 File Offset: 0x0000F698
        private int DecodeRfc2231Octets(bool decode, byte[] source, int sourceIndex, byte[] destination, int destinationIndex)
        {
            if (decode)
            {
                int num = destinationIndex;
                while (sourceIndex < source.Length)
                {
                    if (37 == source[sourceIndex] && sourceIndex + 2 < source.Length)
                    {
                        byte b = MimeParameter.DecodeHexadecimal(source[sourceIndex + 1]);
                        if (255 != b)
                        {
                            byte b2 = MimeParameter.DecodeHexadecimal(source[sourceIndex + 2]);
                            if (255 != b2)
                            {
                                sourceIndex += 3;
                                destination[destinationIndex++] = (byte)(((int)b << 4) + (int)b2);
                                continue;
                            }
                        }
                    }
                    destination[destinationIndex++] = source[sourceIndex++];
                }
                return(destinationIndex - num);
            }
            int num2 = source.Length - sourceIndex;

            Buffer.BlockCopy(source, sourceIndex, destination, destinationIndex, num2);
            return(num2);
        }
        // Token: 0x060002FB RID: 763 RVA: 0x00010840 File Offset: 0x0000EA40
        public sealed override void CopyTo(object destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }
            if (destination == this)
            {
                return;
            }
            MimeParameter mimeParameter = destination as MimeParameter;

            if (mimeParameter == null)
            {
                throw new ArgumentException(Strings.CantCopyToDifferentObjectType);
            }
            mimeParameter.AllowAppend = true;
            base.CopyTo(destination);
            mimeParameter.AllowAppend    = false;
            mimeParameter.valueEncoded   = this.valueEncoded;
            mimeParameter.segmentNumber  = this.segmentNumber;
            mimeParameter.valueFragments = this.valueFragments.Clone();
            mimeParameter.decodedValue   = this.decodedValue;
            mimeParameter.paramName      = this.paramName;
        }
        // Token: 0x060002FA RID: 762 RVA: 0x0001081C File Offset: 0x0000EA1C
        public sealed override MimeNode Clone()
        {
            MimeParameter mimeParameter = new MimeParameter(this.paramName);

            this.CopyTo(mimeParameter);
            return(mimeParameter);
        }
Пример #4
0
        private void WriteParameter(MimeParameter parameter)
        {
            if (this.lastHeader == null || !(this.lastHeader is ComplexHeader))
            {
                throw new InvalidOperationException(Strings.CannotWriteParametersOnThisHeader);
            }
            switch (this.state)
            {
            case MimeWriteState.Complete:
            case MimeWriteState.StartPart:
            case MimeWriteState.Recipients:
            case MimeWriteState.PartContent:
            case MimeWriteState.EndPart:
                throw new InvalidOperationException(Strings.CannotWriteParametersHere);
            }
            this.state = MimeWriteState.Parameters;
            ContentTypeHeader contentTypeHeader = this.lastHeader as ContentTypeHeader;

            if (contentTypeHeader != null && contentTypeHeader.IsMultipart && parameter.Name == "boundary")
            {
                string value = parameter.Value;
                if (value.Length == 0)
                {
                    throw new ArgumentException(Strings.CannotWriteEmptyOrNullBoundary);
                }
                this.currentPart.Boundary = ByteString.StringToBytes(value, false);
            }
            this.lastHeader.InternalAppendChild(parameter);
        }
        // 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: 0x060002FE RID: 766 RVA: 0x0001097F File Offset: 0x0000EB7F
 internal static string CorrectValue(string value)
 {
     if (-1 == value.IndexOfAny(MimeParameter.ControlCharacters))
     {
         return(value);
     }
     return(MimeParameter.CorrectValue(value.ToCharArray()));
 }
Пример #7
0
        internal void WriteMimeNode(MimeNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            Header header = node as Header;

            if (header != null)
            {
                this.WriteHeader(header);
                this.FlushHeader();
                return;
            }
            MimePart mimePart = node as MimePart;

            if (mimePart != null)
            {
                this.StartPart();
                mimePart.WriteTo(this.shimStream, this.encodingOptions);
                this.EndPart();
                return;
            }
            HeaderList headerList = node as HeaderList;

            if (headerList != null)
            {
                foreach (Header header2 in headerList)
                {
                    this.WriteHeader(header);
                }
                this.FlushHeader();
                return;
            }
            node = node.Clone();
            MimeRecipient mimeRecipient = node as MimeRecipient;

            if (mimeRecipient != null)
            {
                this.WriteRecipient(mimeRecipient);
                return;
            }
            MimeParameter mimeParameter = node as MimeParameter;

            if (mimeParameter != null)
            {
                this.WriteParameter(mimeParameter);
                return;
            }
            MimeGroup mimeGroup = node as MimeGroup;

            if (mimeGroup != null)
            {
                this.StartGroup(mimeGroup);
                this.EndGroup();
            }
        }
Пример #8
0
 // Token: 0x060001E0 RID: 480 RVA: 0x000087D8 File Offset: 0x000069D8
 private void EnsureBoundary()
 {
     if (base["boundary"] == null)
     {
         MimeParameter mimeParameter = new MimeParameter("boundary");
         base.InternalAppendChild(mimeParameter);
         mimeParameter.RawValue = ContentTypeHeader.CreateBoundary();
     }
 }
 // Token: 0x06000300 RID: 768 RVA: 0x000109E4 File Offset: 0x0000EBE4
 internal bool FallBackIfRequired(byte[] bytes, DecodingOptions decodingOptions, out string value)
 {
     if ((DecodingFlags.FallbackToRaw & decodingOptions.DecodingFlags) != DecodingFlags.None)
     {
         if (bytes == null)
         {
             value = string.Empty;
         }
         else
         {
             value = ByteString.BytesToString(bytes, decodingOptions.AllowUTF8);
             if ((DecodingFlags.AllowControlCharacters & decodingOptions.DecodingFlags) == DecodingFlags.None)
             {
                 value = MimeParameter.CorrectValue(value);
             }
         }
         return(true);
     }
     value = null;
     return(false);
 }
Пример #10
0
 private void FlushHeader()
 {
     this.headerValueWritten = false;
     if (this.lastHeader != null)
     {
         if (this.lastHeader.HeaderId == HeaderId.MimeVersion && this.partDepth == 1)
         {
             this.foundMimeVersion = true;
         }
         else if (this.lastHeader.HeaderId == HeaderId.ContentTransferEncoding)
         {
             string value = this.lastHeader.Value;
             if (value != null)
             {
                 this.contentTransferEncoding = MimePart.GetEncodingType(new MimeString(value));
             }
         }
         else if (this.lastHeader.HeaderId == HeaderId.ContentType)
         {
             ContentTypeHeader contentTypeHeader = this.lastHeader as ContentTypeHeader;
             if (contentTypeHeader.IsMultipart)
             {
                 this.currentPart.IsMultipart = true;
                 MimeParameter mimeParameter = contentTypeHeader["boundary"];
                 this.currentPart.Boundary = mimeParameter.RawValue;
             }
             else
             {
                 this.currentPart.IsMultipart = false;
             }
             this.currentPart.HasContentType = true;
         }
         this.lastHeader.WriteTo(this.shimStream, this.encodingOptions);
         this.lastHeader = null;
     }
 }
        // Token: 0x0600030B RID: 779 RVA: 0x000112A8 File Offset: 0x0000F4A8
        private bool TryDecodeRfc2231(ref DecodingOptions decodingOptions, out DecodingResults decodingResults, out string value)
        {
            decodingResults = default(DecodingResults);
            decodingResults.EncodingScheme = EncodingScheme.Rfc2231;
            Charset charset = null;

            byte[] sz  = this.valueFragments.GetSz(4026531839U);
            int    num = 0;

            if (this.valueEncoded)
            {
                int num2 = (sz == null) ? -1 : ByteString.IndexOf(sz, 39, 0, sz.Length);
                if (-1 < num2 && num2 < sz.Length - 1)
                {
                    int num3 = ByteString.IndexOf(sz, 39, ++num2, sz.Length - num2);
                    if (-1 < num3)
                    {
                        decodingResults.CharsetName = ByteString.BytesToString(sz, 0, num2 - 1, false);
                        decodingResults.CultureName = ByteString.BytesToString(sz, num2, num3 - num2, false);
                        if (!Charset.TryGetCharset(decodingResults.CharsetName, out charset))
                        {
                            decodingResults.DecodingFailed = true;
                            return(this.FallBackIfRequired(sz, decodingOptions, out value));
                        }
                        num = num3 + 1;
                    }
                }
            }
            if (charset == null)
            {
                charset = decodingOptions.Charset;
                if (charset == null)
                {
                    charset = DecodingOptions.DefaultCharset;
                }
            }
            decodingResults.CharsetName = charset.Name;
            Encoding encoding;

            if (!charset.TryGetEncoding(out encoding))
            {
                decodingResults.DecodingFailed = true;
                return(this.FallBackIfRequired(sz, decodingOptions, out value));
            }
            int num4 = this.valueFragments.Length - num;

            for (MimeNode mimeNode = base.FirstChild; mimeNode != null; mimeNode = mimeNode.NextSibling)
            {
                MimeParameter mimeParameter = mimeNode as MimeParameter;
                if (mimeParameter != null)
                {
                    num4 += mimeParameter.RawLength;
                }
            }
            byte[] array = new byte[num4];
            int    num5  = 0;

            if (sz != null && num < sz.Length)
            {
                num5 += this.DecodeRfc2231Octets(this.valueEncoded, sz, num, array, 0);
            }
            for (MimeNode mimeNode = base.FirstChild; mimeNode != null; mimeNode = mimeNode.NextSibling)
            {
                MimeParameter mimeParameter2 = mimeNode as MimeParameter;
                if (mimeParameter2 != null)
                {
                    byte[] rawValue = mimeParameter2.RawValue;
                    if (rawValue != null)
                    {
                        num5 += this.DecodeRfc2231Octets(mimeParameter2.valueEncoded, mimeParameter2.RawValue, 0, array, num5);
                    }
                }
            }
            value = ((num5 != 0) ? encoding.GetString(array, 0, num5) : string.Empty);
            if ((DecodingFlags.AllowControlCharacters & decodingOptions.DecodingFlags) == DecodingFlags.None)
            {
                value = MimeParameter.CorrectValue(value);
            }
            return(true);
        }
        // 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);
        }