Example usage for javax.mail Flags Flags

List of usage examples for javax.mail Flags Flags

Introduction

In this page you can find the example usage for javax.mail Flags Flags.

Prototype

public Flags() 

Source Link

Document

Construct an empty Flags object.

Usage

From source file:org.apache.james.jmap.methods.integration.GetMailboxesMethodTest.java

@Test
public void getMailboxesShouldReturnMailboxesWhenAvailable() throws Exception {
    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "name");

    mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "name"),
            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false,
            new Flags());

    given().header("Authorization", accessToken.serialize()).body("[[\"getMailboxes\", {}, \"#0\"]]").when()
            .post("/jmap").then().statusCode(200).body(NAME, equalTo("mailboxes"))
            .body(ARGUMENTS + ".list.name", hasItem("name"));
}

From source file:com.hs.mail.imap.mailbox.DefaultMailboxManager.java

public MailMessage appendMessage(long mailboxID, Date internalDate, Flags flags, File file) throws IOException {
    // If a date-time is specified, the internal date SHOULD be set in
    // the resulting message; otherwise, the internal date of the
    // resulting message is set to the current date and time by default.
    if (internalDate == null) {
        internalDate = new Date();
    }//from   w ww  . j a va 2 s  .  co m

    // If a flag parenthesized list is specified, the flags SHOULD be
    // set in the resulting message; otherwise, the flag list of the
    // resulting message is set to empty by default.
    if (flags == null) {
        flags = new Flags();
    }

    MailMessage message = MailMessage.createMailMessage(file, internalDate, flags);
    appendMessage(mailboxID, message);

    // Save the message file
    message.save(true);

    return message;
}

From source file:org.apache.james.jmap.methods.integration.SetMessagesMethodTest.java

@Test
public void setMessagesShouldReturnDestroyedNotDestroyWhenMixed() throws Exception {
    jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");

    jmapServer.serverProbe().appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(),
            false, new Flags());

    jmapServer.serverProbe().appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(),
            false, new Flags());

    jmapServer.serverProbe().appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(),
            false, new Flags());
    await();/*from   w w  w  . jav a  2  s  .c  o  m*/

    String missingMessageId = username + "|mailbox|4";
    given().header("Authorization", accessToken.serialize())
            .body("[[\"setMessages\", {\"destroy\": [\"" + username + "|mailbox|1\", \"" + missingMessageId
                    + "\", \"" + username + "|mailbox|3\"]}, \"#0\"]]")
            .when().post("/jmap").then().log().ifValidationFails().statusCode(200)
            .body(NAME, equalTo("messagesSet")).body(ARGUMENTS + ".destroyed", hasSize(2))
            .body(ARGUMENTS + ".notDestroyed", aMapWithSize(1))
            .body(ARGUMENTS + ".destroyed", contains(username + "|mailbox|1", username + "|mailbox|3"))
            .body(ARGUMENTS + ".notDestroyed",
                    hasEntry(equalTo(missingMessageId), Matchers.allOf(hasEntry("type", "notFound"),
                            hasEntry("description", "The message " + missingMessageId + " can't be found"))));
}

From source file:org.apache.james.jmap.methods.integration.GetMailboxesMethodTest.java

@Test
public void getMailboxesShouldReturnMailboxPropertiesWhenAvailable() throws Exception {
    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "name");

    mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "name"),
            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false,
            new Flags());

    MailboxId mailboxId = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, username, "name")
            .getMailboxId();/*from w w  w.j a v a2  s .  c o  m*/
    given().header("Authorization", accessToken.serialize())
            .body("[[\"getMailboxes\", {\"ids\": [\"" + mailboxId.serialize() + "\"]}, \"#0\"]]").when()
            .post("/jmap").then().statusCode(200).body(NAME, equalTo("mailboxes"))
            .body(ARGUMENTS + ".list.name", hasItem("name")).body(ARGUMENTS + ".list[0].parentId", nullValue())
            .body(ARGUMENTS + ".list[0].role", nullValue())
            .body(ARGUMENTS + ".list[0].sortOrder", equalTo(1000))
            .body(ARGUMENTS + ".list[0].mustBeOnlyMailbox", equalTo(false))
            .body(ARGUMENTS + ".list[0].mayReadItems", equalTo(false))
            .body(ARGUMENTS + ".list[0].mayAddItems", equalTo(false))
            .body(ARGUMENTS + ".list[0].mayRemoveItems", equalTo(false))
            .body(ARGUMENTS + ".list[0].mayCreateChild", equalTo(false))
            .body(ARGUMENTS + ".list[0].mayRename", equalTo(false))
            .body(ARGUMENTS + ".list[0].mayDelete", equalTo(false))
            .body(ARGUMENTS + ".list[0].totalMessages", equalTo(1))
            .body(ARGUMENTS + ".list[0].unreadMessages", equalTo(1))
            .body(ARGUMENTS + ".list[0].unreadThreads", equalTo(0));
}

From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java

@Test
public void spamEmailShouldBeWellConvertedToJsonWithApacheTika() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new TikaTextExtractor(), ZoneId.of("Europe/Paris"));
    MailboxMessage spamMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET,
            new SharedByteArrayInputStream(
                    IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/nonTextual.eml"))),
            new Flags(), propertyBuilder, MAILBOX_ID);
    spamMail.setModSeq(MOD_SEQ);//from   ww  w . ja va  2  s . c  o m
    assertThatJson(messageToElasticSearchJson.convertToJson(spamMail,
            ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER)
                    .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/nonTextual.json"), CHARSET));
}

From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java

@Test
public void getMessageListUnsetDraftFilterShouldWork() throws Exception {
    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");

    ComposedMessageId messageNotDraft = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false,
            new Flags());
    ComposedMessageId messageDraft = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false,
            new Flags(Flags.Flag.DRAFT));

    await();/*from   w  ww  .j a v a 2s .c o  m*/

    given().header("Authorization", accessToken.serialize())
            .body("[[\"getMessageList\", {\"filter\":{\"isDraft\":\"false\"}}, \"#0\"]]").when().post("/jmap")
            .then().statusCode(200).body(NAME, equalTo("messageList")).body(ARGUMENTS + ".messageIds",
                    allOf(containsInAnyOrder(messageNotDraft.getMessageId().serialize()),
                            not(containsInAnyOrder(messageDraft.getMessageId().serialize()))));
}

From source file:org.apache.james.mailbox.cassandra.mail.CassandraMessageMapper.java

@Override
public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
    return applicableFlagDAO.retrieveApplicableFlag((CassandraId) mailbox.getMailboxId()).join()
            .orElse(new Flags());
}

From source file:org.apache.james.jmap.methods.integration.GetMessageListMethodTest.java

@Test
public void getMessageListSetAnsweredFilterShouldWork() throws Exception {
    mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");

    ComposedMessageId messageNotAnswered = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false,
            new Flags());
    ComposedMessageId messageAnswered = mailboxProbe.appendMessage(username,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
            ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false,
            new Flags(Flags.Flag.ANSWERED));

    await();/*from  ww w .ja  va  2s.  com*/

    given().header("Authorization", accessToken.serialize())
            .body("[[\"getMessageList\", {\"filter\":{\"isAnswered\":\"true\"}}, \"#0\"]]").when().post("/jmap")
            .then().statusCode(200).body(NAME, equalTo("messageList")).body(ARGUMENTS + ".messageIds",
                    allOf(containsInAnyOrder(messageAnswered.getMessageId().serialize()),
                            not(containsInAnyOrder(messageNotAnswered.getMessageId().serialize()))));
}

From source file:org.apache.james.pop3server.POP3ServerTest.java

/**
 * Test for JAMES-1202 -  Which shows that UIDL,STAT and LIST all show the same message numbers.
 *//*from  w  w  w. j ava  2 s.c o m*/
@Test
public void testStatUidlList() throws Exception {
    finishSetUp(pop3Configuration);

    pop3Client = new POP3Client();
    pop3Client.connect("127.0.0.1", pop3Port);

    usersRepository.addUser("foo2", "bar2");

    MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "foo2", "INBOX");
    MailboxSession session = mailboxManager.login("foo2", "bar2", LoggerFactory.getLogger("Test"));

    if (!mailboxManager.mailboxExists(mailboxPath, session)) {
        mailboxManager.createMailbox(mailboxPath, session);
    }

    int msgCount = 100;
    for (int i = 0; i < msgCount; i++) {
        mailboxManager.getMailbox(mailboxPath, session).appendMessage(
                new ByteArrayInputStream(("Subject: test\r\n\r\n" + i).getBytes()), new Date(), session, true,
                new Flags());
    }

    pop3Client.login("foo2", "bar2");
    assertEquals(1, pop3Client.getState());

    POP3MessageInfo[] listEntries = pop3Client.listMessages();
    POP3MessageInfo[] uidlEntries = pop3Client.listUniqueIdentifiers();
    POP3MessageInfo statInfo = pop3Client.status();
    assertEquals(msgCount, listEntries.length);
    assertEquals(msgCount, uidlEntries.length);
    assertEquals(msgCount, statInfo.number);

    pop3Client.sendCommand("quit");
    pop3Client.disconnect();

    pop3Client.connect("127.0.0.1", pop3Port);

    pop3Client.login("foo2", "bar2");
    assertEquals(1, pop3Client.getState());

    mailboxManager.deleteMailbox(mailboxPath, session);

}