MimeKit.MimeMessage.DkimWriteHeaderRelaxed C# (CSharp) Method

DkimWriteHeaderRelaxed() static private method

static private DkimWriteHeaderRelaxed ( MimeKit.FormatOptions options, Stream stream, Header header, bool isDkimSignature ) : void
options MimeKit.FormatOptions
stream Stream
header Header
isDkimSignature bool
return void
		static void DkimWriteHeaderRelaxed (FormatOptions options, Stream stream, Header header, bool isDkimSignature)
		{
			// o  Convert all header field names (not the header field values) to
			//    lowercase.  For example, convert "SUBJect: AbC" to "subject: AbC".
			var name = Encoding.ASCII.GetBytes (header.Field.ToLowerInvariant ());
			var rawValue = header.GetRawValue (options);
			int index = 0;

			// o  Delete any WSP characters remaining before and after the colon
			//    separating the header field name from the header field value.  The
			//    colon separator MUST be retained.
			stream.Write (name, 0, name.Length);
			stream.WriteByte ((byte) ':');

			// trim leading whitespace...
			while (index < rawValue.Length && rawValue[index].IsWhitespace ())
				index++;

			while (index < rawValue.Length) {
				int startIndex = index;

				// look for the first non-whitespace character
				while (index < rawValue.Length && rawValue[index].IsWhitespace ())
					index++;

				// o  Delete all WSP characters at the end of each unfolded header field
				//    value.
				if (index >= rawValue.Length)
					break;

				// o  Convert all sequences of one or more WSP characters to a single SP
				//    character.  WSP characters here include those before and after a
				//    line folding boundary.
				if (index > startIndex)
					stream.WriteByte ((byte) ' ');

				startIndex = index;

				while (index < rawValue.Length && !rawValue[index].IsWhitespace ())
					index++;

				if (index > startIndex)
					stream.Write (rawValue, startIndex, index - startIndex);
			}

			if (!isDkimSignature)
				stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
		}