javax.mail.Flags.Flag Java Examples

The following examples show how to use javax.mail.Flags.Flag. 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: MessageMapperTest.java    From james-project with Apache License 2.0 7 votes vote down vote up
@Test
void getApplicableFlagShouldHaveEffectWhenUpdateFlagsByAddingThenComputingApplicableFlagsFromCurrentMailboxState() throws Exception {
    message1.setFlags(new Flags(Flag.ANSWERED));
    message2.setFlags(new Flags(Flag.DELETED));

    String customFlag = "custom1";
    FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(customFlag), FlagsUpdateMode.ADD);

    saveMessages();
    messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());

    assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
        .isEqualTo(FlagsBuilder.builder()
            .add(Flag.DELETED, Flag.ANSWERED, Flag.DRAFT, Flag.FLAGGED, Flag.SEEN)
            .add(customFlag)
            .build());
}
 
Example #2
Source File: CassandraMessageIdDAOTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void updateShouldUpdateUserFlag() {
    CassandraMessageId messageId = messageIdFactory.generate();
    CassandraId mailboxId = CassandraId.timeBased();
    MessageUid messageUid = MessageUid.of(1);

    ComposedMessageId composedMessageId = new ComposedMessageId(mailboxId, messageId, messageUid);
    testee.insert(ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags())
            .modSeq(ModSeq.of(1))
            .build())
        .block();

    ComposedMessageIdWithMetaData expectedComposedMessageId = ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags(Flag.USER))
            .modSeq(ModSeq.of(2))
            .build();
    testee.updateMetadata(expectedComposedMessageId).block();

    Optional<ComposedMessageIdWithMetaData> message = testee.retrieve(mailboxId, messageUid).block();
    assertThat(message.get()).isEqualTo(expectedComposedMessageId);
}
 
Example #3
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 #4
Source File: AbstractCombinationManagerTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void appendMessageFromMessageManagerAndSetInMailboxFromMessageIdManagerShouldUpdateApplicableFlag() throws Exception {
    Flags messageFlag = new FlagsBuilder()
        .add(Flag.ANSWERED)
        .add(USER_FLAGS_VALUE)
        .build();

    MessageId messageId = messageManager1.appendMessage(
        MessageManager.AppendCommand.builder()
            .withFlags(messageFlag)
            .build(mailContent), session)
        .getId().getMessageId();

    messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);

    Flags expected = ApplicableFlagBuilder
        .from(messageFlag)
        .build();

    assertThat(messageManager1.getApplicableFlags(session))
        .isEqualTo(expected);

    assertThat(messageManager2.getApplicableFlags(session))
        .isEqualTo(expected);
}
 
Example #5
Source File: LuceneMessageSearchIndex.java    From james-project with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the given {@link Flag} to a String
 */
private String toString(Flag flag) {
    if (Flag.ANSWERED.equals(flag)) {
        return "\\ANSWERED";
    } else if (Flag.DELETED.equals(flag)) {
        return "\\DELETED";
    } else if (Flag.DRAFT.equals(flag)) {
        return "\\DRAFT";
    } else if (Flag.FLAGGED.equals(flag)) {
        return "\\FLAGGED";
    } else if (Flag.RECENT.equals(flag)) {
        return "\\RECENT";
    } else if (Flag.SEEN.equals(flag)) {
        return "\\FLAG";
    } else {
        return flag.toString();
    }
}
 
Example #6
Source File: CassandraMessageIdDAOTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void updateShouldUpdateRecentFlag() {
    CassandraMessageId messageId = messageIdFactory.generate();
    CassandraId mailboxId = CassandraId.timeBased();
    MessageUid messageUid = MessageUid.of(1);

    ComposedMessageId composedMessageId = new ComposedMessageId(mailboxId, messageId, messageUid);
    testee.insert(ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags())
            .modSeq(ModSeq.of(1))
            .build())
        .block();

    ComposedMessageIdWithMetaData expectedComposedMessageId = ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags(Flag.RECENT))
            .modSeq(ModSeq.of(2))
            .build();
    testee.updateMetadata(expectedComposedMessageId).block();

    Optional<ComposedMessageIdWithMetaData> message = testee.retrieve(mailboxId, messageUid).block();
    assertThat(message.get()).isEqualTo(expectedComposedMessageId);
}
 
Example #7
Source File: CassandraMessageIdToImapUidDAOTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void updateShouldUpdateUserFlag() {
    CassandraMessageId messageId = messageIdFactory.of(UUIDs.timeBased());
    CassandraId mailboxId = CassandraId.timeBased();
    MessageUid messageUid = MessageUid.of(1);

    ComposedMessageId composedMessageId = new ComposedMessageId(mailboxId, messageId, messageUid);
    testee.insert(ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags())
            .modSeq(ModSeq.of(1))
            .build())
        .block();

    ComposedMessageIdWithMetaData expectedComposedMessageId = ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags(Flag.USER))
            .modSeq(ModSeq.of(2))
            .build();
    testee.updateMetadata(expectedComposedMessageId, ModSeq.of(1)).block();

    List<ComposedMessageIdWithMetaData> messages = testee.retrieve(messageId, Optional.of(mailboxId)).collectList().block();
    assertThat(messages).containsOnly(expectedComposedMessageId);
}
 
Example #8
Source File: AbstractCombinationManagerTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void setFlagsFromMessageManagerAndSetFlagsFromMessageIdManagerShouldUpdateSameApplicableFlag() throws Exception {
    Flags customFlag1 = new Flags(Flag.ANSWERED);
    Flags customFlag2 = new Flags("customFlag2");
    MessageId messageId = messageManager1.appendMessage(
        MessageManager.AppendCommand.builder()
            .withFlags(customFlag1)
            .build(mailContent), session)
        .getId().getMessageId();


    messageIdManager.setFlags(customFlag2, FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox1.getMailboxId()), session);
    messageManager1.setFlags(customFlag2, FlagsUpdateMode.ADD, MessageRange.all(), session);

    Flags applicableFlags = messageManager1.getApplicableFlags(session);

    assertThat(applicableFlags)
        .isEqualTo(ApplicableFlagBuilder
            .from(customFlag1, customFlag2)
            .build());
}
 
Example #9
Source File: MessageMapperTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void getApplicableFlagShouldHaveNotEffectWhenUpdateFlagsByReplaceThenIncrementalApplicableFlags() throws Exception {
    Assume.assumeTrue(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
    String customFlags = "custom";
    message1.setFlags(new Flags(customFlags));
    message2.setFlags(new Flags(Flag.DELETED));
    FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN), FlagsUpdateMode.REPLACE);

    saveMessages();
    messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());

    assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
        .isEqualTo(new FlagsBuilder()
            .add(Flag.DELETED, Flag.ANSWERED, Flag.DRAFT, Flag.FLAGGED, Flag.SEEN)
            .add(customFlags)
            .build());
}
 
Example #10
Source File: AbstractCombinationManagerTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void appendMessageFromMessageManagerAndSetFlagsFromMessageIdManagerShouldUnionApplicableFlag() throws Exception {
    Flags messageFlag = new FlagsBuilder()
        .add(Flag.ANSWERED)
        .add(USER_FLAGS_VALUE)
        .build();

    Flags deleted = new FlagsBuilder()
        .add(Flag.DELETED)
        .add(USER_FLAGS_VALUE, ANOTHER_USER_FLAGS_VALUE)
        .build();

    MessageId messageId = messageManager1.appendMessage(
        MessageManager.AppendCommand.builder()
            .withFlags(messageFlag)
            .build(mailContent), session)
        .getId().getMessageId();

    messageIdManager.setFlags(deleted, FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox1.getMailboxId()), session);

    assertThat(messageManager1.getApplicableFlags(session))
        .isEqualTo(ApplicableFlagBuilder
            .from(USER_FLAGS_VALUE, ANOTHER_USER_FLAGS_VALUE)
            .build());
}
 
Example #11
Source File: MessageIdMapperTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void setFlagsShouldWorkWhenCalledOnDuplicatedMailbox() throws Exception {
    message1.setUid(mapperProvider.generateMessageUid());
    message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    sut.save(message1);
    message2.setUid(mapperProvider.generateMessageUid());
    message2.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    sut.save(message2);
    message3.setUid(mapperProvider.generateMessageUid());
    message3.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    sut.save(message3);
    message4.setUid(mapperProvider.generateMessageUid());
    message4.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    sut.save(message4);

    MessageId messageId = message1.getMessageId();
    sut.setFlags(messageId, ImmutableList.of(message1.getMailboxId(), message1.getMailboxId()), new Flags(Flag.ANSWERED), FlagsUpdateMode.ADD);

    List<MailboxMessage> messages = sut.find(ImmutableList.of(messageId), MessageMapper.FetchType.Body);
    assertThat(messages).hasSize(1);
    assertThat(messages.get(0).isAnswered()).isTrue();
}
 
Example #12
Source File: MessageIdMapperTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void setFlagsShouldReturnUpdatedFlagsWhenMessageIsInOneMailbox() throws Exception {
    message1.setUid(mapperProvider.generateMessageUid());
    message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    sut.save(message1);

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

    ModSeq modSeq = mapperProvider.highestModSeq(benwaInboxMailbox);
    UpdatedFlags expectedUpdatedFlags = UpdatedFlags.builder()
        .uid(message1.getUid())
        .modSeq(modSeq)
        .oldFlags(new Flags())
        .newFlags(newFlags)
        .build();
    assertThat(flags.asMap()).containsOnly(MapEntry.entry(benwaInboxMailbox.getMailboxId(), ImmutableList.of(expectedUpdatedFlags)));
}
 
Example #13
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the list of messages that have no {@link javax.mail.Flags.Flag#DELETED} flag set for current user.
 * 
 * @return the list of non-deleted messages.
 */
@Override
protected List<SimpleStoredMessage> getNonDeletedMessagesInternal()
{
    if (logger.isDebugEnabled())
    {
        logger.debug("[getNonDeletedMessagesInternal] " + this);
    }
    List<SimpleStoredMessage> result = new ArrayList<SimpleStoredMessage>();

    Collection<SimpleStoredMessage> values = getMessagesInternal();
    for (SimpleStoredMessage message : values)
    {
        if (!getFlags(message).contains(Flags.Flag.DELETED))
        {
            result.add(message);
        }

    }
    if (logger.isDebugEnabled() && folderInfo != null)
    {
        logger.debug(folderInfo.getName() + " - Non deleted messages count:" + result.size());
    }
    return result;
}
 
Example #14
Source File: CassandraMessageIdDAOTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void updateShouldUpdateDeletedFlag() {
    CassandraMessageId messageId = messageIdFactory.generate();
    CassandraId mailboxId = CassandraId.timeBased();
    MessageUid messageUid = MessageUid.of(1);

    ComposedMessageId composedMessageId = new ComposedMessageId(mailboxId, messageId, messageUid);
    testee.insert(ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags())
            .modSeq(ModSeq.of(1))
            .build())
        .block();

    ComposedMessageIdWithMetaData expectedComposedMessageId = ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags(Flag.DELETED))
            .modSeq(ModSeq.of(2))
            .build();
    testee.updateMetadata(expectedComposedMessageId).block();

    Optional<ComposedMessageIdWithMetaData> message = testee.retrieve(mailboxId, messageUid).block();
    assertThat(message.get()).isEqualTo(expectedComposedMessageId);
}
 
Example #15
Source File: SelectedMailboxImpl.java    From james-project with Apache License 2.0 6 votes vote down vote up
private boolean interestingFlags(UpdatedFlags updated) {
    boolean result;
    final Iterator<Flags.Flag> it = updated.systemFlagIterator();
    if (it.hasNext()) {
        final Flags.Flag flag = it.next();
        if (flag.equals(uninterestingFlag)) {
            result = false;
        } else {
            result = true;
        }
    } else {
        result = false;
    }
    // See if we need to check the user flags
    if (result == false) {
        final Iterator<String> userIt = updated.userFlagIterator();
        result = userIt.hasNext();
    }
    return result;
}
 
Example #16
Source File: MessageMapperTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void getApplicableFlagShouldUnionAllMessageFlagsExceptRecentAndUser() throws Exception {
    message1.setFlags(new Flags(Flag.ANSWERED));
    message2.setFlags(new Flags(Flag.DELETED));

    Flags recentAndUser = new Flags(Flag.RECENT);
    recentAndUser.add(Flag.USER);
    recentAndUser.add(CUSTOMS_USER_FLAGS_VALUE);
    message3.setFlags(recentAndUser);

    saveMessages();

    assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
        .isEqualTo(FlagsBuilder.builder()
            .add(Flag.DELETED, Flag.ANSWERED, Flag.DRAFT, Flag.FLAGGED, Flag.SEEN)
            .add(CUSTOMS_USER_FLAGS_VALUE)
            .build());
}
 
Example #17
Source File: LuceneMailboxMessageSearchIndexTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void updateShouldUpdateFlags() throws Exception {
    Flags newFlags = new Flags(Flags.Flag.DRAFT);
    UpdatedFlags updatedFlags = UpdatedFlags.builder()
        .uid(uid2)
        .modSeq(MOD_SEQ)
        .oldFlags(new Flags(Flag.ANSWERED))
        .newFlags(newFlags)
        .build();

    index.update(session, mailbox.getMailboxId(), Lists.newArrayList(updatedFlags)).block();

    SearchQuery query = SearchQuery.of(SearchQuery.flagIsSet(Flags.Flag.DRAFT));
    assertThat(index.search(session, mailbox, query))
        .containsExactly(uid2);
}
 
Example #18
Source File: MailboxFolder.java    From javamail-mock2 with Apache License 2.0 6 votes vote down vote up
public synchronized Message[] expunge() throws MessagingException {
    checkExists();
    final List<Message> expunged = new ArrayList<Message>();
    for (final Message msg : getByFlags(new Flags(Flag.DELETED), true)) {

        expunged.add(messages.remove(((MockMessage) msg).getMockid()));
        ((MockMessage) msg).setExpunged(true);

        for (final MailboxEventListener mailboxEventListener : mailboxEventListeners) {
            mailboxEventListener.messageExpunged(this, (MockMessage) msg, true);
        }
    }

    logger.debug(expunged.size() + " messages expunged (deleted) from" + getFullName());
    return expunged.toArray(new Message[expunged.size()]);

}
 
Example #19
Source File: MessageMapperTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void getApplicableFlagShouldHaveEffectWhenUnsetMessageFlagThenComputingApplicableFlagsFromCurrentMailboxState() throws Exception {
    Assume.assumeFalse(mapperProvider.getSupportedCapabilities().contains(Capabilities.INCREMENTAL_APPLICABLE_FLAGS));
    String customFlag1 = "custom1";
    String customFlag2 = "custom2";
    String customFlag3 = "custom3";
    message1.setFlags(new FlagsBuilder().add(customFlag1, customFlag2).build());
    message2.setFlags(new Flags(customFlag3));
    FlagsUpdateCalculator newFlags = new FlagsUpdateCalculator(new Flags(), FlagsUpdateMode.REPLACE);

    saveMessages();
    messageMapper.updateFlags(benwaInboxMailbox, newFlags, message1.getUid().toRange());

    assertThat(messageMapper.getApplicableFlag(benwaInboxMailbox))
        .isEqualTo(FlagsBuilder.builder()
            .add(Flag.DELETED, Flag.ANSWERED, Flag.DRAFT, Flag.FLAGGED, Flag.SEEN)
            .add(customFlag3)
            .build());
}
 
Example #20
Source File: MessageIdMapperTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void setFlagsShouldUpdateMessageFlagsWhenRemoveMode() throws Exception {
    Flags messageFlags = new FlagsBuilder().add(Flags.Flag.RECENT, Flags.Flag.FLAGGED)
        .build();

    message1.setUid(mapperProvider.generateMessageUid());
    message1.setFlags(messageFlags);
    message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    sut.save(message1);

    MessageId messageId = message1.getMessageId();
    Flags newFlags = new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.FLAGGED)
        .add("userflag")
        .build();

    sut.setFlags(messageId, ImmutableList.of(message1.getMailboxId()), newFlags, FlagsUpdateMode.REMOVE);

    List<MailboxMessage> messages = sut.find(ImmutableList.of(messageId), MessageMapper.FetchType.Body);
    assertThat(messages).hasSize(1);
    assertThat(messages.get(0).isRecent()).isTrue();
    assertThat(messages.get(0).isFlagged()).isFalse();
}
 
Example #21
Source File: CassandraMessageIdDAOTest.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Test
void updateShouldUpdateFlaggedFlag() {
    CassandraMessageId messageId = messageIdFactory.generate();
    CassandraId mailboxId = CassandraId.timeBased();
    MessageUid messageUid = MessageUid.of(1);

    ComposedMessageId composedMessageId = new ComposedMessageId(mailboxId, messageId, messageUid);
    testee.insert(ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags())
            .modSeq(ModSeq.of(1))
            .build())
        .block();

    ComposedMessageIdWithMetaData expectedComposedMessageId = ComposedMessageIdWithMetaData.builder()
            .composedMessageId(composedMessageId)
            .flags(new Flags(Flag.FLAGGED))
            .modSeq(ModSeq.of(2))
            .build();
    testee.updateMetadata(expectedComposedMessageId).block();

    Optional<ComposedMessageIdWithMetaData> message = testee.retrieve(mailboxId, messageUid).block();
    assertThat(message.get()).isEqualTo(expectedComposedMessageId);
}
 
Example #22
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *  Creates the EML message in the specified folder.
 *  
 *  @param folderFileInfo The folder to create message in.
 *  @param message The original MimeMessage.
 *  @return ID of the new message created 
 * @throws FileNotFoundException 
 * @throws FileExistsException 
 * @throws MessagingException 
 * @throws IOException 
 */
private long createMimeMessageInFolder(
        FileInfo folderFileInfo,
        MimeMessage message,
        Flags flags)
        throws FileExistsException, FileNotFoundException, IOException, MessagingException 
{
    String name = AlfrescoImapConst.MESSAGE_PREFIX + GUID.generate();
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    FileInfo messageFile = fileFolderService.create(folderFileInfo.getNodeRef(), name, ContentModel.TYPE_CONTENT);
    final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
    name = AlfrescoImapConst.MESSAGE_PREFIX  + newMessageUid + AlfrescoImapConst.EML_EXTENSION;
    fileFolderService.rename(messageFile.getNodeRef(), name);
    Flags newFlags = new Flags(flags);
    newFlags.add(Flag.RECENT);
    imapService.setFlags(messageFile, newFlags, true);
    
    if (extractAttachmentsEnabled)
    {
        imapService.extractAttachments(messageFile.getNodeRef(), message);
    }
    // Force persistence of the message to the repository
    new IncomingImapMessage(messageFile, serviceRegistry, message);
    return newMessageUid;        
}
 
Example #23
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Marks all messages in the folder as deleted using {@link javax.mail.Flags.Flag#DELETED} flag.
 */
@Override
public void deleteAllMessagesInternal() throws FolderException
{
    if (isReadOnly())
    {
        throw new FolderException("Can't delete all - Permission denied");
    }
    
    for (Map.Entry<Long, FileInfo> entry : searchMails().entrySet())
    {
        imapService.setFlag(entry.getValue(), Flags.Flag.DELETED, true);
        // comment out to physically remove content.
        // fileFolderService.delete(fileInfo.getNodeRef());
    }
}
 
Example #24
Source File: OldKeywordTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void applyStateShouldPreserveCustomFlag() {
    Optional<OldKeyword> testee = OldKeyword.builder()
        .isUnread(Optional.of(false))
        .computeOldKeyword();

    String customFlag = "custom";
    assertThat(testee.get().applyToState(new Flags(customFlag)))
        .isEqualTo(new FlagsBuilder().add(Flag.SEEN).add(customFlag).build());
}
 
Example #25
Source File: MessageIdMapperTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void setFlagsShouldUpdateFlagsWhenMessageIsInOneMailbox() throws Exception {
    message1.setUid(mapperProvider.generateMessageUid());
    message1.setModSeq(mapperProvider.generateModSeq(benwaInboxMailbox));
    sut.save(message1);

    MessageId messageId = message1.getMessageId();
    sut.setFlags(messageId, ImmutableList.of(message1.getMailboxId()), new Flags(Flag.ANSWERED), FlagsUpdateMode.ADD);

    List<MailboxMessage> messages = sut.find(ImmutableList.of(messageId), MessageMapper.FetchType.Body);
    assertThat(messages).hasSize(1);
    assertThat(messages.get(0).isAnswered()).isTrue();
}
 
Example #26
Source File: FilterToCriteriaTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void filterConditionShouldMapWhenIsFlagged() {
    Stream<SearchQuery.Criterion> criteria = new FilterToCriteria().convert(FilterCondition.builder()
            .isFlagged(true)
            .build());

    assertThat(criteria).containsExactly(SearchQuery.flagIsSet(Flag.FLAGGED));
}
 
Example #27
Source File: FilterToCriteriaTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void filterConditionShouldMapWhenIsAnswered() {
    Stream<SearchQuery.Criterion> criteria = new FilterToCriteria().convert(FilterCondition.builder()
            .isAnswered(true)
            .build());

    assertThat(criteria).containsExactly(SearchQuery.flagIsSet(Flag.ANSWERED));
}
 
Example #28
Source File: SearchProcessorTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
public void testAND() throws Exception {
    expectsGetSelectedMailbox();
    List<SearchKey> keys = new ArrayList<>();
    keys.add(SearchKey.buildOn(DAY_MONTH_YEAR));
    keys.add(SearchKey.buildOld());
    keys.add(SearchKey.buildLarger(SIZE));
    List<Criterion> criteria = new ArrayList<>();
    criteria.add(SearchQuery.internalDateOn(getDate(DAY, MONTH, YEAR), DateResolution.Day));
    criteria.add(SearchQuery.flagIsUnSet(Flag.RECENT));
    criteria.add(SearchQuery.sizeGreaterThan(SIZE));
    check(SearchKey.buildAnd(keys), SearchQuery.and(criteria));
}
 
Example #29
Source File: MessageIdMapperTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void setFlagsShouldUpdateModSeqWhenMessageIsInOneMailbox() throws Exception {
    message1.setUid(mapperProvider.generateMessageUid());
    ModSeq modSeq = mapperProvider.generateModSeq(benwaInboxMailbox);
    message1.setModSeq(modSeq);
    sut.save(message1);

    MessageId messageId = message1.getMessageId();
    sut.setFlags(messageId, ImmutableList.of(message1.getMailboxId()), new Flags(Flag.ANSWERED), FlagsUpdateMode.ADD);

    List<MailboxMessage> messages = sut.find(ImmutableList.of(messageId), MessageMapper.FetchType.Body);
    assertThat(messages).hasSize(1);
    assertThat(messages.get(0).getModSeq()).isGreaterThan(modSeq);
}
 
Example #30
Source File: MessageMapperTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void copiedRecentMessageShouldBeMarkedAsRecent() throws MailboxException {
    saveMessages();
    message6.setFlags(new Flags(Flags.Flag.RECENT));
    MessageMetaData metaData = messageMapper.copy(benwaInboxMailbox, SimpleMailboxMessage.copy(benwaInboxMailbox.getMailboxId(), message6));
    assertThat(
        messageMapper.findInMailbox(benwaInboxMailbox,
            MessageRange.one(metaData.getUid()),
            MessageMapper.FetchType.Metadata,
            LIMIT
        ).next()
            .isRecent()
    ).isTrue();
}