Example #1
0
 public void TestGetDate()
 {
     var msg = new Message();
       int[] date;
       msg.SetHeader("date", "Sat, 1 Jan 2000 12:34:56 +1034");
       date = msg.GetDate();
       Assert.AreEqual(2000, date[0]);
       Assert.AreEqual(1, date[1]);
       Assert.AreEqual(1, date[2]);
       Assert.AreEqual(12, date[3]);
       Assert.AreEqual(34, date[4]);
       Assert.AreEqual(56, date[5]);
       Assert.AreEqual(0, date[6]);
       Assert.AreEqual(10 * 60 + 34, date[7]);
       msg.SetHeader("date", "Mon, 1 Jan 1900 23:59:60 -1034");
       date = msg.GetDate();
       Assert.AreEqual(1900, date[0]);
       Assert.AreEqual(1, date[1]);
       Assert.AreEqual(1, date[2]);
       Assert.AreEqual(23, date[3]);
       Assert.AreEqual(59, date[4]);
       Assert.AreEqual(60, date[5]);
       Assert.AreEqual(0, date[6]);
       Assert.AreEqual(-(10 * 60 + 34), date[7]);
       msg.SetHeader("date", "Sun, 1 Jan 2000 12:34:56 +1034");
       if (msg.GetDate() != null) {
      Assert.Fail();
      }
       msg.SetHeader("date", "1 Jan 2000 12:34:56 +1034");
       date = msg.GetDate();
       Assert.AreEqual(2000, date[0]);
       Assert.AreEqual(1, date[1]);
       Assert.AreEqual(1, date[2]);
       msg.SetHeader("date", "32 Jan 2000 12:34:56 +1034");
       if (msg.GetDate() != null) {
      Assert.Fail();
      }
       msg.SetHeader("date", "30 Feb 2000 12:34:56 +1034");
       if (msg.GetDate() != null) {
      Assert.Fail();
      }
       msg.SetHeader("date", "1 Feb 999999999999999999999 12:34:56 +1034");
       if (msg.GetDate() != null) {
      Assert.Fail();
      }
       msg.SetHeader("date", "1 Jan 2000 24:34:56 +1034");
       if (msg.GetDate() != null) {
      Assert.Fail();
      }
       msg.SetHeader("date", "1 Jan 2000 01:60:56 +1034");
       if (msg.GetDate() != null) {
      Assert.Fail();
      }
       msg.SetHeader("date", "1 Jan 2000 01:01:61 +1034");
       if (msg.GetDate() != null) {
      Assert.Fail();
      }
       msg.SetHeader("date", "1 Jan 2000 01:01:01 +1099");
       if (msg.GetDate() != null) {
      Assert.Fail();
      }
 }
Example #2
0
 public void TestReceivedHeader()
 {
     var msg = new Message();
       string tmp =
     "from x.y.example by a.b.example; Thu, 31 Dec 2012 00:00:00 -0100";
       msg.SetHeader("received", tmp);
 }
Example #3
0
 public void TestContentHeadersOnlyInBodyParts()
 {
     var msg = new Message().SetTextAndHtml("Hello", "Hello");
       msg.SetHeader("x-test", "test");
       msg.Parts[0].SetHeader("x-test", "test");
       {
     string stringTemp = msg.GetHeader("x-test");
     Assert.AreEqual(
       "test",
       stringTemp);
       }
       {
     string stringTemp = msg.Parts[0].GetHeader("x-test");
     Assert.AreEqual(
       "test",
       stringTemp);
       }
       msg = MessageFromString(msg.Generate());
       {
     string stringTemp = msg.GetHeader("x-test");
     Assert.AreEqual(
       "test",
       stringTemp);
       }
       Assert.AreEqual(null, msg.Parts[0].GetHeader("x-test"));
 }
Example #4
0
 public void TestHeaderParsing()
 {
     string tmp;
       tmp = " A Xxxxx: Yyy Zzz <*****@*****.**>;";
       var msg = new Message();
       try {
     msg.SetHeader("to", tmp);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       tmp = "\"Me\" <1234>";
       // just a local part in address
       try {
     msg.SetHeader("to", tmp);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       tmp = "<*****@*****.**>";
       try {
     msg.SetHeader("to", tmp);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       tmp = "<x [email protected]>";  // local part is not a dot-atom
       try {
     msg.SetHeader("to", tmp);
     Assert.Fail("Should have failed");
       } catch (ArgumentException) {
     new Object();
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       tmp = " <*****@*****.**>";
       try {
     msg.SetHeader("to", tmp);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       // Group syntax
       tmp = "G:;";
       try {
     msg.SetHeader("to", tmp);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       tmp = "G:a <*****@*****.**>;";
       try {
     msg.SetHeader("to", tmp);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       tmp = " A Xxxxx: ;";
       try {
     msg.SetHeader("to", tmp);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
       tmp = " A Xxxxx: Yyy Zzz <*****@*****.**>, [email protected], Ww <*****@*****.**>;";
       try {
     msg.SetHeader("to", tmp);
       } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
       }
 }