@Override protected Closeable addContextToMDC(CreateRequest message) { return MDCBuilder.create() .addContext(MDCBuilder.ACTION, "CREATE") .addContext("mailbox", message.getMailboxName()) .build(); } }
@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 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); } } }