Ejemplo n.º 1
0
		/// <summary>
		/// Writes the message to the specified output stream.
		/// </summary>
		/// <remarks>
		/// Writes the message to the output stream using the provided formatting options.
		/// </remarks>
		/// <param name="options">The formatting options.</param>
		/// <param name="stream">The output stream.</param>
		/// <param name="cancellationToken">A cancellation token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="options"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="stream"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		public void WriteTo (FormatOptions options, Stream stream, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (options == null)
				throw new ArgumentNullException ("options");

			if (stream == null)
				throw new ArgumentNullException ("stream");

			if (version == null && Body != null && Body.Headers.Count > 0)
				MimeVersion = new Version (1, 0);

			if (Body != null) {
				using (var filtered = new FilteredStream (stream)) {
					filtered.Add (options.CreateNewLineFilter ());

					foreach (var header in MergeHeaders ()) {
						if (options.HiddenHeaders.Contains (header.Id))
							continue;

						filtered.Write (header.RawField, 0, header.RawField.Length, cancellationToken);
						filtered.Write (new [] { (byte) ':' }, 0, 1, cancellationToken);
						filtered.Write (header.RawValue, 0, header.RawValue.Length, cancellationToken);
					}

					filtered.Flush (cancellationToken);
				}

				var cancellable = stream as ICancellableStream;

				if (cancellable != null) {
					cancellable.Write (options.NewLineBytes, 0, options.NewLineBytes.Length, cancellationToken);
				} else {
					cancellationToken.ThrowIfCancellationRequested ();
					stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
				}

				try {
					Body.Headers.Suppress = true;
					Body.WriteTo (options, stream, cancellationToken);
				} finally {
					Body.Headers.Suppress = false;
				}
			} else {
				Headers.WriteTo (options, stream, cancellationToken);
			}
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Writes the message to the specified output stream.
		/// </summary>
		/// <remarks>
		/// Writes the message to the output stream using the provided formatting options.
		/// </remarks>
		/// <param name="options">The formatting options.</param>
		/// <param name="stream">The output stream.</param>
		/// <param name="cancellationToken">A cancellation token.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <para><paramref name="options"/> is <c>null</c>.</para>
		/// <para>-or-</para>
		/// <para><paramref name="stream"/> is <c>null</c>.</para>
		/// </exception>
		/// <exception cref="System.OperationCanceledException">
		/// The operation was canceled via the cancellation token.
		/// </exception>
		/// <exception cref="System.IO.IOException">
		/// An I/O error occurred.
		/// </exception>
		public void WriteTo (FormatOptions options, Stream stream, CancellationToken cancellationToken = default (CancellationToken))
		{
			if (options == null)
				throw new ArgumentNullException ("options");

			if (stream == null)
				throw new ArgumentNullException ("stream");

			if (version == null && Body != null && Body.Headers.Count > 0)
				MimeVersion = new Version (1, 0);

			if (Body == null) {
				Headers.WriteTo (options, stream, cancellationToken);

				cancellationToken.ThrowIfCancellationRequested ();
				stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
			} else {
				cancellationToken.ThrowIfCancellationRequested ();

				using (var filtered = new FilteredStream (stream)) {
					filtered.Add (options.CreateNewLineFilter ());

					foreach (var header in MergeHeaders ()) {
						if (options.HiddenHeaders.Contains (header.Id))
							continue;

						cancellationToken.ThrowIfCancellationRequested ();

						var name = Encoding.ASCII.GetBytes (header.Field);

						filtered.Write (name, 0, name.Length);
						filtered.WriteByte ((byte) ':');
						filtered.Write (header.RawValue, 0, header.RawValue.Length);
					}

					filtered.Flush ();
				}

				options.WriteHeaders = false;
				Body.WriteTo (options, stream, cancellationToken);
			}
		}
Ejemplo n.º 3
0
		Stream GetResponseStream (ImapReplayCommand command)
		{
			MemoryStream memory;

			if (testUnixFormat) {
				memory = new MemoryStream ();

				using (var filtered = new FilteredStream (memory)) {
					filtered.Add (new Dos2UnixFilter ());
					filtered.Write (command.Response, 0, command.Response.Length);
					filtered.Flush ();
				}

				memory.Position = 0;
			} else {
				memory = new MemoryStream (command.Response, false);
			}

			return memory;
		}
Ejemplo n.º 4
0
        /// <summary>
        /// Writes the message to the specified stream.
        /// </summary>
        /// <param name="options">The formatting options.</param>
        /// <param name="stream">The stream.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <para><paramref name="options"/> is <c>null</c>.</para>
        /// <para>-or-</para>
        /// <para><paramref name="stream"/> is <c>null</c>.</para>
        /// </exception>
        public void WriteTo(FormatOptions options, Stream stream)
        {
            if (options == null)
                throw new ArgumentNullException ("options");

            if (stream == null)
                throw new ArgumentNullException ("stream");

            if (!Headers.Contains ("Date"))
                Date = DateTimeOffset.Now;

            if (messageId == null)
                MessageId = MimeUtils.GenerateMessageId ();

            if (version == null && Body != null && Body.Headers.Count > 0)
                MimeVersion = new Version (1, 0);

            if (Body == null) {
                Headers.WriteTo (stream);

                stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
            } else {
                using (var filtered = new FilteredStream (stream)) {
                    filtered.Add (options.CreateNewLineFilter ());

                    foreach (var header in MergeHeaders ()) {
                        var name = Encoding.ASCII.GetBytes (header.Field);

                        filtered.Write (name, 0, name.Length);
                        filtered.WriteByte ((byte) ':');
                        filtered.Write (header.RawValue, 0, header.RawValue.Length);
                    }

                    filtered.Flush ();
                }

                options.WriteHeaders = false;
                Body.WriteTo (options, stream);
            }
        }