Java Code Examples for javax.mail.Flags#contains()

The following examples show how to use javax.mail.Flags#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StoreMessageManager.java    From james-project with Apache License 2.0 6 votes vote down vote up
/**
 * 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.
 * 
 * This flag is never removed!
 */
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);
            }
        }
    }

}
 
Example 2
Source File: MaildirMessageName.java    From james-project with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a String that represents the provided Flags  
 * @param flags The flags to encode
 * @return A String valid for Maildir
 */
public String encodeFlags(Flags flags) {
    StringBuilder localFlagsString = new StringBuilder(":2,");
    if (flags.contains(Flags.Flag.DRAFT)) {
        localFlagsString.append(FLAG_DRAFT);
    }
    if (flags.contains(Flags.Flag.FLAGGED)) {
        localFlagsString.append(FLAG_FLAGGED);
    }
    if (flags.contains(Flags.Flag.ANSWERED)) {
        localFlagsString.append(FLAG_ANSWERD);
    }
    if (flags.contains(Flags.Flag.SEEN)) {
        localFlagsString.append(FLAG_SEEN);
    }
    if (flags.contains(Flags.Flag.DELETED)) {
        localFlagsString.append(FLAG_DELETED);
    }
    return localFlagsString.toString();
}
 
Example 3
Source File: CassandraIndexTableHandler.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Mono<Void> updateDeletedMessageProjectionOnDelete(CassandraId mailboxId, MessageUid uid, Flags flags) {
    if (flags.contains(Flags.Flag.DELETED)) {
        return deletedMessageDAO.removeDeleted(mailboxId, uid);
    }

    return Mono.empty();
}
 
Example 4
Source File: SimpleMailboxMessage.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
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();
}
 
Example 5
Source File: Keywords.java    From james-project with Apache License 2.0 5 votes vote down vote up
public Flags asFlagsWithRecentAndDeletedFrom(Flags originFlags) {
    Flags flags = asFlags();
    if (originFlags.contains(Flags.Flag.DELETED)) {
        flags.add(Flags.Flag.DELETED);
    }
    if (originFlags.contains(Flags.Flag.RECENT)) {
        flags.add(Flags.Flag.RECENT);
    }

    return flags;
}
 
Example 6
Source File: StoreRightManager.java    From james-project with Apache License 2.0 5 votes vote down vote up
private boolean checkWriteFlag(Rfc4314Rights rights, Flags sharedPermanentFlags) {
    return rights.contains(Right.Write) &&
        (sharedPermanentFlags.contains(Flags.Flag.ANSWERED) ||
            sharedPermanentFlags.contains(Flags.Flag.DRAFT) ||
            sharedPermanentFlags.contains(Flags.Flag.FLAGGED) ||
            sharedPermanentFlags.contains(Flags.Flag.RECENT) ||
            sharedPermanentFlags.contains(Flags.Flag.USER));
}
 
Example 7
Source File: ImapServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void expungeMessage(FileInfo fileInfo)
{
    Flags flags = getFlags(fileInfo);
    if (flags.contains(Flags.Flag.DELETED))
    {
        // See MNT-12259
        //fileFolderService.delete(fileInfo.getNodeRef());
        hideAndDelete(fileInfo.getNodeRef());
        messageCache.remove(fileInfo.getNodeRef());
    }
}
 
Example 8
Source File: CassandraIndexTableHandler.java    From james-project with Apache License 2.0 5 votes vote down vote up
private Mono<Void> updateRecentOnDelete(CassandraId mailboxId, MessageUid uid, Flags flags) {
    if (flags.contains(Flags.Flag.RECENT)) {
        return mailboxRecentDAO.removeFromRecent(mailboxId, uid);
    }

    return Mono.empty();
}
 
Example 9
Source File: GetMessagesMethodStepdefs.java    From james-project with Apache License 2.0 5 votes vote down vote up
private void appendMessage(String messageName, String mailbox, Flags flags) throws Exception {
    ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
    boolean isRecent = flags.contains(Flags.Flag.RECENT);
    MessageId id = mainStepdefs.mailboxProbe.appendMessage(userStepdefs.getConnectedUser(),
        MailboxPath.forUser(Username.of(userStepdefs.getConnectedUser()), mailbox),
        new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
        Date.from(dateTime.toInstant()), isRecent, flags)
        .getMessageId();
    messageIdStepdefs.addMessageId(messageName, id);
    mainStepdefs.awaitMethod.run();
}
 
Example 10
Source File: MaildirMailboxMessage.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public void setFlags(Flags flags) {
    if (flags != null) {
        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);
    }
}
 
Example 11
Source File: AbstractJPAMailboxMessage.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
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);

    String[] userflags = flags.getUserFlags();
    userFlags.clear();
    for (String userflag : userflags) {
        userFlags.add(new JPAUserFlag(userflag));
    }
}
 
Example 12
Source File: OldKeyword.java    From james-project with Apache License 2.0 5 votes vote down vote up
public Flags applyToState(Flags currentFlags) {
    Flags newStateFlags = new Flags();

    if (isFlagged().orElse(currentFlags.contains(Flags.Flag.FLAGGED))) {
        newStateFlags.add(Flags.Flag.FLAGGED);
    }
    if (isAnswered().orElse(currentFlags.contains(Flags.Flag.ANSWERED))) {
        newStateFlags.add(Flags.Flag.ANSWERED);
    }
    if (isDraft().orElse(currentFlags.contains(Flags.Flag.DRAFT))) {
        newStateFlags.add(Flags.Flag.DRAFT);
    }
    if (isForwarded().orElse(currentFlags.contains(new Flags("$Forwarded")))) {
        newStateFlags.add(new Flags("$Forwarded"));
    }
    boolean shouldMessageBeMarkSeen = isUnread().map(b -> !b).orElse(currentFlags.contains(Flags.Flag.SEEN));
    if (shouldMessageBeMarkSeen) {
        newStateFlags.add(Flags.Flag.SEEN);
    }
    Arrays.stream(currentFlags.getUserFlags())
        .forEach(newStateFlags::add);
    if (currentFlags.contains(Flags.Flag.RECENT)) {
        newStateFlags.add(Flags.Flag.RECENT);
    }
    if (currentFlags.contains(Flags.Flag.DELETED)) {
        newStateFlags.add(Flags.Flag.DELETED);
    }
    return newStateFlags;
}
 
Example 13
Source File: MessageFlags.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * Returns IMAP formatted String naming flags.
 * 
 * @return <code>Collection</code> of <code>String</code>'s naming the
 *         flags.
 */
public static Collection<String> names(Flags flags) {
    final Collection<String> results = new ArrayList<>();
    if (flags.contains(Flags.Flag.ANSWERED)) {
        results.add(ANSWERED_OUTPUT_CAPITALISED);
    }
    if (flags.contains(Flags.Flag.DELETED)) {
        results.add(DELETED_OUTPUT_CAPITALISED);
    }
    if (flags.contains(Flags.Flag.DRAFT)) {
        results.add(DRAFT_OUTPUT_CAPITALISED);
    }
    if (flags.contains(Flags.Flag.FLAGGED)) {
        results.add(FLAGGED_OUTPUT_CAPITALISED);
    }
    if (flags.contains(Flags.Flag.RECENT)) {
        results.add(RECENT_OUTPUT_CAPITALISED);
    }
    if (flags.contains(Flags.Flag.SEEN)) {
        results.add(SEEN_OUTPUT_CAPITALISED);
    }
    
    // Add user flags
    String[] userFlags = flags.getUserFlags();
    Collections.addAll(results, userFlags);

    if (flags.contains(Flags.Flag.USER)) {
        results.add(USER_OUTPUT_CAPITALISED);
    }
    return results;
}
 
Example 14
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns count of messages with {@link javax.mail.Flags.Flag#RECENT} flag.
 * If {@code reset} parameter is {@code true} - removes {@link javax.mail.Flags.Flag#RECENT} flag from
 * the message for current user.
 * 
 * @param reset - if true the {@link javax.mail.Flags.Flag#RECENT} will be deleted for current user if exists.
 * @return returns count of recent messages.
 */
@Override
public int getRecentCount(boolean reset)
{
    int recent = getFolderStatus().recentCount;
    if (reset && recent > 0)
    {
        CommandCallback<Void> command = new CommandCallback<Void>()
        {
            public Void command() throws Throwable
            {
                for (FileInfo fileInfo : folderStatus.search.values())
                {
                    Flags flags = imapService.getFlags(fileInfo);
                    if (flags.contains(Flags.Flag.RECENT))
                    {
                        imapService.setFlag(fileInfo, Flags.Flag.RECENT, false);
                    }
                }
                return null;
            }
        };
        try
        {
            command.run();
        }
        catch (AccessDeniedException ade)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("Access denied to reset RECENT FLAG");
            }
        }
    }
    return recent;        
}
 
Example 15
Source File: CassandraIndexTableHandler.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Mono<Void> decrementCountersOnDelete(CassandraId mailboxId, Flags flags) {
    if (flags.contains(Flags.Flag.SEEN)) {
        return mailboxCounterDAO.decrementCount(mailboxId);
    }
    return mailboxCounterDAO.decrementUnseenAndCount(mailboxId);
}
 
Example 16
Source File: CassandraIndexTableHandler.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Mono<Void> incrementCountersOnSave(CassandraId mailboxId, Flags flags) {
    if (flags.contains(Flags.Flag.SEEN)) {
        return mailboxCounterDAO.incrementCount(mailboxId);
    }
    return mailboxCounterDAO.incrementUnseenAndCount(mailboxId);
}
 
Example 17
Source File: CassandraIndexTableHandler.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Mono<Void> updateFirstUnseenOnAdd(CassandraId mailboxId, Flags flags, MessageUid uid) {
    if (flags.contains(Flags.Flag.SEEN)) {
        return Mono.empty();
    }
    return firstUnseenDAO.addUnread(mailboxId, uid);
}
 
Example 18
Source File: UpdatedFlags.java    From james-project with Apache License 2.0 4 votes vote down vote up
private static boolean isChanged(Flags original, Flags updated, String userFlag) {
    return original != null && updated != null && (original.contains(userFlag) ^ updated.contains(userFlag));
}
 
Example 19
Source File: CassandraIndexTableHandler.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Mono<Void> updateFirstUnseenOnDelete(CassandraId mailboxId, Flags flags, MessageUid uid) {
    if (flags.contains(Flags.Flag.SEEN)) {
        return Mono.empty();
    }
    return firstUnseenDAO.removeUnread(mailboxId, uid);
}
 
Example 20
Source File: StoreRightManager.java    From james-project with Apache License 2.0 4 votes vote down vote up
private boolean checkSeenFlag(Rfc4314Rights rights, Flags sharedPermanentFlags) {
    return sharedPermanentFlags.contains(Flags.Flag.SEEN) && rights.contains(Right.WriteSeenFlag);
}