javax.mail.Flags Java Examples
The following examples show how to use
javax.mail.Flags.
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: GreenMailServer.java From micro-integrator with Apache License 2.0 | 7 votes |
/** * Delete all emails in the inbox. * * @param protocol protocol used to connect to the server * @throws MessagingException if we're unable to connect to the store */ public static void deleteAllEmails(String protocol, GreenMailUser user) throws MessagingException { Folder inbox = null; Store store = getConnection(user, protocol); try { inbox = store.getFolder(EMAIL_INBOX); inbox.open(Folder.READ_WRITE); Message[] messages = inbox.getMessages(); for (Message message : messages) { message.setFlag(Flags.Flag.DELETED, true); log.info("Deleted email Subject : " + message.getSubject()); } } finally { if (inbox != null) { inbox.close(true); } if (store != null) { store.close(); } } }
Example #2
Source File: CassandraMessageIdToImapUidDAO.java From james-project with Apache License 2.0 | 6 votes |
public Mono<Boolean> updateMetadata(ComposedMessageIdWithMetaData composedMessageIdWithMetaData, ModSeq oldModSeq) { ComposedMessageId composedMessageId = composedMessageIdWithMetaData.getComposedMessageId(); Flags flags = composedMessageIdWithMetaData.getFlags(); return cassandraAsyncExecutor.executeReturnApplied(update.bind() .setLong(MOD_SEQ, composedMessageIdWithMetaData.getModSeq().asLong()) .setBool(ANSWERED, flags.contains(Flag.ANSWERED)) .setBool(DELETED, flags.contains(Flag.DELETED)) .setBool(DRAFT, flags.contains(Flag.DRAFT)) .setBool(FLAGGED, flags.contains(Flag.FLAGGED)) .setBool(RECENT, flags.contains(Flag.RECENT)) .setBool(SEEN, flags.contains(Flag.SEEN)) .setBool(USER, flags.contains(Flag.USER)) .setSet(USER_FLAGS, ImmutableSet.copyOf(flags.getUserFlags())) .setUUID(MESSAGE_ID, ((CassandraMessageId) composedMessageId.getMessageId()).get()) .setUUID(MAILBOX_ID, ((CassandraId) composedMessageId.getMailboxId()).asUuid()) .setLong(IMAP_UID, composedMessageId.getUid().asLong()) .setLong(MOD_SEQ_CONDITION, oldModSeq.asLong())); }
Example #3
Source File: MailboxFolder.java From javamail-mock2 with Apache License 2.0 | 6 votes |
public synchronized Message[] getByFlags(final Flags flags, final boolean mustSet /*final Folder folder*/) throws MessagingException { checkExists(); final List<MockMessage> sms = new ArrayList<MockMessage>(); int num = 0; for (final MockMessage mockMessage : new TreeSet<MockMessage>(messages.values())) { if (mustSet && mockMessage.getFlags().contains(flags) || !mustSet && !mockMessage.getFlags().contains(flags)) { mockMessage.setMessageNumber(++num); // mockMessage.setFolder(folder); sms.add(mockMessage); } } logger.debug("getByFlags() for " + getFullName() + " returns " + sms.size()); return sms.toArray(new Message[sms.size()]); }
Example #4
Source File: CommandParser.java From greenmail with Apache License 2.0 | 6 votes |
public void setFlag(String flagString, Flags flags) { if (flagString.equalsIgnoreCase(MessageFlags.ANSWERED)) { flags.add(Flags.Flag.ANSWERED); } else if (flagString.equalsIgnoreCase(MessageFlags.DELETED)) { flags.add(Flags.Flag.DELETED); } else if (flagString.equalsIgnoreCase(MessageFlags.DRAFT)) { flags.add(Flags.Flag.DRAFT); } else if (flagString.equalsIgnoreCase(MessageFlags.FLAGGED)) { flags.add(Flags.Flag.FLAGGED); } else if (flagString.equalsIgnoreCase(MessageFlags.SEEN)) { flags.add(Flags.Flag.SEEN); } else if (flagString.equalsIgnoreCase(MessageFlags.RECENT)) { flags.add(Flags.Flag.RECENT); } else { // User flag flags.add(flagString); } }
Example #5
Source File: FlagsExtraField.java From james-project with Apache License 2.0 | 6 votes |
private static String systemFlagToString(Flags.Flag flag) throws RuntimeException { if (flag == Flags.Flag.ANSWERED) { return "\\ANSWERED"; } else if (flag == Flags.Flag.DELETED) { return "\\DELETED"; } else if (flag == Flags.Flag.DRAFT) { return "\\DRAFT"; } else if (flag == Flags.Flag.FLAGGED) { return "\\FLAGGED"; } else if (flag == Flags.Flag.RECENT) { return "\\RECENT"; } else if (flag == Flags.Flag.SEEN) { return "\\SEEN"; } throw new RuntimeException("Unknown system flag"); }
Example #6
Source File: CassandraMessageIdToImapUidDAOTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void updateShouldUpdateRecentFlag() { 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.RECENT)) .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 #7
Source File: GetMessageListMethodTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void getMessageListUnsetAnsweredFilterShouldReturnOnlyNotAnsweredMessages() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE.asString(), "mailbox"); ComposedMessageId messageNotAnswered = mailboxProbe.appendMessage(ALICE.asString(), ALICE_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); ComposedMessageId messageAnswered = mailboxProbe.appendMessage(ALICE.asString(), ALICE_MAILBOX, ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags(Flags.Flag.ANSWERED)); await(); given() .header("Authorization", aliceAccessToken.asString()) .body("[[\"getMessageList\", {\"filter\":{\"isAnswered\":\"false\"}}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", allOf( containsInAnyOrder(messageNotAnswered.getMessageId().serialize()), not(containsInAnyOrder(messageAnswered.getMessageId().serialize())))); }
Example #8
Source File: GetMessageListMethodTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void getMessageListShouldReturnAllMessagesWhenPositionIsNotGiven() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE.asString(), "mailbox"); LocalDate date = LocalDate.now(); ComposedMessageId message1 = mailboxProbe.appendMessage(ALICE.asString(), ALICE_MAILBOX, new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), convertToDate(date.plusDays(1)), false, new Flags()); ComposedMessageId message2 = mailboxProbe.appendMessage(ALICE.asString(), ALICE_MAILBOX, new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), convertToDate(date), false, new Flags()); await(); given() .header("Authorization", aliceAccessToken.asString()) .body("[[\"getMessageList\", {}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", containsInAnyOrder(message1.getMessageId().serialize(), message2.getMessageId().serialize())); }
Example #9
Source File: CassandraIndexTableHandlerTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void updateIndexOnFlagsUpdateShouldRemoveMessageInDeletedMessageWhenDeletedFlagIsUnset() { MailboxMessage message = mock(MailboxMessage.class); when(message.createFlags()).thenReturn(new Flags()); when(message.getUid()).thenReturn(MESSAGE_UID); testee.updateIndexOnAdd(message, MAILBOX_ID).block(); deletedMessageDAO.addDeleted(MAILBOX_ID, MESSAGE_UID).block(); testee.updateIndexOnFlagsUpdate(MAILBOX_ID, UpdatedFlags.builder() .uid(MESSAGE_UID) .newFlags(new Flags()) .oldFlags(new Flags(Flags.Flag.DELETED)) .modSeq(MODSEQ) .build()).block(); assertThat( deletedMessageDAO .retrieveDeletedMessage(MAILBOX_ID, MessageRange.all()) .collectList() .block()) .isEmpty(); }
Example #10
Source File: MailboxMessageAssertTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void messageAssertShouldSucceedWithTwoEqualsMessages() throws IOException { String headerString = "name: headerName\n\n"; String bodyString = "body\n.\n"; Date date = new Date(); SimpleMailboxMessage message1 = new SimpleMailboxMessage(MESSAGE_ID, date, headerString.length() + bodyString.length(), headerString.length(), new SharedByteArrayInputStream((headerString + bodyString).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID); message1.setUid(UID); SimpleMailboxMessage message2 = new SimpleMailboxMessage(MESSAGE_ID, date, headerString.length() + bodyString.length(), headerString.length(), new SharedByteArrayInputStream((headerString + bodyString).getBytes()), new Flags(), new PropertyBuilder(), MAILBOX_ID); message2.setUid(UID); MessageAssert.assertThat(message1).isEqualTo(message2, MessageMapper.FetchType.Full); }
Example #11
Source File: CassandraIndexTableHandlerTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void updateIndexOnDeleteShouldNotDecrementUnseenMessageCountWhenSeen() throws Exception { MailboxMessage message = mock(MailboxMessage.class); when(message.createFlags()).thenReturn(new Flags()); when(message.getUid()).thenReturn(MESSAGE_UID); testee.updateIndexOnAdd(message, MAILBOX_ID).block(); testee.updateIndexOnDelete(new ComposedMessageIdWithMetaData( new ComposedMessageId(MAILBOX_ID, CASSANDRA_MESSAGE_ID, MESSAGE_UID), new Flags(Flags.Flag.SEEN), MODSEQ), MAILBOX_ID).block(); Long actual = mailboxCounterDAO.countUnseenMessagesInMailbox(mailbox).block(); assertThat(actual).isEqualTo(1); }
Example #12
Source File: AbstractCombinationManagerTest.java From james-project with Apache License 2.0 | 6 votes |
@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 #13
Source File: AlfrescoImapFolder.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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: CassandraMessageIdToImapUidDAOTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void updateShouldUpdateDeletedFlag() { 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.DELETED)) .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 #15
Source File: AbstractCombinationManagerTest.java From james-project with Apache License 2.0 | 6 votes |
@Test void getMetadataFromMessageManagerShouldReturnRecentMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { Flags recent = new Flags(Flag.RECENT); ComposedMessageId messageId = messageManager1.appendMessage( MessageManager.AppendCommand.builder() .withFlags(recent) .build(mailContent), session).getId(); long mailbox2NextUid = messageManager2.getMetaData(true, session, MessageManager.MailboxMetaData.FetchGroup.UNSEEN_COUNT).getUidNext().asLong(); messageIdManager.setInMailboxes(messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session); List<MessageUid> messageUids = messageManager2.getMetaData(true, session, MessageManager.MailboxMetaData.FetchGroup.UNSEEN_COUNT).getRecent(); assertThat(messageUids).hasSize(1); assertThat(messageUids.get(0).asLong()).isGreaterThanOrEqualTo(mailbox2NextUid); }
Example #16
Source File: AbstractMessageIdManagerStorageTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void setFlagsShouldThrowExceptionWhenSetFlagsOnOtherSession() { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); assertThatThrownBy(() -> messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), bobSession)) .isInstanceOf(MailboxNotFoundException.class); }
Example #17
Source File: MaildirMessageName.java From james-project with Apache License 2.0 | 5 votes |
/** * Decodes the flags part of the file name if necessary and returns the appropriate Flags object. * @return The {@link Flags} of this message */ public Flags getFlags() { if (flags == null) { split(); if (flagsString == null) { return null; } if (flagsString.length() >= 3) { flags = decodeFlags(flagsString.substring(3)); // skip the ":2," part } } return flags; }
Example #18
Source File: DecoderUtilsTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void customFlagShouldBeAdded() throws Exception { Flags flags = new Flags(); DecoderUtils.setFlag(A_CUSTOM_FLAG, flags); assertThat(flags.contains(A_CUSTOM_FLAG)) .describedAs("Unknown flags should be added") .isTrue(); }
Example #19
Source File: UpdatedFlagsTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void isModifiedToUnsetShouldReturnTrueWhenFlagOnlyInOldFlag() { UpdatedFlags updatedFlags = UpdatedFlags.builder() .newFlags(new Flags()) .oldFlags(new Flags(Flags.Flag.RECENT)) .uid(UID) .modSeq(MOD_SEQ) .build(); assertThat(updatedFlags.isModifiedToUnset(Flags.Flag.RECENT)).isTrue(); }
Example #20
Source File: CassandraIndexTableHandlerTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void updateIndexOnAddShouldNotAddRecentWhenNoRecent() { MailboxMessage message = mock(MailboxMessage.class); when(message.createFlags()).thenReturn(new Flags()); when(message.getUid()).thenReturn(MESSAGE_UID); testee.updateIndexOnAdd(message, MAILBOX_ID).block(); assertThat(mailboxRecentsDAO.getRecentMessageUidsInMailbox(MAILBOX_ID) .collectList() .block()) .isEmpty(); }
Example #21
Source File: StoredMessage.java From greenmail with Apache License 2.0 | 5 votes |
public void setFlags(Flags flags, boolean value) { try { getMimeMessage().setFlags(flags, value); } catch (MessagingException e) { throw new IllegalStateException("Can not set flags " + flags + " to " + value, e); } }
Example #22
Source File: GetMessagesMethodTest.java From james-project with Apache License 2.0 | 5 votes |
@Test public void processShouldReturnKeywordsWithoutForwardedWhenForwardedUserFlagsMessages() throws Exception { Flags flags = FlagsBuilder.builder() .add(Flag.ANSWERED, Flag.DELETED) .add(FORWARDED) .build(); MessageManager inbox = mailboxManager.getMailbox(inboxPath, session); ComposedMessageId message1 = inbox.appendMessage( AppendCommand.builder() .withFlags(flags) .build(messageContent1), session).getId(); GetMessagesRequest request = GetMessagesRequest.builder() .ids(ImmutableList.of(message1.getMessageId())) .build(); List<JmapResponse> result = testee.processToStream(request, methodCallId, session).collect(Collectors.toList()); assertThat(result).hasSize(1) .extracting(JmapResponse::getResponse) .hasOnlyElementsOfType(GetMessagesResponse.class) .extracting(GetMessagesResponse.class::cast) .flatExtracting(GetMessagesResponse::list) .hasOnlyElementsOfType(MessageFullView.class) .extracting(MessageFullView.class::cast) .extracting(MessageFullView::getKeywords) .containsOnlyElementsOf( ImmutableList.of( ImmutableMap.of( "$Answered", true, FORWARDED, true))); }
Example #23
Source File: MessageFlags.java From james-project with Apache License 2.0 | 5 votes |
/** * 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 #24
Source File: ListeningMessageSearchIndexContract.java From james-project with Apache License 2.0 | 5 votes |
@Test default void retrieveIndexedFlagsShouldReturnEmptyFlagsWhenNoFlags() { Flags flags = new Flags(); SimpleMailboxMessage message = MESSAGE_BUILDER.mailboxId(mailbox().getMailboxId()) .flags(flags) .build(); testee().add(session(), mailbox(), message).block(); assertThat(testee().retrieveIndexedFlags(mailbox(), MESSAGE_UID).block()) .isEqualTo(flags); }
Example #25
Source File: StoreRightManagerTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void isReadWriteShouldReturnTrueWhenUserHasPerformExpungeRightOnMailbox() throws Exception { Flags flags = new Flags(); Mailbox mailbox = new Mailbox(MailboxPath.forUser(BOB, MailboxConstants.INBOX), UID_VALIDITY, MAILBOX_ID); mailbox.setACL(new MailboxACL(new MailboxACL.Entry(MailboxFixture.ALICE.asString(), Right.PerformExpunge))); assertThat(storeRightManager.isReadWrite(aliceSession, mailbox, flags)) .isTrue(); }
Example #26
Source File: GetMessageListMethodTest.java From james-project with Apache License 2.0 | 5 votes |
@Test @Category(CassandraAndElasticSearchCategory.class) public void getMessageListShouldExcludeMessagesWhenAttachmentFilterDoesntMatch() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE.asString(), "mailbox"); byte[] attachmentContent = ClassLoaderUtils.getSystemResourceAsByteArray("eml/attachment.pdf"); Multipart multipart = MultipartBuilder.create("mixed") .addBodyPart(BodyPartBuilder.create() .setBody(attachmentContent, "application/pdf") .setContentDisposition("attachment")) .addBodyPart(BodyPartBuilder.create() .setBody("The message has a PDF attachment.", "plain", StandardCharsets.UTF_8)) .build(); Message message = Message.Builder.of() .setBody(multipart) .build(); mailboxProbe.appendMessage(ALICE.asString(), ALICE_MAILBOX, new ByteArrayInputStream(DefaultMessageWriter.asBytes(message)), new Date(), false, new Flags()); await(); given() .header("Authorization", aliceAccessToken.asString()) .body("[[\"getMessageList\", {\"filter\":{\"attachments\":\"no apple inside\"}}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .body(ARGUMENTS + ".messageIds", empty()); }
Example #27
Source File: AbstractMessageIdManagerSideEffectTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void setFlagsShouldNotDispatchWhenFlagAlreadySet() throws Exception { givenUnlimitedQuota(); Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, newFlags, session); eventBus.register(eventCollector); messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox2.getMailboxId()), session); assertThat(eventCollector.getEvents()).isEmpty(); }
Example #28
Source File: AlfrescoImapFolder.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Moves the node <code>sourceNodeRef</code> extracted from the message id. * A part of a complex move operation. * * @param folderInfo FileInfo * @param message MimeMessage * @param flags Flags * @param sourceNodeRef NodeRef * @return UUID of the moved node * @throws FileExistsException * @throws FileNotFoundException */ @SuppressWarnings("deprecation") private long copyOrMoveNode(FileInfo folderInfo, MimeMessage message, Flags flags, NodeRef sourceNodeRef, boolean move) throws FileExistsException, FileNotFoundException { FileFolderService fileFolderService = serviceRegistry.getFileFolderService(); FileFilterMode.setClient(FileFilterMode.Client.imap); FileInfo messageFile = null; if (move) { fileFolderService.setHidden(sourceNodeRef, false); messageFile = fileFolderService.move(sourceNodeRef, folderInfo.getNodeRef(), null); } else { NodeRef newNodeRef = serviceRegistry.getCopyService().copyAndRename(sourceNodeRef, folderInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, null, false); fileFolderService.setHidden(newNodeRef, false); messageFile = fileFolderService.getFileInfo(newNodeRef); } final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID); imapService.persistMessageHeaders(messageFile.getNodeRef(), message); Flags newFlags = new Flags(flags); newFlags.add(Flag.RECENT); imapService.setFlags(messageFile, newFlags, true); imapService.setFlag(messageFile, Flag.DELETED, false); return newMessageUid; }
Example #29
Source File: MessageManager.java From james-project with Apache License 2.0 | 5 votes |
public AppendCommand build(InputStream msgIn) { return new AppendCommand( msgIn, internalDate.orElse(new Date()), isRecent.orElse(true), flags.orElse(new Flags())); }
Example #30
Source File: MessageMapperTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void updateFlagsWithRangeAllRangeShouldAffectAllMessages() throws MailboxException { saveMessages(); assertThat(messageMapper.updateFlags(benwaInboxMailbox, new FlagsUpdateCalculator(new Flags(Flags.Flag.SEEN), FlagsUpdateMode.REPLACE), MessageRange.all())) .toIterable() .hasSize(5); }