本文整理汇总了C#中InternetAddressList类的典型用法代码示例。如果您正苦于以下问题:C# InternetAddressList类的具体用法?C# InternetAddressList怎么用?C# InternetAddressList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InternetAddressList类属于命名空间,在下文中一共展示了InternetAddressList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: MimeMessage
internal MimeMessage (ParserOptions options, IEnumerable<Header> headers)
{
addresses = new Dictionary<string, InternetAddressList> (icase);
Headers = new HeaderList (options);
// initialize our address lists
foreach (var name in StandardAddressHeaders) {
var list = new InternetAddressList ();
list.Changed += InternetAddressListChanged;
addresses.Add (name, list);
}
references = new MessageIdList ();
references.Changed += ReferencesChanged;
inreplyto = null;
Headers.Changed += HeadersChanged;
// add all of our message headers...
foreach (var header in headers) {
if (header.Field.StartsWith ("Content-", StringComparison.OrdinalIgnoreCase))
continue;
Headers.Add (header);
}
}
示例3: TestSimpleAddrSpec
public void TestSimpleAddrSpec ()
{
var expected = new InternetAddressList ();
var mailbox = new MailboxAddress ("", "");
InternetAddressList result;
string text;
expected.Add (mailbox);
text = "[email protected]";
mailbox.Address = "[email protected]";
Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
AssertInternetAddressListsEqual (text, expected, result);
result = InternetAddressList.Parse (text);
AssertInternetAddressListsEqual (text, expected, result);
text = "fejj";
mailbox.Address = "fejj";
Assert.IsTrue (InternetAddressList.TryParse (text, out result), "Failed to parse: {0}", text);
AssertInternetAddressListsEqual (text, expected, result);
result = InternetAddressList.Parse (text);
AssertInternetAddressListsEqual (text, expected, result);
}
示例4: AssertParse
static void AssertParse (string text, string encoded, InternetAddressList expected)
{
var buffer = Encoding.UTF8.GetBytes (text);
InternetAddressList result = null;
try {
result = InternetAddressList.Parse (text);
} catch {
Assert.Fail ("Parse(string): {0}", text);
}
AssertInternetAddressListsEqual (encoded, expected, result);
try {
result = InternetAddressList.Parse (buffer);
} catch {
Assert.Fail ("Parse(byte[]): {0}", text);
}
AssertInternetAddressListsEqual (encoded, expected, result);
try {
result = InternetAddressList.Parse (buffer, 0);
} catch {
Assert.Fail ("Parse(byte[], int): {0}", text);
}
AssertInternetAddressListsEqual (encoded, expected, result);
try {
result = InternetAddressList.Parse (buffer, 0, buffer.Length);
} catch {
Assert.Fail ("Parse(byte[], int, int): {0}", text);
}
AssertInternetAddressListsEqual (encoded, expected, result);
}
示例5: Envelope
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.Envelope"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="Envelope"/>.
/// </remarks>
public Envelope ()
{
From = new InternetAddressList ();
Sender = new InternetAddressList ();
ReplyTo = new InternetAddressList ();
To = new InternetAddressList ();
Cc = new InternetAddressList ();
Bcc = new InternetAddressList ();
}
示例6: 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);
}
}
示例7: 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");
}
示例8: AssertTryParse
static void AssertTryParse (string text, string encoded, InternetAddressList expected)
{
var buffer = Encoding.UTF8.GetBytes (text);
InternetAddressList result;
Assert.IsTrue (InternetAddressList.TryParse (text, out result), "TryParse(string): {0}", text);
AssertInternetAddressListsEqual (encoded, expected, result);
Assert.IsTrue (InternetAddressList.TryParse (buffer, out result), "TryParse(byte[]): {0}", text);
AssertInternetAddressListsEqual (encoded, expected, result);
Assert.IsTrue (InternetAddressList.TryParse (buffer, 0, out result), "TryParse(byte[], int): {0}", text);
AssertInternetAddressListsEqual (encoded, expected, result);
Assert.IsTrue (InternetAddressList.TryParse (buffer, 0, buffer.Length, out result), "TryParse(byte[] int, int): {0}", text);
AssertInternetAddressListsEqual (encoded, expected, result);
}
示例9: TestArgumentExceptions
public void TestArgumentExceptions ()
{
var mailbox = new MailboxAddress ("MimeKit Unit Tests", "[email protected]");
var list = new InternetAddressList ();
list.Add (new MailboxAddress ("Example User", "[email protected]"));
Assert.Throws<ArgumentNullException> (() => new InternetAddressList (null));
Assert.Throws<ArgumentNullException> (() => list.Add (null));
Assert.Throws<ArgumentNullException> (() => list.AddRange (null));
Assert.Throws<ArgumentNullException> (() => list.CompareTo (null));
Assert.Throws<ArgumentNullException> (() => list.Contains (null));
Assert.Throws<ArgumentNullException> (() => list.CopyTo (null, 0));
Assert.Throws<ArgumentOutOfRangeException> (() => list.CopyTo (new InternetAddress[0], -1));
Assert.Throws<ArgumentNullException> (() => list.IndexOf (null));
Assert.Throws<ArgumentOutOfRangeException> (() => list.Insert (-1, mailbox));
Assert.Throws<ArgumentNullException> (() => list.Insert (0, null));
Assert.Throws<ArgumentNullException> (() => list.Remove (null));
Assert.Throws<ArgumentOutOfRangeException> (() => list.RemoveAt (-1));
Assert.Throws<ArgumentOutOfRangeException> (() => list[-1] = mailbox);
Assert.Throws<ArgumentNullException> (() => list[0] = null);
}
示例10: TestEquality
public void TestEquality ()
{
var list1 = new InternetAddressList ();
list1.Add (new GroupAddress ("Local recipients", new InternetAddress[] {
new MailboxAddress ("", "phil"),
new MailboxAddress ("", "joe"),
new MailboxAddress ("", "alex"),
new MailboxAddress ("", "bob"),
}));
list1.Add (new MailboxAddress ("Joey", "[email protected]"));
list1.Add (new MailboxAddress ("Chandler", "[email protected]"));
var list2 = new InternetAddressList ();
list2.Add (new MailboxAddress ("Chandler", "[email protected]"));
list2.Add (new GroupAddress ("Local recipients", new InternetAddress[] {
new MailboxAddress ("", "phil"),
new MailboxAddress ("", "joe"),
new MailboxAddress ("", "alex"),
new MailboxAddress ("", "bob"),
}));
list2.Add (new MailboxAddress ("Joey", "[email protected]"));
Assert.IsTrue (list1.Equals (list2), "The 2 lists should be equal.");
}
示例11: 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);
}
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}