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(String flag) 

Source Link

Document

Construct a Flags object initialized with the given user flag.

Usage

From source file:com.googlecode.gmail4j.javamail.ImapGmailClient.java

/**
 * Returns list of unread/read priority {@link GmailMessage} objects 
 * based on the {@code unreadOnly} value
 * //from  w w  w  . ja  v  a 2s  .c  o  m
 * @param unreadOnly {@code true} to unread priority {@link GmailMessage} 
 * objects only, {@code false} to read priority {@link GmailMessage} 
 * objects only
 * @return List of unread/read priority messages
 * @throws GmailException if unable to get unread/read priority messages
 */
public List<GmailMessage> getPriorityMessages(boolean unreadOnly) {
    try {
        final List<GmailMessage> priorityMessages = new ArrayList<GmailMessage>();
        final Store store = openGmailStore();
        Folder folder = getFolder(ImapGmailLabel.IMPORTANT.getName(), store);
        folder.open(Folder.READ_ONLY);
        for (final Message msg : folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), !unreadOnly))) {
            priorityMessages.add(new JavaMailGmailMessage(msg));
        }

        return priorityMessages;
    } catch (final Exception e) {
        throw new GmailException("Failed getting priority messages", e);
    }
}

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

@Test
public void setFlagsShouldReturnEmptyWhenMailboxIdsIsEmpty() throws Exception {
    message1.setUid(mapperProvider.generateMessageUid());
    message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    sut.save(message1);//from w  w  w .  ja  va2 s  .  co  m

    MessageId messageId = message1.getMessageId();
    Flags newFlags = new Flags(Flag.ANSWERED);
    Map<MailboxId, UpdatedFlags> flags = sut.setFlags(messageId, ImmutableList.of(), newFlags,
            FlagsUpdateMode.REMOVE);

    assertThat(flags).isEmpty();
}

From source file:org.pentaho.di.job.entries.getpop.MailConnection.java

public void setFlagTermNew() {
    addSearchTerm(new FlagTerm(new Flags(Flags.Flag.RECENT), true));
}

From source file:org.pentaho.di.job.entries.getpop.MailConnection.java

public void setFlagTermOld() {
    addSearchTerm(new FlagTerm(new Flags(Flags.Flag.RECENT), false));
}

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

@Test
public void setFlagsShouldReturnEmptyWhenMessageIdDoesntExist() throws Exception {
    MessageId unknownMessageId = mapperProvider.generateMessageId();
    Map<MailboxId, UpdatedFlags> flags = sut.setFlags(unknownMessageId,
            ImmutableList.of(message1.getMailboxId()), new Flags(Flag.RECENT), FlagsUpdateMode.REMOVE);

    assertThat(flags).isEmpty();/*from  ww w . j  ava  2 s  .  c om*/
}

From source file:org.pentaho.di.job.entries.getpop.MailConnection.java

public void setFlagTermRead() {
    addSearchTerm(new FlagTerm(new Flags(Flags.Flag.SEEN), true));
}

From source file:org.pentaho.di.job.entries.getpop.MailConnection.java

public void setFlagTermUnread() {
    addSearchTerm(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
}

From source file:org.jasig.portlet.emailpreview.dao.javamail.JavamailAccountDaoImpl.java

@Override
public boolean deleteMessages(MailStoreConfiguration config, String[] uuids) {
    Authenticator auth = credentialsProvider.getAuthenticator();
    Folder inbox = null;/*  www .ja  va  2s .  c om*/
    try {

        // Retrieve user's inbox
        Session session = openMailSession(config, auth);
        inbox = getUserInbox(session, config.getInboxFolderName());

        // Verify that we can even perform this operation
        if (!(inbox instanceof UIDFolder)) {
            String msg = "Delete feature is supported only for UIDFolder instances";
            throw new UnsupportedOperationException(msg);
        }

        inbox.open(Folder.READ_WRITE);

        Message[] msgs = ((UIDFolder) inbox).getMessagesByUID(getMessageUidsAsLong(uuids));
        inbox.setFlags(msgs, new Flags(Flag.DELETED), true);

        return true; // Indicate success

    } catch (MessagingException e) {
        log.error("Messaging exception while deleting messages", e);
    } finally {
        if (inbox != null) {
            try {
                inbox.close(false);
            } catch (Exception e) {
                log.warn("Can't close correctly javamail inbox connection");
            }
            try {
                inbox.getStore().close();
            } catch (Exception e) {
                log.warn("Can't close correctly javamail store connection");
            }
        }
    }

    return false; // We failed if we reached this point
}

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

@Test
public void setFlagsShouldAddFlagsWhenAddUpdateMode() throws Exception {
    Flags initialFlags = new Flags(Flag.RECENT);
    message1.setUid(mapperProvider.generateMessageUid());
    message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    message1.setFlags(initialFlags);//from   www. jav a 2  s .c om
    sut.save(message1);

    MessageId messageId = message1.getMessageId();

    Map<MailboxId, UpdatedFlags> flags = sut.setFlags(messageId, ImmutableList.of(message1.getMailboxId()),
            new Flags(Flag.ANSWERED), FlagsUpdateMode.ADD);

    Flags newFlags = new FlagsBuilder().add(Flag.RECENT).add(Flag.ANSWERED).build();
    long modSeq = mapperProvider.highestModSeq(benwaInboxMailbox);
    UpdatedFlags expectedUpdatedFlags = UpdatedFlags.builder().uid(message1.getUid()).modSeq(modSeq)
            .oldFlags(initialFlags).newFlags(newFlags).build();
    assertThat(flags).containsOnly(MapEntry.entry(benwaInboxMailbox.getMailboxId(), expectedUpdatedFlags));
}

From source file:org.pentaho.di.job.entries.getpop.MailConnection.java

public void setFlagTermFlagged() {
    addSearchTerm(new FlagTerm(new Flags(Flags.Flag.FLAGGED), true));
}