/** * 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); }
/** * @see CommandTemplate#doProcess */ @Override protected void doProcess(ImapRequestLineReader request, ImapResponse response, ImapSession session) throws ProtocolException { String authType = parser.astring(request); parser.endLine(request); response.commandFailed(this, "Unsupported authentication mechanism '" + authType + "'"); } }
/** * 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); } }
folder = getMailbox(mailboxName, session, true); } catch (FolderException ex) { response.commandFailed(this, "No such mailbox"); return;
@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); } }
response.commandFailed(command, "Command not valid in this state"); return;
@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); // NAME root (name usage limit) Quota[] quota = session.getHost().getStore().getQuota( root, session.getUser().getQualifiedMailboxName()); for(Quota q: quota) { StringBuilder buf = new StringBuilder(); appendQuota(q, buf); response.untaggedResponse(buf.toString()); } response.commandComplete(this); }
response.commandFailed(this, "Mailbox selected read only.");
/** * @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); } } }
@Override protected void doProcess(final ImapRequestLineReader request, final ImapResponse response, final ImapSession session) { if(!session.getHost().getStore().isQuotaSupported()) { response.commandFailed(this,"Quota is not supported. Activate quota capability first"); } try { String root = parser.mailbox(request); Quota quota = new Quota(root); parser.consumeChar(request, ' '); parser.consumeChar(request, '('); quota.setResourceLimit(parser.astring(request), parser.consumeLong(request)); char c =request.nextWordChar(); if(')' != c) { quota.setResourceLimit(parser.astring(request), parser.consumeLong(request)); } parser.consumeChar(request, ')'); session.getHost().getStore().setQuota( quota, session.getUser().getQualifiedMailboxName()); response.commandComplete(this); } catch (ProtocolException e) { response.commandFailed(this, "Can not parse command"+e.getMessage()); } } }
selectMailbox(mailboxName, session, isExamine); } catch (FolderException ex) { response.commandFailed(this, "No such mailbox"); return;