public static String getUserName(ImapSession imapSession) { Preconditions.checkNotNull(imapSession); return Optional.ofNullable(getMailboxSession(imapSession)) .map(mailboxSession -> mailboxSession.getUser().getUserName()) .orElse(null); } }
public MailboxPath buildFullPath(final ImapSession session, String mailboxName) { String namespace = null; String name = null; final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); user = ImapSessionUtils.getUserName(session);
private String retrieveUserName(String namespace) { if (namespace.equals(MailboxConstants.USER_NAMESPACE)) { return ImapSessionUtils.getUserName(session); } return null; }
private MailboxPath buildRelativePath(String mailboxName) { return buildMailboxPath(MailboxConstants.USER_NAMESPACE, ImapSessionUtils.getUserName(session), mailboxName); }
@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(); }
@Test public void getUserNameShouldThrowOnNullImapSession() { assertThatThrownBy(() -> ImapSessionUtils.getUserName(null)) .isInstanceOf(NullPointerException.class); }
@Override public synchronized void deselect() { MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); try { mailboxManager.removeListener(path, this, mailboxSession); } catch (MailboxException e) { if (session.getLog().isInfoEnabled()) { session.getLog().info("Unable to remove listener " + this + " from mailbox while closing it", e); } } uidToMsn.clear(); msnToUid.clear(); flagUpdateUids.clear(); expungedUids.clear(); recentUids.clear(); }
@Test public void getUserNameShouldReturnUserWhenMailboxSession() { fakeImapSession.setAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY, MAILBOX_SESSION); assertThat(ImapSessionUtils.getUserName(fakeImapSession)) .isEqualTo(USERNAME); }
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); }
@Override protected void doProcess(GetAnnotationRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) { try { proceed(message, session, tag, command, responder); } catch (MailboxNotFoundException e) { LOGGER.info("The command: {} is failed because not found mailbox {}", command.getName(), message.getMailboxName()); no(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, ResponseCode.tryCreate()); } catch (MailboxException e) { LOGGER.error("GetAnnotation on mailbox {} failed for user {}", message.getMailboxName(), ImapSessionUtils.getUserName(session), e); no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } }
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; } }
@Test public void getUserNameShouldReturnNullWhenNoMailboxSession() { assertThat(ImapSessionUtils.getUserName(fakeImapSession)) .isNull(); }
/** * Forces a logout of any mailbox session. * * @param imapSession * not null * @throws MailboxException * when forced logout fails */ private void forceLogout(ImapSession imapSession) throws MailboxException { final MailboxSession session = ImapSessionUtils.getMailboxSession(imapSession); if (session == null) { LOGGER.trace("No mailbox session so no force logout needed"); } else { session.close(); mailboxManager.logout(session, true); } }
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; }
/** * @see * org.apache.james.imap.decode.base.AbstractImapCommandParser#decode(org.apache.james.imap.api.ImapCommand, * org.apache.james.imap.decode.ImapRequestLineReader, java.lang.String, * org.apache.james.imap.api.process.ImapSession) */ protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, ImapSession session) throws DecodingException { String mailboxName = request.mailbox(); MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); // Check if we have an mailboxsession. This is a workaround for // IMAP-240: // https://issues.apache.org/jira/browse/IMAP-240 if (mailboxSession != null) { // RFC3501@6.3.3p2 // When mailbox name is suffixed with hierarchy separator // name created must remove tailing delimiter if (mailboxName.endsWith(Character.toString(mailboxSession.getPathDelimiter()))) { // NOPMD // keep // comment mailboxName = mailboxName.substring(0, mailboxName.length() - 1); } } request.eol(); final ImapMessage result = new CreateRequest(command, mailboxName, tag); return result; }
private MessageManager getMailbox(ImapSession session, SelectedMailbox selected) throws MailboxException { final MailboxManager mailboxManager = getMailboxManager(); return mailboxManager.getMailbox(selected.getPath(), ImapSessionUtils.getMailboxSession(session)); }
/** * Forces a logout of any mailbox session. * * @param imapSession * not null * @throws MailboxException * when forced logout fails */ private void forceLogout(ImapSession imapSession) throws MailboxException { final MailboxSession session = ImapSessionUtils.getMailboxSession(imapSession); if (session == null) { if (imapSession.getLog().isTraceEnabled()) { imapSession.getLog().trace("No mailbox session so no force logout needed"); } } else { session.close(); mailboxManager.logout(session, true); } }
@Override protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, String tag, ImapSession session) throws DecodingException { String mailboxName = request.mailbox(); MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); // Check if we have an mailboxsession. This is a workaround for // IMAP-240: // https://issues.apache.org/jira/browse/IMAP-240 if (mailboxSession != null) { // RFC3501@6.3.3p2 // When mailbox name is suffixed with hierarchy separator // name created must remove tailing delimiter if (mailboxName.endsWith(Character.toString(mailboxSession.getPathDelimiter()))) { mailboxName = mailboxName.substring(0, mailboxName.length() - 1); } } request.eol(); assertMailboxNameJustContainDelimiter(mailboxName, mailboxSession.getPathDelimiter()); return new CreateRequest(command, mailboxName, tag); }