private void emailEnglishAssertions(String filePath) throws Exception {
    // initialize mailboxes
    getPersonalMailbox("jdoe");

    injectEmail(filePath);
    DocumentRef dayRef = new PathRef(CaseConstants.CASE_ROOT_DOCUMENT_PATH + "/2009/03/17");
    assertTrue(session.exists(dayRef));
    DocumentModelList envelopes = session.getChildren(dayRef, MailConstants.MAIL_ENVELOPE_TYPE);
    assertEquals(1, envelopes.size());

    DocumentModel envelopeDoc = envelopes.get(0);
    Case envelope = envelopeDoc.getAdapter(Case.class);
    List<DocumentModel> linkedDocs = envelope.getDocuments();
    assertEquals(2, linkedDocs.size());
    DocumentModel firstDoc = linkedDocs.get(0);

    String title = (String) firstDoc.getPropertyValue(CaseConstants.TITLE_PROPERTY_NAME);
    assertEquals("[Fwd: RENOUVELLEMENT DE SUPPORT ANNUEL NUXEO]", title);
    Calendar originalReceptionDate =
        (Calendar) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_IMPORT_DATE_PROPERTY_NAME);
    assertEquals(
        emailDateParser.parse("Wed, 14 Jan 2009 15:15:25 +0100").getTime(),
        originalReceptionDate.getTime().getTime());
    Calendar receptionDate =
        (Calendar) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_RECEIVE_DATE_PROPERTY_NAME);
    assertEquals(
        emailDateParser.parse("Tue, 17 Mar 2009 13:39:05 +0100").getTime(),
        receptionDate.getTime().getTime());

    Contacts senders = Contacts.getContactsForDoc(firstDoc, CaseConstants.CONTACTS_SENDERS);
    assertNotNull(senders);
    assertEquals(1, senders.size());
    Contact sender = senders.get(0);
    assertEquals("Sylvie KAPCOM", sender.getName());
    assertEquals("*****@*****.**", sender.getEmail());

    Contacts recipients = Contacts.getContactsForDoc(firstDoc, CaseConstants.CONTACTS_PARTICIPANTS);
    assertNotNull(recipients);
    assertEquals(2, recipients.size());

    assertEquals("*****@*****.**", recipients.get(0).getEmail());

    assertTrue(
        (recipients.get(1).getName() == null) || ("".equals(recipients.get(1).getName().trim())));
    assertEquals("*****@*****.**", recipients.get(1).getEmail());

    // testing content
    DocumentModel secondDoc = linkedDocs.get(1);
    Blob fileBlob = (Blob) secondDoc.getPropertyValue(CaseConstants.FILE_PROPERTY_NAME);

    assertEquals("The file blob filename is", "testpdf.pdf", fileBlob.getFilename());
    assertEquals("the file blob length is", 24016, fileBlob.getLength());

    String fileNamePropertyValue =
        (String) secondDoc.getPropertyValue(CaseConstants.FILENAME_PROPERTY_NAME);
    assertEquals("The filename property value is", "testpdf.pdf", fileNamePropertyValue);
  }
  /**
   * copy of the previous test but with a mail forwarded using gmail
   *
   * @throws Exception
   */
  @Test
  public void testParseMailGmail() throws Exception {
    // initialize mailboxes
    Mailbox forwarderMailbox = getPersonalMailbox(nulrich);
    Mailbox origSenderMailbox = getPersonalMailbox(ldoguin);

    String filePath = "data/test_mail_gmail.eml";
    injectEmail(filePath);

    DocumentRef dayRef = new PathRef(CaseConstants.CASE_ROOT_DOCUMENT_PATH + "/2010/12/08");
    assertTrue(session.exists(dayRef));
    DocumentModelList envelopes = session.getChildren(dayRef, MailConstants.MAIL_ENVELOPE_TYPE);
    assertEquals(1, envelopes.size());

    DocumentModel envelopeDoc = envelopes.get(0);
    Case envelope = envelopeDoc.getAdapter(Case.class);
    List<DocumentModel> linkedDocs = envelope.getDocuments();
    DocumentModel firstDoc = linkedDocs.get(0);
    // initial message reception
    Calendar receptionDate =
        (Calendar) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_RECEIVE_DATE_PROPERTY_NAME);
    assertEquals(
        emailDateParser.parse("Wed, 8 Dec 2010 18:25:20 +0100").getTime(),
        receptionDate.getTime().getTime());
    // date of the initial message
    Calendar importDate =
        (Calendar) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_IMPORT_DATE_PROPERTY_NAME);
    assertEquals(
        new SimpleDateFormat("yyyy/M/d").parse("2010/12/8").getTime(),
        importDate.getTime().getTime());
    String reference =
        (String) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_REFERENCE_PROPERTY_NAME);
    assertEquals("<[email protected]>", reference);
    String origin = (String) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_ORIGIN_PROPERTY_NAME);
    assertEquals("mail", origin);
    String object = (String) firstDoc.getPropertyValue(CaseConstants.TITLE_PROPERTY_NAME);
    assertEquals("Fwd: correspondence gmail en test sample", object);

    Contacts senders = Contacts.getContactsForDoc(firstDoc, CaseConstants.CONTACTS_SENDERS);
    assertNotNull(senders);
    assertEquals(1, senders.size());
    Contact sender = senders.get(0);
    assertEquals("laurent O'doguin (nuxeo/reponseD)", sender.getName());
    assertEquals("*****@*****.**", sender.getEmail());
    assertEquals("user-ldoguin", sender.getMailboxIdd());

    Contacts recipients = Contacts.getContactsForDoc(firstDoc, CaseConstants.CONTACTS_PARTICIPANTS);
    assertNotNull(recipients);
    assertEquals(1, recipients.size());
    Contact recipient = recipients.get(0);
    assertEquals("nicolas ulrich (nuxeo/starship)", recipient.getName());
    assertEquals("*****@*****.**", recipient.getEmail());
    assertEquals("user-nulrich", recipient.getMailboxIdd());

    List<CaseLink> forwarderReceivedPosts =
        distributionService.getReceivedCaseLinks(session, forwarderMailbox, 0, 0);
    assertNotNull(forwarderReceivedPosts);
    assertEquals(1, forwarderReceivedPosts.size());

    List<CaseLink> forwarderSentPosts =
        distributionService.getSentCaseLinks(session, forwarderMailbox, 0, 0);
    assertNotNull(forwarderSentPosts);
    assertEquals(0, forwarderSentPosts.size());

    // original sender does not have any message, even if he has a
    // mailbox...
    List<CaseLink> origSenderReceivedPosts =
        distributionService.getReceivedCaseLinks(session, origSenderMailbox, 0, 0);
    assertNotNull(origSenderReceivedPosts);
    assertEquals(0, origSenderReceivedPosts.size());

    List<CaseLink> origSenderSentPosts =
        distributionService.getSentCaseLinks(session, origSenderMailbox, 0, 0);
    assertNotNull(origSenderSentPosts);
    assertEquals(0, origSenderSentPosts.size());
  }
  /**
   * Test match Email of ccRecipient
   *
   * @throws Exception
   */
  @Test
  public void testParseMailEnglishThunderbird() throws Exception {
    // initialize mailboxes
    Mailbox forwarderMailbox = getPersonalMailbox(nulrich);
    Mailbox origSenderMailbox = getPersonalMailbox(ldoguin);

    String filePath = "data/test_mail_en_thunderbird.eml";
    injectEmail(filePath);

    DocumentRef dayRef = new PathRef(CaseConstants.CASE_ROOT_DOCUMENT_PATH + "/2010/02/25");
    assertTrue(session.exists(dayRef));
    DocumentModelList envelopes = session.getChildren(dayRef, MailConstants.MAIL_ENVELOPE_TYPE);
    assertEquals(1, envelopes.size());

    DocumentModel envelopeDoc = envelopes.get(0);
    Case envelope = envelopeDoc.getAdapter(Case.class);
    List<DocumentModel> linkedDocs = envelope.getDocuments();
    DocumentModel firstDoc = linkedDocs.get(0);
    Calendar receptionDate =
        (Calendar) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_RECEIVE_DATE_PROPERTY_NAME);
    assertEquals(
        emailDateParser.parse("Thu, 25 Feb 2010 15:14:35 +0100").getTime(),
        receptionDate.getTime().getTime());
    Calendar importDate =
        (Calendar) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_IMPORT_DATE_PROPERTY_NAME);
    assertEquals(
        emailDateParser.parse("Thu, 25 Feb 2010 15:15:25 +0100").getTime(),
        importDate.getTime().getTime());
    String reference =
        (String) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_REFERENCE_PROPERTY_NAME);
    assertEquals("<*****@*****.**>", reference);
    String origin = (String) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_ORIGIN_PROPERTY_NAME);
    assertEquals("mail", origin);
    String object = (String) firstDoc.getPropertyValue(CaseConstants.TITLE_PROPERTY_NAME);
    assertEquals("Fwd: correspondence test sample", object);

    Contacts senders = Contacts.getContactsForDoc(firstDoc, CaseConstants.CONTACTS_SENDERS);
    assertNotNull(senders);
    assertEquals(1, senders.size());
    Contact sender = senders.get(0);
    assertEquals("laurent O'doguin (nuxeo/reponseD)", sender.getName());
    assertEquals("*****@*****.**", sender.getEmail());
    assertEquals("user-ldoguin", sender.getMailboxIdd());

    Contacts recipients = Contacts.getContactsForDoc(firstDoc, CaseConstants.CONTACTS_PARTICIPANTS);
    assertNotNull(recipients);
    assertEquals(1, recipients.size());
    Contact recipient = recipients.get(0);
    assertEquals("nicolas ulrich (nuxeo/starship)", recipient.getName());
    assertEquals("*****@*****.**", recipient.getEmail());
    assertEquals("user-nulrich", recipient.getMailboxIdd());

    List<CaseLink> forwarderReceivedPosts =
        distributionService.getReceivedCaseLinks(session, forwarderMailbox, 0, 0);
    assertNotNull(forwarderReceivedPosts);
    assertEquals(1, forwarderReceivedPosts.size());

    List<CaseLink> forwarderSentPosts =
        distributionService.getSentCaseLinks(session, forwarderMailbox, 0, 0);
    assertNotNull(forwarderSentPosts);
    assertEquals(0, forwarderSentPosts.size());

    // original sender does not have any message, even if he has a
    // mailbox...
    List<CaseLink> origSenderReceivedPosts =
        distributionService.getReceivedCaseLinks(session, origSenderMailbox, 0, 0);
    assertNotNull(origSenderReceivedPosts);
    assertEquals(0, origSenderReceivedPosts.size());

    List<CaseLink> origSenderSentPosts =
        distributionService.getSentCaseLinks(session, origSenderMailbox, 0, 0);
    assertNotNull(origSenderSentPosts);
    assertEquals(0, origSenderSentPosts.size());
  }