@Override public Iterator<MessageUid> expunge(MessageRange set, MailboxSession mailboxSession) throws MailboxException { if (!isWriteable(mailboxSession)) { throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter()); } Map<MessageUid, MessageMetaData> uids = deleteMarkedInMailbox(set, mailboxSession); dispatcher.expunged(mailboxSession, uids, getMailboxEntity()); return uids.keySet().iterator(); }
@Override public Map<MessageUid, Flags> setFlags(final Flags flags, final FlagsUpdateMode flagsUpdateMode, final MessageRange set, MailboxSession mailboxSession) throws MailboxException { if (!isWriteable(mailboxSession)) { throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter()); } final SortedMap<MessageUid, Flags> newFlagsByUid = new TreeMap<>(); trimFlags(flags, mailboxSession); final MessageMapper messageMapper = mapperFactory.getMessageMapper(mailboxSession); Iterator<UpdatedFlags> it = messageMapper.execute(() -> messageMapper.updateFlags(getMailboxEntity(), new FlagsUpdateCalculator(flags, flagsUpdateMode), set)); final SortedMap<MessageUid, UpdatedFlags> uFlags = new TreeMap<>(); while (it.hasNext()) { UpdatedFlags flag = it.next(); newFlagsByUid.put(flag.getUid(), flag.getNewFlags()); uFlags.put(flag.getUid(), flag); } dispatcher.flagsUpdated(mailboxSession, new ArrayList<>(uFlags.keySet()), getMailboxEntity(), new ArrayList<>(uFlags.values())); return newFlagsByUid; }
/** * Move the {@link MessageRange} to the {@link StoreMessageManager} * * @param set * @param toMailbox * @param session * @throws MailboxException */ public List<MessageRange> moveTo(final MessageRange set, final StoreMessageManager toMailbox, final MailboxSession session) throws MailboxException { if (!isWriteable(session)) { throw new ReadOnlyException(getMailboxPath(), session.getPathDelimiter()); } if (!toMailbox.isWriteable(session)) { throw new ReadOnlyException(new StoreMailboxPath(toMailbox.getMailboxEntity()), session.getPathDelimiter()); } //TODO lock the from mailbox too, in a non-deadlocking manner - how? return locker.executeWithLock(session, new StoreMailboxPath(toMailbox.getMailboxEntity()), () -> { SortedMap<MessageUid, MessageMetaData> movedUids = move(set, toMailbox, session); return MessageRange.toRanges(new ArrayList<>(movedUids.keySet())); }, true); }
/** * Copy the {@link MessageRange} to the {@link StoreMessageManager} * * @param set * @param toMailbox * @param session * @throws MailboxException */ public List<MessageRange> copyTo(final MessageRange set, final StoreMessageManager toMailbox, final MailboxSession session) throws MailboxException { if (!toMailbox.isWriteable(session)) { throw new ReadOnlyException(new StoreMailboxPath(toMailbox.getMailboxEntity()), session.getPathDelimiter()); } return locker.executeWithLock(session, new StoreMailboxPath(toMailbox.getMailboxEntity()), () -> { SortedMap<MessageUid, MessageMetaData> copiedUids = copy(set, toMailbox, session); return MessageRange.toRanges(new ArrayList<>(copiedUids.keySet())); }, true); }
/** * Return a List which holds all uids of recent messages and optional reset * the recent flag on the messages for the uids */ protected List<MessageUid> recent(final boolean reset, MailboxSession mailboxSession) throws MailboxException { if (reset) { if (!isWriteable(mailboxSession)) { throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter()); } } final MessageMapper messageMapper = mapperFactory.getMessageMapper(mailboxSession); return messageMapper.execute(() -> { final List<MessageUid> members = messageMapper.findRecentMessageUidsInMailbox(getMailboxEntity()); // Convert to MessageRanges so we may be able to optimize the // flag update List<MessageRange> ranges = MessageRange.toRanges(members); for (MessageRange range : ranges) { if (reset) { // only call save if we need to messageMapper.updateFlags(getMailboxEntity(), new FlagsUpdateCalculator(new Flags(Flag.RECENT), FlagsUpdateMode.REMOVE), range); } } return members; }); }
throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter());