static IDictionary<string, string> ParseDkimSignature (string signature)
{
var parameters = new Dictionary<string, string> ();
foreach (var token in signature.Split (';')) {
var value = new StringBuilder ();
int startIndex, index = 0;
string name;
while (index < token.Length && IsWhiteSpace (token[index]))
index++;
startIndex = index;
while (index < token.Length && token[index] != '=')
index++;
if (index + 1 >= token.Length)
continue;
name = token.Substring (startIndex, index - startIndex).Trim ();
index++;
while (index < token.Length) {
if (!IsWhiteSpace (token[index]))
value.Append (token[index]);
index++;
}
if (parameters.ContainsKey (name))
throw new FormatException (string.Format ("Malformed DKIM-Signature value: duplicate parameter '{0}'.", name));
parameters.Add (name, value.ToString ());
}
return parameters;
}