Example #1
0
        void Initialize(Stream stream, string startInfo, string boundary, string startUri, bool writeMessageHeaders, bool ownsStream)
        {
            if (stream == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
            if (startInfo == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("startInfo");
            if (boundary == null)
                boundary = GetBoundaryString();
            if (startUri == null)
                startUri = GenerateUriForMimePart(0);
            if (!MailBnfHelper.IsValidMimeBoundary(boundary))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MtomBoundaryInvalid, boundary), "boundary"));

            this.ownsStream = ownsStream;
            this.isClosed = false;
            this.depth = 0;
            this.totalSizeOfMimeParts = 0;
            this.sizeOfBufferedBinaryData = 0;
            this.binaryDataChunks = null;
            this.contentType = null;
            this.contentTypeStream = null;
            this.contentID = startUri;
            if (this.mimeParts != null)
                this.mimeParts.Clear();
            this.mimeWriter = new MimeWriter(stream, boundary);
            this.initialContentTypeForRootPart = GetContentTypeForRootMimePart(this.encoding, startInfo);
            if (writeMessageHeaders)
                this.initialContentTypeForMimeMessage = GetContentTypeForMimeMessage(boundary, startUri, startInfo);
        }
Example #2
0
        internal MimeWriter(Stream stream, string boundary)
        {
            if (stream == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
            if (boundary == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("boundary");

            this.stream = stream;
            this.boundaryBytes = MimeWriter.GetBoundaryBytes(boundary);
            this.state = MimeWriterState.Start;
            this.bufferedWrite = new BufferedWrite();
        }
 public MimeReader(Stream stream, string boundary)
 {
     if (stream == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
     }
     if (boundary == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("boundary");
     }
     this.reader        = new DelimittedStreamReader(stream);
     this.boundaryBytes = MimeWriter.GetBoundaryBytes(boundary);
     this.reader.Push(this.boundaryBytes, 0, 2);
 }
 private void Initialize(Stream stream, string startInfo, string boundary, string startUri, bool writeMessageHeaders, bool ownsStream)
 {
     if (stream == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream");
     }
     if (startInfo == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("startInfo");
     }
     if (boundary == null)
     {
         boundary = GetBoundaryString();
     }
     if (startUri == null)
     {
         startUri = GenerateUriForMimePart(0);
     }
     if (!MailBnfHelper.IsValidMimeBoundary(boundary))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.Runtime.Serialization.SR.GetString("MtomBoundaryInvalid", new object[] { boundary }), "boundary"));
     }
     this.ownsStream = ownsStream;
     this.isClosed = false;
     this.depth = 0;
     this.totalSizeOfMimeParts = 0;
     this.sizeOfBufferedBinaryData = 0;
     this.binaryDataChunks = null;
     this.contentType = null;
     this.contentTypeStream = null;
     this.contentID = startUri;
     if (this.mimeParts != null)
     {
         this.mimeParts.Clear();
     }
     this.mimeWriter = new MimeWriter(stream, boundary);
     this.initialContentTypeForRootPart = GetContentTypeForRootMimePart(this.encoding, startInfo);
     if (writeMessageHeaders)
     {
         this.initialContentTypeForMimeMessage = GetContentTypeForMimeMessage(boundary, startUri, startInfo);
     }
 }
Example #5
0
 static int GetSize(string contentID, string contentType, string contentTransferEncoding, int sizeOfBufferedBinaryData, int maxSizeInBytes)
 {
     int size = XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, 0, MimeGlobals.CRLF.Length * 3);
     if (contentTransferEncoding != null)
         size += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, size, MimeWriter.GetHeaderSize(MimeGlobals.ContentTransferEncodingHeader, contentTransferEncoding, maxSizeInBytes));
     if (contentType != null)
         size += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, size, MimeWriter.GetHeaderSize(MimeGlobals.ContentTypeHeader, contentType, maxSizeInBytes));
     if (contentID != null)
     {
         size += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, size, MimeWriter.GetHeaderSize(MimeGlobals.ContentIDHeader, contentID, maxSizeInBytes));
         size += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, size, 2); // include '<' and '>'
     }
     size += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, size, sizeOfBufferedBinaryData);
     return size;
 }
Example #6
0
            private static int GetSize(string contentID, string contentType, string contentTransferEncoding, int sizeOfBufferedBinaryData, int maxSizeInBytes)
            {
                int offset = XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, 0, MimeGlobals.CRLF.Length * 3);

                if (contentTransferEncoding != null)
                {
                    offset += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, offset, MimeWriter.GetHeaderSize(MimeGlobals.ContentTransferEncodingHeader, contentTransferEncoding, maxSizeInBytes));
                }
                if (contentType != null)
                {
                    offset += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, offset, MimeWriter.GetHeaderSize(MimeGlobals.ContentTypeHeader, contentType, maxSizeInBytes));
                }
                if (contentID != null)
                {
                    offset += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, offset, MimeWriter.GetHeaderSize(MimeGlobals.ContentIDHeader, contentID, maxSizeInBytes));
                    offset += XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, offset, 2);
                }
                return(offset + XmlMtomWriter.ValidateSizeOfMessage(maxSizeInBytes, offset, sizeOfBufferedBinaryData));
            }