Example usage for javax.mail Flags contains

List of usage examples for javax.mail Flags contains

Introduction

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

Prototype

public boolean contains(Flags f) 

Source Link

Document

Check whether all the flags in the specified Flags object are present in this Flags object.

Usage

From source file:org.apache.james.mailbox.jcr.mail.model.JCRMailboxMessage.java

@Override
public void setFlags(Flags flags) {
    if (isPersistent()) {
        try {/*from  w  ww  . j  av a  2 s .  c om*/
            node.setProperty(ANSWERED_PROPERTY, flags.contains(Flags.Flag.ANSWERED));
            node.setProperty(DELETED_PROPERTY, flags.contains(Flags.Flag.DELETED));
            node.setProperty(DRAFT_PROPERTY, flags.contains(Flags.Flag.DRAFT));
            node.setProperty(FLAGGED_PROPERTY, flags.contains(Flags.Flag.FLAGGED));
            node.setProperty(RECENT_PROPERTY, flags.contains(Flags.Flag.RECENT));
            node.setProperty(SEEN_PROPERTY, flags.contains(Flags.Flag.SEEN));
            node.setProperty(USERFLAGS_PROPERTY, flags.getUserFlags());
        } catch (RepositoryException e) {
            logger.error("Unable to set flags", e);
        }
    } else {
        answered = flags.contains(Flags.Flag.ANSWERED);
        deleted = flags.contains(Flags.Flag.DELETED);
        draft = flags.contains(Flags.Flag.DRAFT);
        flagged = flags.contains(Flags.Flag.FLAGGED);
        recent = flags.contains(Flags.Flag.RECENT);
        seen = flags.contains(Flags.Flag.SEEN);
        userFlags = flags.getUserFlags();
    }
}

From source file:org.apache.james.mailbox.jcr.mail.model.JCRMessage.java

public void setFlags(Flags flags) {
    if (isPersistent()) {
        try {//  ww  w .  j  a  v a  2s .c  o  m
            node.setProperty(ANSWERED_PROPERTY, flags.contains(Flags.Flag.ANSWERED));
            node.setProperty(DELETED_PROPERTY, flags.contains(Flags.Flag.DELETED));
            node.setProperty(DRAFT_PROPERTY, flags.contains(Flags.Flag.DRAFT));
            node.setProperty(FLAGGED_PROPERTY, flags.contains(Flags.Flag.FLAGGED));
            node.setProperty(RECENT_PROPERTY, flags.contains(Flags.Flag.RECENT));
            node.setProperty(SEEN_PROPERTY, flags.contains(Flags.Flag.SEEN));
            node.setProperty(USERFLAGS_PROPERTY, flags.getUserFlags());
        } catch (RepositoryException e) {
            logger.error("Unable to set flags", e);
        }
    } else {
        answered = flags.contains(Flags.Flag.ANSWERED);
        deleted = flags.contains(Flags.Flag.DELETED);
        draft = flags.contains(Flags.Flag.DRAFT);
        flagged = flags.contains(Flags.Flag.FLAGGED);
        recent = flags.contains(Flags.Flag.RECENT);
        seen = flags.contains(Flags.Flag.SEEN);
        userFlags = flags.getUserFlags();
    }
}

From source file:org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage.java

/**
 * @see MailboxMessage#setFlags(javax.mail.Flags)
 *///from w  w w .j  a va2  s.  com
public void setFlags(Flags flags) {
    answered = flags.contains(Flags.Flag.ANSWERED);
    deleted = flags.contains(Flags.Flag.DELETED);
    draft = flags.contains(Flags.Flag.DRAFT);
    flagged = flags.contains(Flags.Flag.FLAGGED);
    recent = flags.contains(Flags.Flag.RECENT);
    seen = flags.contains(Flags.Flag.SEEN);

    /*
    // Loop over the user flags and check which of them needs to get added / removed
    List<String> uFlags = Arrays.asList(flags.getUserFlags());
    for (int i = 0; i < userFlags.size(); i++) {
    JPAUserFlag f = userFlags.get(i);
    if (uFlags.contains(f.getName()) == false) {
        userFlags.remove(f);
        i++;
    }
    }
    for (int i = 0; i < uFlags.size(); i++) {
    boolean found = false;
    String uFlag = uFlags.get(i);
    for (int a = 0; a < userFlags.size(); a++) {
        String userFlag = userFlags.get(a).getName();
        if (userFlag.equals(uFlag)) {
            found = true;
            break;
        }
    }
    if (found == false) {
        userFlags.add(new JPAUserFlag(uFlag));
    }
            
            
    }
    */
    String[] userflags = flags.getUserFlags();
    userFlags.clear();
    for (String userflag : userflags) {
        userFlags.add(new JPAUserFlag(userflag));
    }
}

From source file:org.apache.james.mailbox.maildir.mail.MaildirMessageMapper.java

/**
 * @see org.apache.james.mailbox.store.mail.MessageMapper#updateFlags(org.apache.james.mailbox.store.mail.model.Mailbox,
 *      javax.mail.Flags, boolean, boolean,
 *      org.apache.james.mailbox.model.MessageRange)
 *///from  w w  w.j  av  a2 s .  c  o m
@Override
public Iterator<UpdatedFlags> updateFlags(Mailbox mailbox, FlagsUpdateCalculator flagsUpdateCalculator,
        MessageRange set) throws MailboxException {
    final List<UpdatedFlags> updatedFlags = new ArrayList<UpdatedFlags>();
    final MaildirFolder folder = maildirStore.createMaildirFolder(mailbox);

    Iterator<MailboxMessage> it = findInMailbox(mailbox, set, FetchType.Metadata, -1);
    while (it.hasNext()) {
        final MailboxMessage member = it.next();
        Flags originalFlags = member.createFlags();
        member.setFlags(flagsUpdateCalculator.buildNewFlags(originalFlags));
        Flags newFlags = member.createFlags();

        try {
            MaildirMessageName messageName = folder.getMessageNameByUid(mailboxSession, member.getUid());
            if (messageName != null) {
                File messageFile = messageName.getFile();
                // System.out.println("save existing " + message +
                // " as " + messageFile.getName());
                messageName.setFlags(member.createFlags());
                // this automatically moves messages from new to cur if
                // needed
                String newMessageName = messageName.getFullName();

                File newMessageFile;

                // See MAILBOX-57
                if (newFlags.contains(Flag.RECENT)) {
                    // message is recent so save it in the new folder
                    newMessageFile = new File(folder.getNewFolder(), newMessageName);
                } else {
                    newMessageFile = new File(folder.getCurFolder(), newMessageName);
                }
                long modSeq;
                // if the flags don't have change we should not try to move
                // the file
                if (newMessageFile.equals(messageFile) == false) {
                    FileUtils.moveFile(messageFile, newMessageFile);
                    modSeq = newMessageFile.lastModified();

                } else {
                    modSeq = messageFile.lastModified();
                }
                member.setModSeq(modSeq);

                updatedFlags.add(new UpdatedFlags(member.getUid(), modSeq, originalFlags, newFlags));

                long uid = member.getUid();
                folder.update(mailboxSession, uid, newMessageName);
            }
        } catch (IOException e) {
            throw new MailboxException("Failure while save MailboxMessage " + member + " in Mailbox " + mailbox,
                    e);
        }

    }
    return updatedFlags.iterator();

}

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

public synchronized void setFlags(Flags flags) {
    answered = flags.contains(Flags.Flag.ANSWERED);
    deleted = flags.contains(Flags.Flag.DELETED);
    draft = flags.contains(Flags.Flag.DRAFT);
    flagged = flags.contains(Flags.Flag.FLAGGED);
    recent = flags.contains(Flags.Flag.RECENT);
    seen = flags.contains(Flags.Flag.SEEN);
    userFlags = flags.getUserFlags();//  www  .  j  a v  a2s  .  c o m
}

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

public synchronized void setFlags(Flags flags) {
    answered = flags.contains(Flags.Flag.ANSWERED);
    deleted = flags.contains(Flags.Flag.DELETED);
    draft = flags.contains(Flags.Flag.DRAFT);
    flagged = flags.contains(Flags.Flag.FLAGGED);
    recent = flags.contains(Flags.Flag.RECENT);
    seen = flags.contains(Flags.Flag.SEEN);
}

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

public MessageAssert hasFlags(Flags flags) {
    if (flags.contains(Flags.Flag.ANSWERED) != actual.isAnswered()) {
        failWithMessage("Expected ANSWERED flag to be <%s> but was <%>", flags.contains(Flags.Flag.ANSWERED),
                actual.isAnswered());/* w  ww . ja  va2 s.c  o  m*/
    }
    if (flags.contains(Flags.Flag.DELETED) != actual.isDeleted()) {
        failWithMessage("Expected DELETED flag to be <%s> but was <%>", flags.contains(Flags.Flag.DELETED),
                actual.isDeleted());
    }
    if (flags.contains(Flags.Flag.DRAFT) != actual.isDraft()) {
        failWithMessage("Expected DRAFT flag to be <%s> but was <%>", flags.contains(Flags.Flag.DRAFT),
                actual.isDraft());
    }
    if (flags.contains(Flags.Flag.FLAGGED) != actual.isFlagged()) {
        failWithMessage("Expected FLAGGED flag to be <%s> but was <%>", flags.contains(Flags.Flag.FLAGGED),
                actual.isFlagged());
    }
    if (flags.contains(Flags.Flag.SEEN) != actual.isSeen()) {
        failWithMessage("Expected SEEN flag to be <%s> but was <%>", flags.contains(Flags.Flag.SEEN),
                actual.isSeen());
    }
    if (flags.contains(Flags.Flag.RECENT) != actual.isRecent()) {
        failWithMessage("Expected RECENT flag to be <%s> but was <%>", flags.contains(Flags.Flag.RECENT),
                actual.isRecent());
    }
    return this;
}

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

public void setFlags(Flags flags) {
    answered = flags.contains(Flags.Flag.ANSWERED);
    deleted = flags.contains(Flags.Flag.DELETED);
    draft = flags.contains(Flags.Flag.DRAFT);
    flagged = flags.contains(Flags.Flag.FLAGGED);
    recent = flags.contains(Flags.Flag.RECENT);
    seen = flags.contains(Flags.Flag.SEEN);
}

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

/**
 * Check if the given {@link Flags} contains {@link Flags} which are not
 * included in the returned {@link Flags} of
 * {@link #getPermanentFlags(MailboxSession)}. If any are found, these are
 * removed from the given {@link Flags} instance. The only exception is the
 * {@link Flag#RECENT} flag./*  w w  w  .ja  va 2 s  .  com*/
 * 
 * This flag is never removed!
 * 
 * @param flags
 * @param session
 */
private void trimFlags(Flags flags, MailboxSession session) {

    Flags permFlags = getPermanentFlags(session);

    Flag[] systemFlags = flags.getSystemFlags();
    for (Flag f : systemFlags) {
        if (f != Flag.RECENT && permFlags.contains(f) == false) {
            flags.remove(f);
        }
    }
    // if the permFlags contains the special USER flag we can skip this as
    // all user flags are allowed
    if (permFlags.contains(Flags.Flag.USER) == false) {
        String[] uFlags = flags.getUserFlags();
        for (String uFlag : uFlags) {
            if (permFlags.contains(uFlag) == false) {
                flags.remove(uFlag);
            }
        }
    }

}

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));
}