예제 #1
0
 /** Test subject */
 public void testSubject() throws Exception {
   assertEquals("test message", simple.getSubject());
   assertEquals("Test the content transformer", quick.getSubject());
   assertEquals(
       "IN-SPIRE servers going down for a bit, back up around 8am", outlook30.getSubject());
   assertEquals("test pi\u00e8ce jointe 1", attachments.getSubject());
 }
예제 #2
0
  /** Test message headers */
  public void testHeaders() throws Exception {
    // Simple email first
    assertEquals(26, simple.getHeaders().length);
    assertTrue(simple.getHeaders()[0].startsWith("Return-path:"));
    assertTrue(simple.getHeaders()[1].equals("Envelope-to: [email protected]"));
    assertTrue(simple.getHeaders()[25].startsWith("X-Antivirus-Scanner: Clean"));

    // Quick doesn't have them
    try {
      quick.getHeaders();
      fail();
    } catch (ChunkNotFoundException e) {
    }

    // Attachments doesn't have them
    try {
      attachments.getHeaders();
      fail();
    } catch (ChunkNotFoundException e) {
    }

    // Outlook30 has some
    assertEquals(33, outlook30.getHeaders().length);
    assertTrue(outlook30.getHeaders()[0].startsWith("Microsoft Mail Internet Headers"));
    assertTrue(outlook30.getHeaders()[1].startsWith("x-mimeole:"));
    assertTrue(
        outlook30.getHeaders()[32].startsWith("\t\"Williams")); // May need better parsing in future
  }
예제 #3
0
  /** Can we always get the recipient's email? */
  public void testRecipientEmail() throws Exception {
    assertEquals("*****@*****.**", simple.getRecipientEmailAddress());
    assertEquals("*****@*****.**", quick.getRecipientEmailAddress());
    assertEquals("*****@*****.**", attachments.getRecipientEmailAddress());

    // This one has lots...
    assertEquals(18, outlook30.getRecipientEmailAddressList().length);
    assertEquals(
        "[email protected]; [email protected]; [email protected]; "
            + "[email protected]; [email protected]; [email protected]; [email protected]; "
            + "[email protected]; [email protected]; [email protected]; [email protected]; "
            + "[email protected]; [email protected]; [email protected]; "
            + "[email protected]; [email protected]; [email protected]; [email protected]",
        outlook30.getRecipientEmailAddress());
  }
예제 #4
0
  /** Test missing chunks. Use a file with no HTML body */
  public void testMissingChunks() throws Exception {
    assertEquals(false, attachments.isReturnNullOnMissingChunk());

    try {
      attachments.getHtmlBody();
      fail();
    } catch (ChunkNotFoundException e) {
      // Good
    }

    attachments.setReturnNullOnMissingChunk(true);

    assertEquals(null, attachments.getHtmlBody());

    attachments.setReturnNullOnMissingChunk(false);

    try {
      attachments.getHtmlBody();
      fail();
    } catch (ChunkNotFoundException e) {
      // Good
    }
  }
예제 #5
0
  /**
   * We default to CP1252, but can sometimes do better if needed. This file is really CP1251,
   * according to the person who submitted it in bug #49441
   */
  public void testEncoding() throws Exception {
    assertEquals(2, cyrillic.getRecipientDetailsChunks().length);
    assertEquals(
        "CP1252",
        cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
    assertEquals(
        "CP1252",
        cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding());

    cyrillic.guess7BitEncoding();

    assertEquals(
        "Cp1251",
        cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
    assertEquals(
        "Cp1251",
        cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding());

    // Override it, check it's taken
    cyrillic.set7BitEncoding("UTF-8");
    assertEquals(
        "UTF-8",
        cyrillic.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
    assertEquals(
        "UTF-8",
        cyrillic.getRecipientDetailsChunks()[1].recipientDisplayNameChunk.get7BitEncoding());

    // Check with a file that has no headers
    try {
      chinese.getHeaders();
      fail("File doesn't have headers!");
    } catch (ChunkNotFoundException e) {
    }

    String html = chinese.getHtmlBody();
    assertTrue("Charset not found:\n" + html, html.contains("text/html; charset=big5"));

    // Defaults to CP1251
    assertEquals(
        "CP1252",
        chinese.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());

    // But after guessing goes to the correct one, cp950 (Windows Traditional Chinese)
    chinese.guess7BitEncoding();
    assertEquals(
        "cp950",
        chinese.getRecipientDetailsChunks()[0].recipientDisplayNameChunk.get7BitEncoding());
  }
예제 #6
0
 /** Test the 7 bit detection */
 public void test7BitDetection() throws Exception {
   assertEquals(false, unicode.has7BitEncodingStrings());
   assertEquals(true, simple.has7BitEncodingStrings());
   assertEquals(true, chinese.has7BitEncodingStrings());
   assertEquals(true, cyrillic.has7BitEncodingStrings());
 }
예제 #7
0
  /** More missing chunk testing, this time for missing recipient email address */
  public void testMissingAddressChunk() throws Exception {
    assertEquals(false, noRecipientAddress.isReturnNullOnMissingChunk());

    try {
      noRecipientAddress.getRecipientEmailAddress();
      fail();
    } catch (ChunkNotFoundException e) {
      // Good
    }
    try {
      noRecipientAddress.getRecipientEmailAddressList();
      fail();
    } catch (ChunkNotFoundException e) {
      // Good
    }

    noRecipientAddress.setReturnNullOnMissingChunk(true);

    noRecipientAddress.getRecipientEmailAddress();
    noRecipientAddress.getRecipientEmailAddressList();
    assertEquals("", noRecipientAddress.getRecipientEmailAddress());
    assertEquals(1, noRecipientAddress.getRecipientEmailAddressList().length);
    assertEquals(null, noRecipientAddress.getRecipientEmailAddressList()[0]);

    // Check a few other bits too
    assertEquals("Microsoft Outlook 2003 Team", noRecipientAddress.getDisplayFrom());
    assertEquals("New Outlook User", noRecipientAddress.getDisplayTo());

    noRecipientAddress.setReturnNullOnMissingChunk(false);
  }
예제 #8
0
 /** Test attachments */
 public void testAttachments() throws Exception {
   assertEquals(0, simple.getAttachmentFiles().length);
   assertEquals(0, quick.getAttachmentFiles().length);
   assertEquals(0, outlook30.getAttachmentFiles().length);
   assertEquals(2, attachments.getAttachmentFiles().length);
 }