Skip to content

Commit

Permalink
Simplified Header.SetValue(string charset, string value) and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Jun 22, 2024
1 parent c6f9fd9 commit 5bef376
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 1 addition & 6 deletions MimeKit/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1542,12 +1542,7 @@ public void SetValue (FormatOptions format, string charset, string value)
/// </exception>
public void SetValue (string charset, string value)
{
if (charset is null)
throw new ArgumentNullException (nameof (charset));

var encoding = CharsetUtils.GetEncoding (charset);

SetValue (FormatOptions.Default, encoding, value);
SetValue (FormatOptions.Default, charset, value);
}

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions UnitTests/HeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -930,5 +930,19 @@ public void TestReformatDispositionNotificationOptions ()

Assert.That (result, Is.EqualTo (value));
}

[Test]
public void TestSetValueCharset ()
{
var expected = " =?gb18030?b?suLK1M7Esb4=?=" + FormatOptions.Default.NewLine;
var header = new Header ("Subject", "");

header.SetValue ("GB18030", "测试文本");

var raw = ByteArrayToString (header.RawValue);

Assert.That (raw[raw.Length - 1], Is.EqualTo ('\n'), "The RawValue does not end with a new line.");
Assert.That (raw, Is.EqualTo (expected), $"The encoded header does not match the expected value: {raw}");
}
}
}

0 comments on commit 5bef376

Please sign in to comment.