/// <summary> /// Gets attachment stream. /// </summary> /// <returns>Returns attachment stream.</returns> internal Stream GetStream() { if (m_pStream == null) { m_pStream = File.OpenRead(m_FileName); } if (m_ZipCompress) { #if NET20 || NET35 || NET40 throw new InvalidOperationException("Not supported lower framework version than 4.5."); #else SwapableStream retVal = new SwapableStream(); using (ZipArchive archive = new ZipArchive(retVal, ZipArchiveMode.Create)){ ZipArchiveEntry entry = archive.CreateEntry(m_Name, CompressionLevel.Optimal); using (Stream zipStream = entry.Open()){ Net_Utils.StreamCopy(m_pStream, zipStream, 64000); } } retVal.Position = 0; CloseStream(); return(retVal); #endif } return(m_pStream); }
/// <summary> /// Sets body data from the specified stream. /// </summary> /// <param name="stream">Source stream.</param> /// <param name="transferEncoding">Specifies content-transfer-encoding to use to encode data.</param> /// <exception cref="ArgumentNullException">Is raised when <b>stream</b> or <b>transferEncoding</b> is null reference.</exception> /// <exception cref="InvalidOperationException">Is raised when this method is accessed and this body is not bounded to any entity.</exception> public void SetData(Stream stream, string transferEncoding) { if (stream == null) { throw new ArgumentNullException("stream"); } if (transferEncoding == null) { throw new ArgumentNullException("transferEncoding"); } if (string.Equals(transferEncoding, MIME_TransferEncodings.QuotedPrintable, StringComparison.InvariantCultureIgnoreCase)) { using (SwapableStream fs = new SwapableStream()){ QuotedPrintableStream encoder = new QuotedPrintableStream(new SmartStream(fs, false), FileAccess.ReadWrite); Net_Utils.StreamCopy(stream, encoder, 84000); encoder.Flush(); fs.Position = 0; SetEncodedData(transferEncoding, fs); } } else if (string.Equals(transferEncoding, MIME_TransferEncodings.Base64, StringComparison.InvariantCultureIgnoreCase)) { using (SwapableStream fs = new SwapableStream()){ Base64Stream encoder = new Base64Stream(fs, false, true, FileAccess.ReadWrite); Net_Utils.StreamCopy(stream, encoder, 84000); encoder.Finish(); fs.Position = 0; SetEncodedData(transferEncoding, fs); } } else if (string.Equals(transferEncoding, MIME_TransferEncodings.Binary, StringComparison.InvariantCultureIgnoreCase)) { SetEncodedData(transferEncoding, stream); } else if (string.Equals(transferEncoding, MIME_TransferEncodings.EightBit, StringComparison.InvariantCultureIgnoreCase)) { SetEncodedData(transferEncoding, stream); } else if (string.Equals(transferEncoding, MIME_TransferEncodings.SevenBit, StringComparison.InvariantCultureIgnoreCase)) { SetEncodedData(transferEncoding, stream); } else { throw new NotSupportedException("Not supported Content-Transfer-Encoding '" + transferEncoding + "'."); } }