@Test public void testBadCharset() throws Exception { ImapRequestLineReader reader = new ImapRequestStreamLineReader( new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")), new ByteArrayOutputStream()); parser.decode(command, reader, TAG, false, session); verify(mockStatusResponseFactory, times(1)).taggedNo( eq(TAG), same(command), eq(HumanReadableText.BAD_CHARSET), eq(StatusResponse.ResponseCode.badCharset(CharsetUtil.getAvailableCharsetNames()))); verifyNoMoreInteractions(mockStatusResponseFactory); }
@Test public void testResponseCodeExtension() { assertThat(StatusResponse.ResponseCode.createExtension("XEXTENSION") .getCode()).describedAs("Preserve names beginning with X").isEqualTo("XEXTENSION"); assertThat(StatusResponse.ResponseCode.createExtension("EXTENSION") .getCode()).describedAs("Correct other names").isEqualTo("XEXTENSION"); }
@Test public void responseCodeShouldBuildTheLongestEntryForMetadata() { assertThat(StatusResponse.ResponseCode.longestMetadataEntry(1024).getCode()).isEqualTo("METADATA LONGENTRIES"); assertThat(StatusResponse.ResponseCode.longestMetadataEntry(1024).getNumber()).isEqualTo(1024); } }
final StatusResponse response = getStatusResponseFactory().taggedOk(tag, command, HumanReadableText.FAILED, ResponseCode.condStore(idSet)); responder.respond(response); return; final StatusResponse response = getStatusResponseFactory().taggedOk(tag, command, HumanReadableText.FAILED, ResponseCode.condStore(idRanges)); responder.respond(response); } else { final StatusResponse response = getStatusResponseFactory().taggedOk(tag, command, HumanReadableText.FAILED, ResponseCode.condStore(failedRanges)); responder.respond(response);
final StatusResponse response = getStatusResponseFactory().taggedOk(tag, command, HumanReadableText.FAILED, ResponseCode.condStore(idSet)); responder.respond(response); return; final StatusResponse response = getStatusResponseFactory().taggedOk(tag, command, HumanReadableText.FAILED, ResponseCode.condStore(idRanges)); responder.respond(response);
useParens = false; } else { parameters = responseCode.getParameters(); number = responseCode.getNumber(); useParens = responseCode.useParens();
useParens = false; } else { parameters = responseCode.getParameters(); number = responseCode.getNumber(); useParens = responseCode.useParens();
okComplete(command, tag, ResponseCode.appendUid(uidValidity, new IdRange[] { new IdRange(uid) }), responder); } catch (MailboxNotFoundException e) {
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; }
/** * Issues a TRY CREATE response. * * @param session * not null * @param tag * not null * @param command * not null * @param responder * not null * @param e * not null */ private void tryCreate(ImapSession session, String tag, ImapCommand command, Responder responder, MailboxNotFoundException e) { final Logger logger = session.getLog(); if (logger.isDebugEnabled()) { logger.debug("Cannot open mailbox: ", e); } no(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, StatusResponse.ResponseCode.tryCreate()); }
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; }
@Override protected void doProcess(SetAnnotationRequest message, ImapSession session, String tag, ImapCommand command, Responder responder) { final MailboxManager mailboxManager = getMailboxManager(); final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session); final String mailboxName = message.getMailboxName(); try { MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(mailboxName); mailboxManager.updateAnnotations(mailboxPath, mailboxSession, message.getMailboxAnnotations()); okComplete(command, tag, responder); } catch (MailboxNotFoundException e) { LOGGER.info("{} failed for mailbox {}", command.getName(), mailboxName, e); no(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, StatusResponse.ResponseCode.tryCreate()); } catch (AnnotationException e) { LOGGER.info("{} failed for mailbox {}", command.getName(), mailboxName, e); no(command, tag, responder, new HumanReadableText(HumanReadableText.MAILBOX_ANNOTATION_KEY, e.getMessage())); } catch (MailboxException e) { LOGGER.error("{} failed for mailbox {}", command.getName(), mailboxName, e); no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING); } }
/** * Issues a TRY CREATE response. * * @param session * not null * @param tag * not null * @param command * not null * @param responder * not null * @param e * not null */ private void tryCreate(ImapSession session, String tag, ImapCommand command, Responder responder, MailboxNotFoundException e) { LOGGER.debug("Cannot open mailbox: ", e); no(command, tag, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, StatusResponse.ResponseCode.tryCreate()); }
/** * Creates an extension response code. Names that do not begin with 'X' * will have 'X' prepended * * @param name * extension code, not null * @return <code>ResponseCode</code>, not null */ public static ResponseCode createExtension(String name) { StringBuffer buffer = new StringBuffer(name.length() + 2); if (!name.startsWith("X")) { buffer.append('X'); } buffer.append(name); final ResponseCode result = new ResponseCode(buffer.toString()); return result; }
/** * Creates an extension response code. Names that do not begin with 'X' * will have 'X' prepended * * @param name * extension code, not null * @return <code>ResponseCode</code>, not null */ public static ResponseCode createExtension(String name) { StringBuffer buffer = new StringBuffer(name.length() + 2); if (!name.startsWith("X")) { buffer.append('X'); } buffer.append(name); return new ResponseCode(buffer.toString()); }
@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); } }
/** * Create a RFC4551 <code>NOMODSEQ</code> response code * * @return <code>ResponseCode</code> */ public static ResponseCode noModSeq() { return new ResponseCode("NOMODSEQ"); }