@Override protected Closeable addContextToMDC(CreateRequest message) { return MDCBuilder.create() .addContext(MDCBuilder.ACTION, "CREATE") .addContext("mailbox", message.getMailboxName()) .build(); } }
/** * @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; }
@Test public void decodeShouldReturnCreateRequestWhenValidMailboxName() throws Exception { InputStream inputStream = new ByteArrayInputStream(".AnyMailbox.\n".getBytes(StandardCharsets.US_ASCII)); ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream); CreateRequest imapMessage = (CreateRequest)parser.decode(command, lineReader, TAG, mockImapSession); assertThat(imapMessage.getMailboxName()).isEqualTo(".AnyMailbox"); }
@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); }
@Override protected void doProcess(CreateRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(request.getMailboxName()); try { final MailboxManager mailboxManager = getMailboxManager(); mailboxManager.createMailbox(mailboxPath, ImapSessionUtils.getMailboxSession(session)); unsolicitedResponses(session, responder, false); okComplete(command, tag, responder); } catch (MailboxExistsException e) { LOGGER.debug("Create failed for mailbox {} as it already exists", mailboxPath, e); no(command, tag, responder, HumanReadableText.MAILBOX_EXISTS); } 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("Create failed for mailbox {}", mailboxPath, e); no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } }
/** * @see * org.apache.james.imap.processor.AbstractMailboxProcessor#doProcess(org.apache.james.imap.api.message.request.ImapRequest, * org.apache.james.imap.api.process.ImapSession, java.lang.String, * org.apache.james.imap.api.ImapCommand, * org.apache.james.imap.api.process.ImapProcessor.Responder) */ protected void doProcess(CreateRequest request, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxPath mailboxPath = buildFullPath(session, request.getMailboxName()); try { final MailboxManager mailboxManager = getMailboxManager(); mailboxManager.createMailbox(mailboxPath, ImapSessionUtils.getMailboxSession(session)); unsolicitedResponses(session, responder, false); okComplete(command, tag, responder); } catch (MailboxExistsException e) { if (session.getLog().isDebugEnabled()) { session.getLog().debug("Create failed for mailbox " + mailboxPath + " as it already exists", e); } no(command, tag, responder, HumanReadableText.MAILBOX_EXISTS); } catch (MailboxException e) { if (session.getLog().isInfoEnabled()) { session.getLog().info("Create failed for mailbox " + mailboxPath, e); } no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } } }