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:com.hs.mail.imap.dao.FlagUtils.java

static Flags getFlags(ResultSet rs) throws SQLException {
    Flags flags = new Flags();
    for (int i = 0; i < attrArray.length; i++) {
        if ("Y".equals(rs.getString(attrArray[i]))) {
            flags.add(flagArray[i]);/*from   w w w  . ja va 2s.c o m*/
        }
    }
    return flags;
}

From source file:org.apache.james.mailbox.store.mail.model.impl.SimpleMessageTest.java

private static SimpleMessage<Long> buildMessage(String content) {
    return new SimpleMessage<Long>(Calendar.getInstance().getTime(), content.length(), 0,
            new SharedByteArrayInputStream(content.getBytes()), new Flags(), new PropertyBuilder(), 1L);
}

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

@Test
public void textShouldBeEmptyWhenNoMatchingHeaders() throws Exception {
    MailboxMessage mailboxMessage = mock(MailboxMessage.class);
    TestId mailboxId = TestId.of(1);//w  ww.  j ava 2  s. c  om
    when(mailboxMessage.getMailboxId()).thenReturn(mailboxId);
    when(mailboxMessage.getFullContent()).thenReturn(new ByteArrayInputStream("".getBytes()));
    when(mailboxMessage.createFlags()).thenReturn(new Flags());

    IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage,
            ImmutableList.of(new MockMailboxSession("username").getUser()), new DefaultTextExtractor(),
            ZoneId.of("Europe/Paris"));

    assertThat(indexableMessage.getText()).isEmpty();
}

From source file:org.apache.james.protocols.imap.utils.DecoderUtilsTest.java

@Test
public void testSetRecentFlag() {
    Flags flags = new Flags();
    try {//from  w w  w . j a va  2 s.c  o  m
        DecoderUtils.setFlag("\\Recent", flags);
        fail();
    } catch (DecodingException e) {
        // expected
    }
}

From source file:org.apache.james.protocols.imap.utils.DecoderUtilsTest.java

@Test
public void testSetOtherFlag() throws Exception {
    Flags flags = new Flags();
    DecoderUtils.setFlag(A_CUSTOM_FLAG, flags);
    assertTrue("Unknown flags should be added", flags.contains(A_CUSTOM_FLAG));
}

From source file:org.apache.james.protocols.imap.utils.DecoderUtilsTest.java

@Test
public void testExtensionFlag() throws Exception {
    Flags flags = new Flags();
    DecoderUtils.setFlag(EXTENSION_FLAG, flags);
    assertTrue("Extension flags should be added", flags.contains(EXTENSION_FLAG));
}

From source file:org.apache.hupa.server.handler.SetFlagsHandler.java

@Override
protected GenericResult executeInternal(SetFlag action, ExecutionContext context) throws ActionException {
    User user = getUser();/*from   w  w w  .j  a  v  a 2  s .co  m*/
    IMAPFolder folder = action.getFolder();
    ArrayList<Long> uids = action.getUids();
    com.sun.mail.imap.IMAPFolder f = null;
    try {
        IMAPStore store = cache.get(user);

        f = (com.sun.mail.imap.IMAPFolder) store.getFolder(folder.getFullName());
        if (f.isOpen() == false) {
            f.open(Folder.READ_WRITE);
        }
        Message[] msgs = f.getMessagesByUID(toArray(uids));
        Flag flag = JavamailUtil.convert(action.getFlag());
        Flags flags = new Flags();
        flags.add(flag);

        f.setFlags(msgs, flags, action.getValue());
        return new GenericResult();
    } catch (MessagingException e) {
        String errorMsg = "Error while setting flags of messages with uids " + uids + " for user " + user;
        logger.error(errorMsg, e);
        throw new ActionException(errorMsg, e);
    } finally {
        if (f != null && f.isOpen()) {
            try {
                f.close(false);
            } catch (MessagingException e) {
                // ignore on close
            }
        }
    }
}

From source file:org.apache.james.mailbox.store.ImmutableMailboxMessageTest.java

@Test
public void fullContentMayBeReadMultipleTimes() throws Exception {
    String fullContent = "Subject: Test1 \n\nBody1\n.\n";
    int bodyStartOctet = 16;
    SimpleMailboxMessage simpleMailboxMessage = new SimpleMailboxMessage(new DefaultMessageId(), new Date(),
            fullContent.length(), bodyStartOctet,
            new SharedByteArrayInputStream(fullContent.getBytes(StandardCharsets.UTF_8)), new Flags(),
            new PropertyBuilder(), TestId.of(1));

    ImmutableMailboxMessage message = messageFactory.from(TestId.of(1), simpleMailboxMessage);

    softly.assertThat(IOUtils.toString(message.getFullContent(), StandardCharsets.UTF_8))
            .isEqualTo(fullContent);/*from   w  w w . j a v a 2  s .co m*/
    softly.assertThat(IOUtils.toString(message.getFullContent(), StandardCharsets.UTF_8))
            .isEqualTo(fullContent);
}

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

@Test
public void textShouldContainsFromWhenFrom() throws Exception {
    MailboxMessage mailboxMessage = mock(MailboxMessage.class);
    TestId mailboxId = TestId.of(1);/* w ww.j  av a2s . c o  m*/
    when(mailboxMessage.getMailboxId()).thenReturn(mailboxId);
    when(mailboxMessage.getFullContent()).thenReturn(new ByteArrayInputStream(
            "From: First user <user@james.org>\nFrom: Second user <user2@james.org>".getBytes()));
    when(mailboxMessage.createFlags()).thenReturn(new Flags());

    IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage,
            ImmutableList.of(new MockMailboxSession("username").getUser()), new DefaultTextExtractor(),
            ZoneId.of("Europe/Paris"));

    assertThat(indexableMessage.getText()).isEqualTo("Second user user2@james.org First user user@james.org");
}

From source file:org.nuxeo.cm.event.MailInjectionListener.java

public void handleEvent(Event event) throws ClientException {
    MailService mailService = Framework.getService(MailService.class);
    MessageActionPipe pipe = mailService.getPipe(MAILBOX_PIPE);

    Visitor visitor = new Visitor(pipe);
    Thread.currentThread().setContextClassLoader(Framework.class.getClassLoader());

    Folder rootFolder = null;/*from   w w w.j a  va  2s. c  om*/

    try (CoreSession session = CoreInstance.openCoreSessionSystem(null)) {
        // initialize context
        ExecutionContext initialExecutionContext = new ExecutionContext();
        initialExecutionContext.put(AbstractCaseManagementMailAction.CORE_SESSION_KEY, session);
        initialExecutionContext.put(AbstractCaseManagementMailAction.MIMETYPE_SERVICE_KEY,
                Framework.getService(MimetypeRegistry.class));
        initialExecutionContext.put(AbstractCaseManagementMailAction.CASEMANAGEMENT_SERVICE_KEY,
                Framework.getService(CaseDistributionService.class));

        // open store
        Store store = mailService.getConnectedStore(IMPORT_MAILBOX);
        rootFolder = store.getFolder(INBOX);
        rootFolder.open(Folder.READ_WRITE);
        Flags flags = new Flags();
        flags.add(Flag.SEEN);
        SearchTerm term = new FlagTerm(flags, false);
        Message[] unreadMessages = rootFolder.search(term);

        // perform import
        visitor.visit(unreadMessages, initialExecutionContext);

        // save session
        session.save();

        if (rootFolder.isOpen()) {
            try {
                rootFolder.close(true);
            } catch (MessagingException e) {
                log.error(e.getMessage(), e);
            }
        }
    } catch (MessagingException e) {
        log.error(e, e);
    }
}