@Override public boolean isNoop() { return newPath.equals(path); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final SimpleMailboxMetaData other = (SimpleMailboxMetaData) obj; if (path == null) { if (other.path != null) { return false; } } else if (!path.equals(other.path)) { return false; } return true; }
private Optional<MailboxId> retrieveParentFromMetadata(MailboxPath parent, List<MailboxMetaData> list) { return list.stream() .filter(metadata -> metadata.getPath().equals(parent)) .map(MailboxMetaData::getId) .findAny(); } }
private Stream<MailboxPath> listAncestors(MailboxSession mailboxSession, MailboxPath mailboxPath) { return mailboxPath.getHierarchyLevels(mailboxSession.getPathDelimiter()) .stream() .filter(hierarchyMailboxPath -> !hierarchyMailboxPath.equals(mailboxPath)); }
@Override public List<Mailbox> findMailboxWithPathLike(MailboxPath path) { List<Mailbox> mailboxesV2 = toMailboxes(path, mailboxPathV2DAO.listUserMailboxes(path.getNamespace(), path.getUser())); List<Mailbox> mailboxesV1 = toMailboxes(path, mailboxPathDAO.listUserMailboxes(path.getNamespace(), path.getUser())); List<Mailbox> mailboxesV1NotInV2 = mailboxesV1.stream() .filter(mailboxV1 -> mailboxesV2.stream() .map(Mailbox::generateAssociatedPath) .noneMatch(mailboxV2path -> mailboxV2path.equals(mailboxV1.generateAssociatedPath()))) .collect(Guavate.toImmutableList()); return ImmutableList.<Mailbox>builder() .addAll(mailboxesV2) .addAll(mailboxesV1NotInV2) .build(); }
if (event.getMailboxPath().equals(getPath())) { final long eventSessionId = event.getSession().getSessionId(); if (event instanceof MessageEvent) { if (Flag.RECENT.equals(flags.next())) { MailboxPath path = sm.getPath(); if (path != null && path.equals(event.getMailboxPath())) { sm.addRecent(u.getUid());
private boolean isAddedToOutboxEvent(String messageId, Event event) { if (!(event instanceof EventFactory.AddedImpl)) { return false; } EventFactory.AddedImpl added = (EventFactory.AddedImpl) event; return added.getMailboxPath().equals(MailboxPath.forUser(USERNAME, DefaultMailboxes.OUTBOX)) && added.getUids().size() == 1 && added.getMetaData(added.getUids().get(0)).getMessageId().serialize().equals(messageId); }
@Override protected void doProcess(DeleteRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(request.getMailboxName()); try { final SelectedMailbox selected = session.getSelected(); if (selected != null && selected.getPath().equals(mailboxPath)) { session.deselect(); } final MailboxManager mailboxManager = getMailboxManager(); mailboxManager.deleteMailbox(mailboxPath, ImapSessionUtils.getMailboxSession(session)); unsolicitedResponses(session, responder, false); okComplete(command, tag, responder); } catch (MailboxNotFoundException e) { LOGGER.debug("Delete failed for mailbox {} as it doesn't exist", mailboxPath, e); no(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX); } catch (TooLongMailboxNameException e) { LOGGER.debug("The mailbox name length is over limit: {}", mailboxPath.getName(), e); taggedBad(command, tag, responder, HumanReadableText.FAILURE_MAILBOX_NAME); } catch (MailboxException e) { LOGGER.error("Delete failed for mailbox {}", mailboxPath, e); no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } }
try { final SelectedMailbox selected = session.getSelected(); if (selected != null && selected.getPath().equals(mailboxPath)) { session.deselect();
private void updateMailbox(Mailbox mailbox, MailboxUpdateRequest updateRequest, MailboxSession mailboxSession) throws MailboxException { MailboxPath originMailboxPath = mailboxManager.getMailbox(mailbox.getId(), mailboxSession).getMailboxPath(); MailboxPath destinationMailboxPath = computeNewMailboxPath(mailbox, originMailboxPath, updateRequest, mailboxSession); if (updateRequest.getSharedWith().isPresent()) { mailboxManager.setRights(originMailboxPath, updateRequest.getSharedWith() .get() .removeEntriesFor(Username.forMailboxPath(originMailboxPath)) .toMailboxAcl(), mailboxSession); } if (!originMailboxPath.equals(destinationMailboxPath)) { mailboxManager.renameMailbox(originMailboxPath, destinationMailboxPath, mailboxSession); subscriptionManager.unsubscribe(mailboxSession, originMailboxPath.getName()); subscriptionManager.subscribe(mailboxSession, destinationMailboxPath.getName()); } }
private void mailboxEvent(MailboxEvent mailboxEvent) { if (mailboxEvent.getMailboxPath().equals(getPath())) { final long eventSessionId = mailboxEvent.getSession().getSessionId(); if (mailboxEvent instanceof MessageEvent) { if (Flag.RECENT.equals(flags.next())) { MailboxPath path = sm.getPath(); if (path != null && path.equals(mailboxEvent.getMailboxPath())) { sm.addRecent(u.getUid());
final SelectedMailbox selectedMailbox = session.getSelected(); final MailboxManager mailboxManager = getMailboxManager(); final boolean isSelectedMailbox = selectedMailbox != null && selectedMailbox.getPath().equals(mailboxPath); final long uid = mailbox.appendMessage(message, datetime, mailboxSession, !isSelectedMailbox, flagsToBeSet); if (isSelectedMailbox) {
private void appendToMailbox(InputStream message, Date datetime, Flags flagsToBeSet, ImapSession session, String tag, ImapCommand command, MessageManager mailbox, Responder responder, MailboxPath mailboxPath) { try { final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); final SelectedMailbox selectedMailbox = session.getSelected(); final MailboxManager mailboxManager = getMailboxManager(); final boolean isSelectedMailbox = selectedMailbox != null && selectedMailbox.getPath().equals(mailboxPath); final ComposedMessageId messageId = mailbox.appendMessage(message, datetime, mailboxSession, !isSelectedMailbox, flagsToBeSet); if (isSelectedMailbox) { selectedMailbox.addRecent(messageId.getUid()); } // get folder UIDVALIDITY Long uidValidity = mailboxManager.getMailbox(mailboxPath, mailboxSession).getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).getUidValidity(); unsolicitedResponses(session, responder, false); // in case of MULTIAPPEND support we will push more then one UID here okComplete(command, tag, ResponseCode.appendUid(uidValidity, new UidRange[] { new UidRange(messageId.getUid()) }), responder); } catch (MailboxNotFoundException e) { // Indicates that the mailbox does not exist // So TRY CREATE tryCreate(session, tag, command, responder, e); } catch (MailboxException e) { LOGGER.error("Unable to append message to mailbox {}", mailboxPath, e); // Some other issue no(command, tag, responder, HumanReadableText.SAVE_FAILED); } }
private MessageManager.MetaData selectMailbox(MailboxPath mailboxPath, ImapSession session) throws MailboxException { final MailboxManager mailboxManager = getMailboxManager(); final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); final MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession); final SelectedMailbox sessionMailbox; final SelectedMailbox currentMailbox = session.getSelected(); if (currentMailbox == null || !currentMailbox.getPath().equals(mailboxPath)) { // QRESYNC EXTENSION // // Response with the CLOSE return-code when the currently selected mailbox is closed implicitly using the SELECT/EXAMINE command on another mailbox // // See rfc5162 3.7. CLOSED Response Code if (currentMailbox != null) { getStatusResponseFactory().untaggedOk(HumanReadableText.QRESYNC_CLOSED, ResponseCode.closed()); } session.selected(new SelectedMailboxImpl(getMailboxManager(), session, mailboxPath)); sessionMailbox = session.getSelected(); } else { // TODO: Check if we need to handle CONDSTORE there too sessionMailbox = currentMailbox; } final MessageManager.MetaData metaData = mailbox.getMetaData(!openReadOnly, mailboxSession, MessageManager.MetaData.FetchGroup.FIRST_UNSEEN); addRecent(metaData, sessionMailbox); return metaData; }
private MessageManager.MetaData selectMailbox(MailboxPath mailboxPath, ImapSession session) throws MailboxException { final MailboxManager mailboxManager = getMailboxManager(); final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); final MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession); final SelectedMailbox sessionMailbox; final SelectedMailbox currentMailbox = session.getSelected(); if (currentMailbox == null || !currentMailbox.getPath().equals(mailboxPath)) { // QRESYNC EXTENSION // // Response with the CLOSE return-code when the currently selected mailbox is closed implicitly using the SELECT/EXAMINE command on another mailbox // // See rfc5162 3.7. CLOSED Response Code if (currentMailbox != null) { getStatusResponseFactory().untaggedOk(HumanReadableText.QRESYNC_CLOSED, ResponseCode.closed()); } session.selected(new SelectedMailboxImpl(getMailboxManager(), session, mailboxPath)); sessionMailbox = session.getSelected(); } else { // TODO: Check if we need to handle CONDSTORE there too sessionMailbox = currentMailbox; } final MessageManager.MetaData metaData = mailbox.getMetaData(!openReadOnly, mailboxSession, MessageManager.MetaData.FetchGroup.FIRST_UNSEEN); addRecent(metaData, sessionMailbox); return metaData; }