public static String getUserName(ImapSession imapSession) { Preconditions.checkNotNull(imapSession); return Optional.ofNullable(getMailboxSession(imapSession)) .map(mailboxSession -> mailboxSession.getUser().getUserName()) .orElse(null); } }
@Override public synchronized void deselect() { MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); try { mailboxManager.removeListener(path, this, mailboxSession); } catch (MailboxException e) { LOGGER.error("Unable to remove listener {} from mailbox while closing it", this, e); } uidMsnConverter.clear(); flagUpdateUids.clear(); expungedUids.clear(); recentUids.clear(); }
private MailboxPath buildAbsolutePath(String absolutePath) { char pathDelimiter = ImapSessionUtils.getMailboxSession(session).getPathDelimiter(); List<String> mailboxPathParts = Splitter.on(pathDelimiter).splitToList(absolutePath); String namespace = mailboxPathParts.get(NAMESPACE); String mailboxName = Joiner.on(pathDelimiter).join(Iterables.skip(mailboxPathParts, 1)); return buildMailboxPath(namespace, retrieveUserName(namespace), mailboxName); }
public static String getUserName(final ImapSession imapSession) { final String result; final MailboxSession mailboxSession = getMailboxSession(imapSession); if (imapSession == null) { result = null; } else { result = mailboxSession.getUser().getUserName(); } return result; } }
private boolean hasRight(QuotaRoot quotaRoot, ImapSession session) throws MailboxException { // If any of the mailboxes owned by quotaRoot user can be read by the current user, then we should respond to him. final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); List<MailboxPath> mailboxList = quotaRootResolver.retrieveAssociatedMailboxes(quotaRoot, mailboxSession); for (MailboxPath mailboxPath : mailboxList) { if (getMailboxManager().hasRight(mailboxPath, MailboxACL.Right.Read, mailboxSession)) { return true; } } return false; }
public SelectedMailboxImpl(final MailboxManager mailboxManager, final ImapSession session, final MailboxPath path) throws MailboxException { this.session = session; this.sessionId = ImapSessionUtils.getMailboxSession(session).getSessionId(); this.mailboxManager = mailboxManager; // Ignore events from our session setSilentFlagChanges(true); this.path = path; init(); }
private MessageManager getMailbox(final ImapSession session, final SelectedMailbox selected) throws MailboxException { final MailboxManager mailboxManager = getMailboxManager(); final MessageManager mailbox = mailboxManager.getMailbox(selected.getPath(), ImapSessionUtils.getMailboxSession(session)); return mailbox; }
private MessageManager getMailbox(ImapSession session, SelectedMailbox selected) throws MailboxException { final MailboxManager mailboxManager = getMailboxManager(); return mailboxManager.getMailbox(selected.getPath(), ImapSessionUtils.getMailboxSession(session)); }
private List<MailboxAnnotation> getMailboxAnnotations(ImapSession session, Set<MailboxAnnotationKey> keys, GetAnnotationRequest.Depth depth, MailboxPath mailboxPath) throws MailboxException { MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); switch (depth) { case ZERO: return getMailboxAnnotationsWithDepthZero(keys, mailboxPath, mailboxSession); case ONE: return getMailboxManager().getAnnotationsByKeysWithOneDepth(mailboxPath, mailboxSession, keys); case INFINITY: return getMailboxManager().getAnnotationsByKeysWithAllDepth(mailboxPath, mailboxSession, keys); default: throw new NotImplementedException("Not implemented"); } }
protected MessageManager getSelectedMailbox(final ImapSession session) throws MailboxException { MessageManager result; final SelectedMailbox selectedMailbox = session.getSelected(); if (selectedMailbox == null) { result = null; } else { final MailboxManager mailboxManager = getMailboxManager(); result = mailboxManager.getMailbox(selectedMailbox.getPath(), ImapSessionUtils.getMailboxSession(session)); } return result; }
protected MessageManager getSelectedMailbox(ImapSession session) throws MailboxException { MessageManager result; final SelectedMailbox selectedMailbox = session.getSelected(); if (selectedMailbox == null) { result = null; } else { final MailboxManager mailboxManager = getMailboxManager(); result = mailboxManager.getMailbox(selectedMailbox.getPath(), ImapSessionUtils.getMailboxSession(session)); } return result; }
final void doProcess(final M message, final ImapCommand command, final String tag, Responder responder, ImapSession session) { if (!command.validForState(session.getState())) { ImapResponseMessage response = factory.taggedNo(tag, command, HumanReadableText.INVALID_COMMAND); responder.respond(response); } else { getMailboxManager().startProcessingRequest(ImapSessionUtils.getMailboxSession(session)); doProcess(message, session, tag, command, responder); getMailboxManager().endProcessingRequest(ImapSessionUtils.getMailboxSession(session)); } }
@Override protected final void doProcess(M message, ImapSession session, String tag, ImapCommand command, Responder responder) { // take care of calling the start/end processing MailboxSession mSession = ImapSessionUtils.getMailboxSession(session); getSubscriptionManager().startProcessingRequest(mSession); doProcessRequest(message, session, tag, command, responder); getSubscriptionManager().endProcessingRequest(mSession); }
@Override protected final void doProcess(M message, ImapSession session, String tag, ImapCommand command, Responder responder) { // take care of calling the start/end processing MailboxSession mSession = ImapSessionUtils.getMailboxSession(session); getSubscriptionManager().startProcessingRequest(mSession); doProcessRequest(message, session, tag, command, responder); getSubscriptionManager().endProcessingRequest(mSession); }
@Override protected void doProcessRequest(UnsubscribeRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final String mailboxName = request.getMailboxName(); final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); try { getSubscriptionManager().unsubscribe(mailboxSession, mailboxName); unsolicitedResponses(session, responder, false); okComplete(command, tag, responder); } catch (SubscriptionException e) { LOGGER.info("Unsubscribe failed for mailbox {}", mailboxName, e); unsolicitedResponses(session, responder, false); no(command, tag, responder, HumanReadableText.GENERIC_SUBSCRIPTION_FAILURE); } }
final void doProcess(M message, ImapCommand command, String tag, Responder responder, ImapSession session) { try { if (!command.validForState(session.getState())) { ImapResponseMessage response = factory.taggedNo(tag, command, HumanReadableText.INVALID_COMMAND); responder.respond(response); } else { getMailboxManager().startProcessingRequest(ImapSessionUtils.getMailboxSession(session)); doProcess(message, session, tag, command, responder); getMailboxManager().endProcessingRequest(ImapSessionUtils.getMailboxSession(session)); } } catch (DeniedAccessOnSharedMailboxException e) { no(command, tag, responder, HumanReadableText.DENIED_SHARED_MAILBOX); } }
@Override protected void doProcess(LogoutRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); try { getMailboxManager().logout(mailboxSession, false); session.logout(); bye(responder); okComplete(command, tag, responder); } catch (MailboxException e) { LOGGER.error("Logout failed for user {}", mailboxSession.getUser().getUserName(), e); no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } }
private void listSubscriptions(ImapSession session, Responder responder, String referenceName, String mailboxName) throws SubscriptionException, MailboxException { MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); Collection<String> mailboxes = getSubscriptionManager().subscriptions(mailboxSession); String decodedMailName = CharsetUtil.decodeModifiedUTF7(referenceName); MailboxNameExpression expression = new PrefixedRegex( decodedMailName, CharsetUtil.decodeModifiedUTF7(mailboxName), mailboxSession.getPathDelimiter()); Collection<String> mailboxResponses = new ArrayList<>(); for (String mailbox : mailboxes) { respond(responder, expression, mailbox, true, mailboxes, mailboxResponses, mailboxSession.getPathDelimiter()); } }
@Override protected void doProcess(NamespaceRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); final List<NamespaceResponse.Namespace> personalNamespaces = buildPersonalNamespaces(mailboxSession, session); final List<NamespaceResponse.Namespace> otherUsersNamespaces = buildOtherUsersSpaces(mailboxSession, session); final List<NamespaceResponse.Namespace> sharedNamespaces = buildSharedNamespaces(mailboxSession, session); final NamespaceResponse response = new NamespaceResponse(personalNamespaces, otherUsersNamespaces, sharedNamespaces); responder.respond(response); unsolicitedResponses(session, responder, false); okComplete(command, tag, responder); }
@Override protected void doProcess(NamespaceRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); final List<NamespaceResponse.Namespace> personalNamespaces = buildPersonalNamespaces(mailboxSession, session); final List<NamespaceResponse.Namespace> otherUsersNamespaces = buildOtherUsersSpaces(mailboxSession, session); final List<NamespaceResponse.Namespace> sharedNamespaces = buildSharedNamespaces(mailboxSession, session); final NamespaceResponse response = new NamespaceResponse(personalNamespaces, otherUsersNamespaces, sharedNamespaces); responder.respond(response); unsolicitedResponses(session, responder, false); okComplete(command, tag, responder); }