public Stream OpenWrite(string path, string contentType, Encoding encoding)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (archiveWriter == null)
            {
                throw new InvalidOperationException("The archive is not open.");
            }

            archiveWriter.WriteLine("Content-Type: {0}", contentType ?? MimeTypes.GetMimeTypeByExtension(Path.GetExtension(path)) ?? MimeTypes.Binary);
            archiveWriter.WriteLine("Content-Transfer-Encoding: base64");
            archiveWriter.WriteLine("Content-Location: file:///{0}", Uri.EscapeUriString(path.Replace('\\', '/')));
            archiveWriter.WriteLine();

            // FIXME: Buffering the whole stream in memory is not very efficient for large files.
            TemporaryMemoryStream stream = new TemporaryMemoryStream();

            stream.Closing += delegate
            {
                stream.Position = 0;
                archiveWriter.Write(Convert.ToBase64String(stream.GetBuffer(), 0, (int)stream.Length, Base64FormattingOptions.InsertLineBreaks));
                archiveWriter.WriteLine();
                archiveWriter.WriteLine(EscapedMessagePartBoundary);
            };

            return(stream);
        }
        /// <inheritdoc />
        public override Stream OpenWrite(string path, string contentType, Encoding encoding)
        {
            ValidateFilePath(path);
            OpenArchiveOutputStream();
            var zipEntry = new ZipEntry(path);

            zipEntry.DateTime = DateTime.Now;
            archiveOutputStream.PutNextEntry(zipEntry);
            var stream = new TemporaryMemoryStream();

            stream.Closing += delegate
            {
                stream.Position = 0;
                archiveOutputStream.Write(stream.GetBuffer(), 0, (int)stream.Length);
            };

            return(stream);
        }
        public Stream OpenWrite(string path, string contentType, Encoding encoding)
        {
            if (path == null)
                throw new ArgumentNullException("path");
            if (archiveWriter == null)
                throw new InvalidOperationException("The archive is not open.");

            archiveWriter.WriteLine("Content-Type: {0}", contentType ?? MimeTypes.GetMimeTypeByExtension(Path.GetExtension(path)) ?? MimeTypes.Binary);
            archiveWriter.WriteLine("Content-Transfer-Encoding: base64");
            archiveWriter.WriteLine("Content-Location: file:///{0}", Uri.EscapeUriString(path.Replace('\\', '/')));
            archiveWriter.WriteLine();

            // FIXME: Buffering the whole stream in memory is not very efficient for large files.
            TemporaryMemoryStream stream = new TemporaryMemoryStream();
            stream.Closing += delegate
            {
                stream.Position = 0;
                archiveWriter.Write(Convert.ToBase64String(stream.GetBuffer(), 0, (int) stream.Length, Base64FormattingOptions.InsertLineBreaks));
                archiveWriter.WriteLine();
                archiveWriter.WriteLine(EscapedMessagePartBoundary);
            };

            return stream;
        }
        /// <inheritdoc />
        public override Stream OpenWrite(string path, string contentType, Encoding encoding)
        {
            ValidateFilePath(path);
            OpenArchiveOutputStream();
            var zipEntry = new ZipEntry(path);
            zipEntry.DateTime = DateTime.Now;
            archiveOutputStream.PutNextEntry(zipEntry);
            var stream = new TemporaryMemoryStream();

            stream.Closing += delegate
            {
                stream.Position = 0;
                archiveOutputStream.Write(stream.GetBuffer(), 0, (int)stream.Length);
            };

            return stream;
        }