Esempio n. 1
0
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.NamedAddress.#ctor(System.String,PeterO.Mail.Address)"]/*'/>
 public NamedAddress(string displayName, Address address)
 {
     if (address == null) {
     throw new ArgumentNullException("address");
       }
       this.displayName = displayName;
       this.groupAddresses = new List<NamedAddress>();
       this.address = address;
       this.isGroup = false;
 }
Esempio n. 2
0
 public void TestLocalPart() {
   var addr = new Address("*****@*****.**");
   Assert.AreEqual("local.local", addr.LocalPart);
   TestParseLocalPart("x", "x");
   TestParseLocalPart("\"" + "\"", String.Empty);
   TestParseLocalPart("x.example", "x.example");
   TestParseLocalPart("x.example\ud800\udc00.example.com",
                 "x.example\ud800\udc00.example.com");
   TestParseLocalPart("x.example.com", "x.example.com");
   TestParseLocalPart("\"(not a comment)\"", "(not a comment)");
   TestParseLocalPart("(comment1) x (comment2)", "x");
   TestParseLocalPart("(comment1) example (comment2) . (comment3) com",
                 "example.com");
 }
Esempio n. 3
0
 public void TestDomain() {
   var addr = new Address("*****@*****.**");
   Assert.AreEqual("example.com",addr.Domain);
   TestParseDomain("x", "x");
   TestParseDomain("x.example", "x.example");
   TestParseDomain("x.example\ud800\udc00.example.com",
                 "x.example\ud800\udc00.example.com");
   TestParseDomain("x.example.com", "x.example.com");
   TestParseDomain("(comment1) x (comment2)", "x");
   TestParseDomain("(comment1) example (comment2) . (comment3) com",
                 "example.com");
   TestParseDomain("(comment1) [x] (comment2)", "[x]");
   TestParseDomain("(comment1) [a.b.c.d] (comment2)", "[a.b.c.d]");
   TestParseDomain("[]", "[]");
   TestParseDomain("[a .\r\n b. c.d ]", "[a.b.c.d]");
 }
Esempio n. 4
0
 public void TestConstructor()
 {
     try {
     Assert.AreEqual(null, new Address("local=domain.example"));
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     Assert.AreEqual(null, new Address("local@"));
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     {
     object objectTemp = null;
     object objectTemp2 = new Address(EncodingTest.Repeat("local", 200) +
       "@example.com");
     Assert.AreEqual(objectTemp, objectTemp2);
     }
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       try {
     Assert.AreEqual(null, new Address("lo,[email protected]"));
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
 }
Esempio n. 5
0
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.NamedAddress.#ctor(System.String)"]/*'/>
 public NamedAddress(string address)
 {
     if (address == null) {
     throw new ArgumentNullException("address");
       }
       var tokener = new Tokener();
       if (HeaderParser.ParseAddress(address, 0, address.Length, tokener) !=
     address.Length) {
     throw new ArgumentException("Address has an invalid syntax.");
       }
       NamedAddress na = HeaderParserUtility.ParseAddress(
       address,
       0,
       address.Length,
       tokener.GetTokens());
       if (na == null) {
     throw new ArgumentException("Address has an invalid syntax.");
       }
       this.displayName = na.displayName;
       this.address = na.address;
       this.groupAddresses = na.groupAddresses;
       this.isGroup = na.isGroup;
 }
Esempio n. 6
0
    public void TestToString() {
      var addr = new Address("*****@*****.**");
      {
string stringTemp = addr.ToString();
Assert.AreEqual(
"*****@*****.**",
stringTemp);
}
    }
Esempio n. 7
0
        public void TestNamedAddress()
        {
            {
            object objectTemp = "\"Me \" <*****@*****.**>";
            object objectTemp2 = new NamedAddress(
              "Me ",
              "*****@*****.**").ToString();
            Assert.AreEqual(objectTemp, objectTemp2);
            }
              {
            object objectTemp = "\" Me\" <*****@*****.**>";
            object objectTemp2 = new NamedAddress(
              " Me",
              "*****@*****.**").ToString();
            Assert.AreEqual(objectTemp, objectTemp2);
            }

              try {
            Assert.AreEqual(null, new Address(String.Empty));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new Address("a [email protected]"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new NamedAddress("a [email protected]"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new NamedAddress("ab.example.com"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new Address("ab@exa mple.example"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new Address("[email protected] addr"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            {
              string stringTemp = new
                    NamedAddress("Me <*****@*****.**>").ToString();
              Assert.AreEqual(
              "Me <*****@*****.**>",
              stringTemp);
            }
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            if ((new NamedAddress("Me\u00e0 <*****@*****.**>")) == null) {
              Assert.Fail();
            }
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            if ((new NamedAddress("\"Me\" <*****@*****.**>")) == null) {
              Assert.Fail();
            }
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            if ((new NamedAddress("\"Me\u00e0\" <*****@*****.**>")) == null) {
              Assert.Fail();
            }
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new Address("Me <*****@*****.**>"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new Address("Me\u00e0 <*****@*****.**>"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new Address("\"Me\" <*****@*****.**>"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            Assert.AreEqual(null, new Address("\"Me\u00e0\" <*****@*****.**>"));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              try {
            const string ValueSt = "Me <*****@*****.**>, Fred <*****@*****.**>";
            Assert.AreEqual(null, new NamedAddress(ValueSt));
            Assert.Fail("Should have failed");
              } catch (ArgumentException) {
            new Object();
              } catch (Exception ex) {
            Assert.Fail(ex.ToString());
            throw new InvalidOperationException(String.Empty, ex);
              }
              Assert.IsFalse(new NamedAddress("*****@*****.**").IsGroup);
              {
            string stringTemp = new NamedAddress("*****@*****.**").Name;
            Assert.AreEqual(
              "*****@*****.**",
              stringTemp);
              }
              {
            string stringTemp = new NamedAddress(
                "*****@*****.**").Address.ToString();
            Assert.AreEqual(
            "*****@*****.**",
            stringTemp);
              }
              Assert.AreEqual(
              "\"(lo cal)\"@example.com",
              new Address("\"(lo cal)\"@example.com").ToString());
              {
            string stringTemp = new Address("*****@*****.**").LocalPart;
            Assert.AreEqual(
              "local",
              stringTemp);
              }
              {
            string stringTemp = new Address("*****@*****.**").Domain;
            Assert.AreEqual(
              "example.com",
              stringTemp);
              }
        }
Esempio n. 8
0
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.NamedAddress.#ctor(System.String,System.Collections.Generic.IList{PeterO.Mail.NamedAddress})"]/*'/>
 public NamedAddress(string groupName, IList<NamedAddress> mailboxes) {
   if (groupName == null) {
     throw new ArgumentNullException("groupName");
   }
   if (groupName.Length == 0) {
     throw new ArgumentException("groupName is empty.");
   }
   if (mailboxes == null) {
     throw new ArgumentNullException("mailboxes");
   }
   this.isGroup = true;
   this.name = groupName;
   foreach (NamedAddress mailbox in mailboxes) {
     if (mailbox.IsGroup) {
       throw new ArgumentException("A mailbox in the list is a group");
     }
   }
   this.address = null;
   this.groupAddresses = new List<NamedAddress>(mailboxes);
 }
Esempio n. 9
0
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.NamedAddress.#ctor(System.String,System.String,System.String)"]/*'/>
 public NamedAddress(string displayName, string localPart, string domain) {
   if (localPart == null) {
     throw new ArgumentNullException("localPart");
   }
   if (domain == null) {
     throw new ArgumentNullException("domain");
   }
   this.address = new Address(localPart, domain);
   if (String.IsNullOrEmpty(displayName)) {
     displayName = this.address.ToString();
   }
   this.groupAddresses = new List<NamedAddress>();
   this.name = displayName;
   this.isGroup = false;
 }
Esempio n. 10
0
 /// <include file='../../docs.xml'
 /// path='docs/doc[@name="M:PeterO.Mail.NamedAddress.#ctor(System.String,PeterO.Mail.Address)"]/*'/>
 public NamedAddress(string displayName, Address address) {
   if (address == null) {
     throw new ArgumentNullException("address");
   }
   if (String.IsNullOrEmpty(displayName)) {
     displayName = address.ToString();
   }
   this.name = displayName;
   this.groupAddresses = new List<NamedAddress>();
   this.address = address;
   this.isGroup = false;
 }