本文整理汇总了C#中InternetAddressList.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# InternetAddressList.ToString方法的具体用法?C# InternetAddressList.ToString怎么用?C# InternetAddressList.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InternetAddressList
的用法示例。
在下文中一共展示了InternetAddressList.ToString方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEncodingMailboxWithArabicName
public void TestEncodingMailboxWithArabicName()
{
var mailbox = new MailboxAddress ("هل تتكلم اللغة الإنجليزية /العربية؟", "[email protected]");
var list = new InternetAddressList ();
list.Add (mailbox);
var expected = "=?utf-8?b?2YfZhCDYqtiq2YPZhNmFINin2YTZhNi62Kk=?=\n =?utf-8?b?INin2YTYpdmG2KzZhNmK2LLZitipIC/Yp9mE2LnYsdio2YrYqdif?=\n\t<[email protected]>";
var actual = list.ToString (UnixFormatOptions, true);
Assert.AreEqual (expected, actual, "Encoding arabic mailbox did not match expected result: {0}", expected);
Assert.IsTrue (InternetAddressList.TryParse (actual, out list), "Failed to parse arabic mailbox");
Assert.AreEqual (mailbox.Name, list[0].Name);
}
示例2: TestDecodedMailboxHasCorrectCharsetEncoding
public void TestDecodedMailboxHasCorrectCharsetEncoding()
{
var latin1 = Encoding.GetEncoding ("iso-8859-1");
var mailbox = new MailboxAddress (latin1, "Kristoffer Brånemyr", "[email protected]");
var list = new InternetAddressList ();
list.Add (mailbox);
var encoded = list.ToString (UnixFormatOptions, true);
InternetAddressList parsed;
Assert.IsTrue (InternetAddressList.TryParse (encoded, out parsed), "Failed to parse address");
Assert.AreEqual (latin1.HeaderName, parsed[0].Encoding.HeaderName, "Parsed charset does not match");
}
示例3: AssertInternetAddressListsEqual
static void AssertInternetAddressListsEqual (string text, InternetAddressList expected, InternetAddressList result)
{
Assert.AreEqual (expected.Count, result.Count, "Unexpected number of addresses: {0}", text);
for (int i = 0; i < expected.Count; i++) {
Assert.AreEqual (expected.GetType (), result.GetType (), "Address #{0} differs in type: {1}", i, text);
Assert.AreEqual (expected[i].ToString (), result[i].ToString (), "Display strings differ for {0}", text);
}
var encoded = result.ToString (true).Replace ("\r\n", "\n");
Assert.AreEqual (text, encoded, "Encoded strings differ for {0}", text);
}
示例4: TestUnsupportedCharsetExceptionNotThrown
public void TestUnsupportedCharsetExceptionNotThrown ()
{
var mailbox = new MailboxAddress (Encoding.UTF8, "狂ったこの世で狂うなら気は確かだ。", "[email protected]");
var list = new InternetAddressList ();
list.Add (mailbox);
var encoded = list.ToString (true);
encoded = encoded.Replace ("utf-8", "x-unknown");
InternetAddressList parsed;
try {
Assert.IsTrue (InternetAddressList.TryParse (encoded, out parsed), "Failed to parse address");
} catch (Exception ex) {
Assert.Fail ("Exception thrown parsing address with unsupported charset: {0}", ex);
}
}
示例5: TestEncodingSimpleAddressList
public void TestEncodingSimpleAddressList ()
{
const string expectedEncoded = "Kristoffer =?iso-8859-1?q?Br=E5nemyr?= <[email protected]>, Jeffrey Stedfast\n\t<[email protected]>";
const string expectedDisplay = "\"Kristoffer Brånemyr\" <[email protected]>, \"Jeffrey Stedfast\" <[email protected]>";
var latin1 = Encoding.GetEncoding ("iso-8859-1");
var options = FormatOptions.Default.Clone ();
var list = new InternetAddressList ();
list.Add (new MailboxAddress (latin1, "Kristoffer Brånemyr", "[email protected]"));
list.Add (new MailboxAddress ("Jeffrey Stedfast", "[email protected]"));
options.NewLineFormat = NewLineFormat.Unix;
var display = list.ToString (options, false);
Assert.AreEqual (expectedDisplay, display, "Display value does not match the expected result: {0}", display);
var encoded = list.ToString (options, true);
Assert.AreEqual (expectedEncoded, encoded, "Encoded value does not match the expected result: {0}", display);
}
示例6: TestEncodingMailboxWithJapaneseName
public void TestEncodingMailboxWithJapaneseName ()
{
const string expected = "=?utf-8?b?54uC44Gj44Gf44GT44Gu5LiW44Gn54uC44GG44Gq44KJ5rCX44Gv56K644GL44Gg?=\n =?utf-8?b?44CC?= <[email protected]>";
var mailbox = new MailboxAddress ("狂ったこの世で狂うなら気は確かだ。", "[email protected]");
var list = new InternetAddressList ();
list.Add (mailbox);
var actual = list.ToString (UnixFormatOptions, true);
Assert.AreEqual (expected, actual, "Encoding japanese mailbox did not match expected result: {0}", expected);
Assert.IsTrue (InternetAddressList.TryParse (actual, out list), "Failed to parse japanese mailbox");
Assert.AreEqual (mailbox.Name, list[0].Name);
}
示例7: TestEncodingMailboxWithReallyLongWord
public void TestEncodingMailboxWithReallyLongWord ()
{
const string expected = "=?us-ascii?q?reeeeeeeeeeeeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaallllllllllll?=\n =?us-ascii?q?llllllllllllllllllllllllllllllllllllllllllly?= long word\n\t<[email protected]>";
const string name = "reeeeeeeeeeeeeeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaallllllllllllllllllllllllllllllllllllllllllllllllllllllly long word";
var mailbox = new MailboxAddress (name, "[email protected]");
var list = new InternetAddressList ();
list.Add (mailbox);
var actual = list.ToString (UnixFormatOptions, true);
Assert.AreEqual (expected, actual, "Encoding really long mailbox did not match expected result: {0}", expected);
Assert.IsTrue (InternetAddressList.TryParse (actual, out list), "Failed to parse really long mailbox");
Assert.AreEqual (mailbox.Name, list[0].Name);
}
示例8: TestEncodingSimpleMailboxWithLatin1Name
public void TestEncodingSimpleMailboxWithLatin1Name ()
{
var latin1 = Encoding.GetEncoding ("iso-8859-1");
var mailbox = new MailboxAddress (latin1, "Kristoffer Brånemyr", "[email protected]");
var list = new InternetAddressList ();
list.Add (mailbox);
var expected = "Kristoffer =?iso-8859-1?q?Br=E5nemyr?= <[email protected]>";
var actual = list.ToString (UnixFormatOptions, true);
Assert.AreEqual (expected, actual, "Encoding latin1 mailbox did not match expected result: {0}", expected);
mailbox = new MailboxAddress (latin1, "Tõivo Leedjärv", "[email protected]");
list = new InternetAddressList ();
list.Add (mailbox);
expected = "=?iso-8859-1?b?VIH1aXZvIExlZWRqgeRydg==?= <[email protected]>";
actual = list.ToString (UnixFormatOptions, true);
Assert.AreEqual (expected, actual, "Encoding latin1 mailbox did not match expected result: {0}", expected);
}
示例9: TestEncodingSimpleMailboxWithQuotedName
public void TestEncodingSimpleMailboxWithQuotedName ()
{
const string expected = "\"Stedfast, Jeffrey\" <[email protected]>";
var mailbox = new MailboxAddress ("Stedfast, Jeffrey", "[email protected]");
var list = new InternetAddressList ();
list.Add (mailbox);
var actual = list.ToString (UnixFormatOptions, true);
Assert.AreEqual (expected, actual, "Encoding quoted mailbox did not match expected result: {0}", expected);
}