MimeKit.Header.EncodeDkimSignatureHeader C# (CSharp) Method

EncodeDkimSignatureHeader() static private method

static private EncodeDkimSignatureHeader ( ParserOptions options, MimeKit.FormatOptions format, Portable.Text.Encoding charset, string field, string value ) : byte[]
options ParserOptions
format MimeKit.FormatOptions
charset Portable.Text.Encoding
field string
value string
return byte[]
		static byte[] EncodeDkimSignatureHeader (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
		{
			var encoded = new StringBuilder ();
			int lineLength = field.Length + 1;
			var token = new StringBuilder ();
			int index = 0;

			while (index < value.Length) {
				while (index < value.Length && IsWhiteSpace (value[index]))
					index++;

				int startIndex = index;
				string name;

				while (index < value.Length && value[index] != '=') {
					if (!IsWhiteSpace (value[index]))
						token.Append (value[index]);
					index++;
				}

				name = value.Substring (startIndex, index - startIndex);

				while (index < value.Length && value[index] != ';') {
					if (!IsWhiteSpace (value[index]))
						token.Append (value[index]);
					index++;
				}

				if (index < value.Length && value[index] == ';') {
					token.Append (';');
					index++;
				}

				if (lineLength + token.Length + 1 > format.MaxLineLength || name == "bh" || name == "b") {
					encoded.Append (format.NewLine);
					encoded.Append ('\t');
					lineLength = 1;
				} else {
					encoded.Append (' ');
					lineLength++;
				}

				if (token.Length > format.MaxLineLength) {
					switch (name) {
					case "z":
						EncodeDkimHeaderList (format, encoded, ref lineLength, token.ToString (), '|');
						break;
					case "h":
						EncodeDkimHeaderList (format, encoded, ref lineLength, token.ToString (), ':');
						break;
					default:
						EncodeDkimLongValue (format, encoded, ref lineLength, token.ToString ());
						break;
					}
				} else {
					encoded.Append (token.ToString ());
					lineLength += token.Length;
				}

				token.Length = 0;
			}

			encoded.Append (format.NewLine);

			return charset.GetBytes (encoded.ToString ());
		}