/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException { parser.endLine(request); response.byeResponse(BYE_MESSAGE); response.commandComplete(this); session.closeConnection(); } }
/** * Writes a standard NO response on command failure, together with a * descriptive message. * Response is writen as: * <pre> a01 NO COMMAND_NAME failed. <reason></pre> * * @param command The ImapCommand which failed. * @param reason A message describing why the command failed. */ public void commandFailed(ImapCommand command, String reason) { commandFailed(command, null, reason); }
/** * Writes a standard tagged OK response on completion of a command, * with a response code (eg READ-WRITE) * Response is writen as: * <pre> a01 OK [responseCode] COMMAND_NAME completed.</pre> * * @param command The ImapCommand which was completed. * @param responseCode A string response code to send to the client. */ public void commandComplete(ImapCommand command, String responseCode) { tag(); message(OK); responseCode(responseCode); commandName(command); message("completed."); end(); }
public void commandResponse(ImapCommand command, String message) { untagged(); commandName(command); message(message); end(); }
selectMailbox(mailboxName, session, isExamine); } catch (FolderException ex) { response.commandFailed(this, "No such mailbox"); return; response.flagsResponse(mailbox.getPermanentFlags()); response.existsResponse(mailbox.getMessageCount()); final boolean resetRecent = !isExamine; response.recentResponse(mailbox.getRecentCount(resetRecent)); response.okResponse("UIDVALIDITY " + mailbox.getUidValidity(), null); response.okResponse("UIDNEXT " + mailbox.getUidNext(), null); response.okResponse("UNSEEN " + firstUnseen, "Message " + firstUnseen + " is the first unseen"); } else { response.okResponse(null, "No messages unseen"); response.permanentFlagsResponse(mailbox.getPermanentFlags()); response.commandComplete(this, "READ-ONLY"); } else { response.commandComplete(this, "READ-WRITE");
/** * Writes an untagged OK response, with the supplied response code, * and an optional message. * * @param responseCode The response code, included in []. * @param message The message to follow the [] */ public void okResponse(String responseCode, String message) { untagged(); message(OK); responseCode(responseCode); message(message); end(); }
tag = parser.tag(request); } catch (ProtocolException e) { response.badResponse(REQUEST_SYNTAX); return; response.setTag(tag); response.commandError(REQUEST_SYNTAX); return; if (command == null) { log.error("Command '{}' not valid", commandName); response.commandError("Invalid command."); return; response.commandFailed(command, "Command not valid in this state"); return;
response.existsResponse(selected.getMessageCount()); response.recentResponse(selected.getRecentCount(true)); selected.setSizeChanged(false); out.append(update.getUid()); response.fetchResponse(msn, out.toString()); int[] expunged = selected.getExpunged(); for (int msn : expunged) { response.expungeResponse(msn);
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) throws ProtocolException, FolderException, AuthorizationException { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } String root = parser.mailbox(request); // QUOTAROOT mailbox Quota[] quota = session.getHost().getStore().getQuota( root, session.getUser().getQualifiedMailboxName()); StringBuilder buf = new StringBuilder("QUOTAROOT "); buf.append(root); for (Quota q : quota) { buf.append(' '); appendQuotaRootName(q, buf); } response.untaggedResponse("QUOTAROOT "+root); for (Quota q : quota) { buf = new StringBuilder(); appendQuota(q, buf); response.untaggedResponse(buf.toString()); } response.commandComplete(this); } }
} catch(IllegalArgumentException ex) { response.commandError("Search command not supported"); return; } catch (CharacterCodingException e) { response.commandError("Search command does not support charset "+e.getMessage()); return; response.commandComplete(this); return; response.commandResponse(this, idList.toString()); response.commandComplete(this);
/** * Writes a standard tagged OK response on completion of a command. * Response is writen as: * <pre> a01 OK COMMAND_NAME completed.</pre> * * @param command The ImapCommand which was completed. */ public void commandComplete(ImapCommand command) { commandComplete(command, null); }
/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException { String userid = parser.astring(request); String password = parser.astring(request); parser.endLine(request); if (session.getUserManager().test(userid, password)) { GreenMailUser user = session.getUserManager().getUser(userid); session.setAuthenticated(user); response.commandComplete(this); } else { response.commandFailed(this, "Invalid login/password for user id "+userid); } } }
folder = getMailbox(mailboxName, session, true); } catch (FolderException ex) { response.commandFailed(this, "No such mailbox"); return; response.commandResponse(this, buffer.toString()); response.commandComplete(this);
@Override public void run() { // Closed automatically when socket is closed via #close() try (InputStream ins = new BufferedInputStream(socket.getInputStream(), 512); OutputStream outs = new BufferedOutputStream(socket.getOutputStream(), 1024) ) { response = new ImapResponse(outs); // Write welcome message String responseBuffer = VERSION + " Server GreenMail v" + BuildInfo.INSTANCE.getProjectVersion() + " ready"; response.okResponse(null, responseBuffer); session = new ImapSessionImpl(imapHost, userManager, this, socket.getInetAddress().getHostAddress()); while (requestHandler.handleRequest(ins, outs, session)) { // Loop ... } } catch (Exception e) { log.error("Can not handle IMAP connection", e); throw new IllegalStateException("Can not handle IMAP connection", e); } finally { close(); } }
/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException, FolderException { parser.endLine(request); if( session.getHost().getStore().isQuotaSupported()) { response.untaggedResponse(CAPABILITY_RESPONSE + SP + "QUOTA"); } else { response.untaggedResponse(CAPABILITY_RESPONSE); } session.unsolicitedResponses(response); response.commandComplete(this); } }
/** * Template methods for handling command processing. This method reads * argument values (validating them), and checks the request for correctness. * If correct, the command processing is delegated to the specific command * implementation. * * @see ImapCommand#process */ @Override public void process(ImapRequestLineReader request, ImapResponse response, ImapSession session) { try { doProcess(request, response, session); } catch (FolderException e) { log.warn("Error processing command", e); response.commandFailed(this, e.getResponseCode(), e.getMessage()); } catch (AuthorizationException e) { log.warn("Error processing command due to authentication", e); String msg = "Authorization error: Lacking permissions to perform requested operation."; response.commandFailed(this, msg); } catch (ProtocolException e) { String msg = e.getMessage() + " Command should be '" + getExpectedMessage() + '\''; log.warn("Error processing command: {}", msg, e); response.commandError(msg); } }
response.commandResponse(this, message.toString()); response.commandComplete(this);
(!useUids && includes(idSet, msn))) { String msgData = getMessageData(useUids, fetch, mailbox, uid); response.fetchResponse(msn, msgData); if (mailbox.getMessageCount() > 0 && includes(idSet, Long.MAX_VALUE) && !includes(idSet, lastMessageUid)) { String msgData = getMessageData(useUids, fetch, mailbox, lastMessageUid); response.fetchResponse(mailbox.getMsn(lastMessageUid), msgData); response.commandComplete(this);