@Override public MailboxPath getMailboxPath() throws MailboxException { return new StoreMailboxPath(getMailboxEntity()); }
/** * Return the uid of the first unseen message or null of none is found */ protected MessageUid findFirstUnseenMessageUid(MailboxSession session) throws MailboxException { MessageMapper messageMapper = mapperFactory.getMessageMapper(session); return messageMapper.findFirstUnseenMessageUid(getMailboxEntity()); }
@Override public long getMessageCount(MailboxSession mailboxSession) throws MailboxException { return mapperFactory.getMessageMapper(mailboxSession).countMessagesInMailbox(getMailboxEntity()); }
protected long countUnseenMessagesInMailbox(MailboxSession session) throws MailboxException { MessageMapper messageMapper = mapperFactory.getMessageMapper(session); return messageMapper.countUnseenMessagesInMailbox(getMailboxEntity()); }
private MoveResult move(Iterator<MailboxMessage> originalRows, MailboxSession session) throws MailboxException { final List<MessageMetaData> movedRows = new ArrayList<>(); final List<MessageMetaData> originalRowsCopy = new ArrayList<>(); final MessageMapper messageMapper = mapperFactory.getMessageMapper(session); while (originalRows.hasNext()) { final MailboxMessage originalMessage = originalRows.next(); originalRowsCopy.add(new SimpleMessageMetaData(originalMessage)); MessageMetaData data = messageMapper.execute( () -> messageMapper.move(getMailboxEntity(), originalMessage)); movedRows.add(data); } return new MoveResult(movedRows.iterator(), originalRowsCopy.iterator()); }
private Iterator<MessageMetaData> copy(Iterator<MailboxMessage> originalRows, MailboxSession session) throws MailboxException { final List<MessageMetaData> copiedRows = new ArrayList<>(); final MessageMapper messageMapper = mapperFactory.getMessageMapper(session); while (originalRows.hasNext()) { final MailboxMessage originalMessage = originalRows.next(); new QuotaChecker(quotaManager, quotaRootResolver, mailbox) .tryAddition(1, originalMessage.getFullContentOctets()); MessageMetaData data = messageMapper.execute( () -> messageMapper.copy(getMailboxEntity(), originalMessage)); dispatcher.added(session, this.getMailboxEntity(), immutableMailboxMessageFactory.from(getMailboxEntity().getMailboxId(), originalMessage)); copiedRows.add(data); } return copiedRows.iterator(); }
protected Map<MessageUid, MessageMetaData> deleteMarkedInMailbox(final MessageRange range, MailboxSession session) throws MailboxException { final MessageMapper messageMapper = mapperFactory.getMessageMapper(session); return messageMapper.execute( () -> messageMapper.expungeMarkedForDeletionInMailbox(getMailboxEntity(), range)); }
/** * Create a new {@link MailboxMessage} for the given data */ protected MailboxMessage createMessage(Date internalDate, int size, int bodyStartOctet, SharedInputStream content, Flags flags, PropertyBuilder propertyBuilder, List<MessageAttachment> attachments) throws MailboxException { return new SimpleMailboxMessage(messageIdFactory.generate(), internalDate, size, bodyStartOctet, content, flags, propertyBuilder, getMailboxEntity().getMailboxId(), attachments); }
private SortedMap<MessageUid, MessageMetaData> copy(MessageRange set, StoreMessageManager to, MailboxSession session) throws MailboxException { IteratorWrapper<MailboxMessage> originalRows = new IteratorWrapper<>(retrieveOriginalRows(set, session)); SortedMap<MessageUid, MessageMetaData> copiedUids = collectMetadata(to.copy(originalRows, session)); ImmutableMap.Builder<MessageUid, MailboxMessage> messagesMap = ImmutableMap.builder(); for (MailboxMessage message : originalRows.getEntriesSeen()) { messagesMap.put(message.getUid(), immutableMailboxMessageFactory.from(to.getMailboxEntity().getMailboxId(), message)); } dispatcher.added(session, copiedUids, to.getMailboxEntity(), messagesMap.build()); dispatcher.moved(session, MessageMoves.builder() .previousMailboxIds(getMailboxEntity().getMailboxId()) .targetMailboxIds(to.getMailboxEntity().getMailboxId(), getMailboxEntity().getMailboxId()) .build(), messagesMap.build()); return copiedUids; }
@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; }
@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(); }
private SortedMap<MessageUid, MessageMetaData> move(MessageRange set, StoreMessageManager to, MailboxSession session) throws MailboxException { IteratorWrapper<MailboxMessage> originalRows = new IteratorWrapper<>(retrieveOriginalRows(set, session)); MoveResult moveResult = to.move(originalRows, session); SortedMap<MessageUid, MessageMetaData> moveUids = collectMetadata(moveResult.getMovedMessages()); ImmutableMap.Builder<MessageUid, MailboxMessage> messagesMap = ImmutableMap.builder(); for (MailboxMessage message : originalRows.getEntriesSeen()) { messagesMap.put(message.getUid(), immutableMailboxMessageFactory.from(to.getMailboxEntity().getMailboxId(), message)); } dispatcher.added(session, moveUids, to.getMailboxEntity(), messagesMap.build()); dispatcher.expunged(session, collectMetadata(moveResult.getOriginalMessages()), getMailboxEntity()); dispatcher.moved(session, MessageMoves.builder() .previousMailboxIds(getMailboxEntity().getMailboxId()) .targetMailboxIds(to.getMailboxEntity().getMailboxId()) .build(), messagesMap.build()); return moveUids; }
/** * 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); }
@Override public Iterator<MessageUid> search(SearchQuery query, MailboxSession mailboxSession) throws MailboxException { if (query.equals(new SearchQuery(SearchQuery.all()))) { return listAllMessageUids(mailboxSession); } return index.search(mailboxSession, getMailboxEntity(), query); }
protected MessageMetaData appendMessageToStore(final MailboxMessage message, final List<MessageAttachment> messageAttachments, MailboxSession session) throws MailboxException { final MessageMapper messageMapper = mapperFactory.getMessageMapper(session); return mapperFactory.getMessageMapper(session).execute(() -> { storeAttachment(message, messageAttachments, session); return messageMapper.add(getMailboxEntity(), message); }); }
/** * 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); }
/** * 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; }); }
boolean hasReadRight = storeRightManager.hasRight(mailbox, MailboxACL.Right.Read, mailboxSession); if (!hasReadRight) { return MailboxMetaData.sensibleInformationFree(resolvedAcl, getMailboxEntity().getUidValidity(), isWriteable(mailboxSession), isModSeqPermanent(mailboxSession)); long uidValidity = getMailboxEntity().getUidValidity(); MessageUid uidNext = mapperFactory.getMessageMapper(mailboxSession).getLastUid(mailbox) .map(MessageUid::next)
MessageMetaData data = appendMessageToStore(message, attachments, mailboxSession); Mailbox mailbox = getMailboxEntity(); MailboxMessage copy = copyMessage(message); dispatcher.added(mailboxSession, mailbox, copy);