Refine search
public Response readResponse() throws IOException, ProtocolException { return new Response(this); }
/** * Extract a NSTRING, starting at the current position. Return it as * a ByteArray. The sequence 'NIL' is returned as null * * NSTRING := QuotedString | Literal | "NIL" * * @return a ByteArray */ public ByteArray readByteArray() { /* * Special case, return the data after the continuation uninterpreted. * It's usually a challenge for an AUTHENTICATE command. */ if (isContinuation()) { skipSpaces(); return new ByteArray(buffer, index, size - index); } return (ByteArray)parseString(false, false); }
if (noauthdebug && isTracing()) { logger.fine("AUTHENTICATE PLAIN command trace suppressed"); suspendTracing(); tag = writeCommand("AUTHENTICATE PLAIN", null); } catch (Exception ex) { r = Response.byeResponse(ex); done = true; try { r = readResponse(); if (r.isContinuation()) { b64os.write(ASCIIUtility.getBytes(s)); b64os.flush(); // complete the encoding os.write(bos.toByteArray()); // write out line os.flush(); // flush the stream } else if (r.isTagged() && r.getTag().equals(tag)) else if (r.isBYE()) // outta here done = true; r = Response.byeResponse(ioex); done = true;
tag = writeCommand("AUTHENTICATE NTLM", null); } catch (Exception ex) { r = Response.byeResponse(ex); done = true; if (r.isContinuation()) { first = false; } else { s = ntlm.generateType3Msg(r.getRest()); os.write(ASCIIUtility.getBytes(s)); os.write(CRLF); // CRLF termination os.flush(); // flush the stream } else if (r.isTagged() && r.getTag().equals(tag)) else if (r.isBYE()) // outta here done = true; else // hmm .. unsolicited response here ?! v.addElement(r); } catch (Exception ioex) { r = Response.byeResponse(ioex); done = true; Response[] responses = new Response[v.size()];
if (!hasCapability("QUOTA")) throw new BadCommandException("QUOTA not supported"); args.writeString(root); Response[] r = command("GETQUOTA", args); Vector v = new Vector(); Response response = r[r.length-1]; if (response.isOK()) { // command succesful for (int i = 0, len = r.length; i < len; i++) { if (!(r[i] instanceof IMAPResponse)) quota = parseQuota(ir); v.addElement(quota); r[i] = null; notifyResponseHandlers(r); handleResult(response); Quota[] qa = new Quota[v.size()]; v.copyInto(qa); return qa;
tag = pr.writeCommand("AUTHENTICATE", args); OutputStream os = pr.getIMAPOutputStream(); // stream to IMAP server if (r.isContinuation()) { byte[] ba = null; if (!sc.isComplete()) { ba = r.readByteArray().getNewBytes(); if (ba.length > 0) ASCIIUtility.toString(ba, 0, ba.length) + " :"); ba = sc.evaluateChallenge(ba); os.write(CRLF); // write out empty line os.flush(); // flush the stream os.write(bos.toByteArray()); // write out line } else if (r.isTagged() && r.getTag().equals(tag)) else if (r.isBYE()) // outta here done = true; else // hmm .. unsolicited response here ?! r = Response.byeResponse(ioex); done = true;
r = command("SEARCH", args); else r = command("SEARCH CHARSET " + charset, args); if (response.isOK()) { // command succesful Vector v = new Vector(); int num; for (int i = 0, len = r.length; i < len; i++) { v.addElement(new Integer(num)); r[i] = null; int vsize = v.size(); matches = new int[vsize]; for (int i = 0; i < vsize; i++) notifyResponseHandlers(r); handleResult(response); return matches;
if (logger.isLoggable(Level.FINE)) logger.fine("protocolConnect returning false" + ", host=" + host + ", user=" + traceUser(user) + boolean poolEmpty; synchronized (pool) { poolEmpty = pool.authenticatedConnections.isEmpty(); if (logger.isLoggable(Level.FINE)) logger.fine("trying to connect to host \"" + host + "\", port " + port + ", isSSL " + isSSL); ", user=" + traceUser(user) + ", password=" + tracePassword(password)); protocol.addResponseHandler(nonStoreResponseHandler); login(protocol, user, password); protocol.removeResponseHandler(nonStoreResponseHandler); protocol.addResponseHandler(this); usingSSL = protocol.isSSL(); // in case anyone asks pool.authenticatedConnections.addElement(protocol); Response r = cex.getResponse(); throw new AuthenticationFailedException( r != null ? r.getRest() : cex.getMessage()); } catch (ProtocolException pex) { // any other exception
if (r.isOK() || r.isNO() || r.isBAD() || r.isBYE()) ((IMAPStore)store).handleResponseCode(r); if (r.isBYE()) { if (opened) // XXX - accessed without holding folder lock cleanup(false); return; } else if (r.isOK()) { r.skipSpaces(); if (r.readByte() == '[') { String s = r.readAtom(); if (s.equalsIgnoreCase("HIGHESTMODSEQ")) highestmodseq = r.readLong(); r.reset(); return; } else if (!r.isUnTagged()) { return; // might be a continuation for IDLE logger.fine("UNEXPECTED RESPONSE : " + r.toString()); return;
/** * Fetch the BODYSTRUCTURE of the specified message. * * @param msgno the message number * @return the BODYSTRUCTURE item * @exception ProtocolException for protocol failures */ public BODYSTRUCTURE fetchBodyStructure(int msgno) throws ProtocolException { Response[] r = fetch(msgno, "BODYSTRUCTURE"); notifyResponseHandlers(r); Response response = r[r.length-1]; if (response.isOK()) return FetchResponse.getItem(r, msgno, BODYSTRUCTURE.class); else if (response.isNO()) return null; else { handleResult(response); return null; } }
if (!hasCapability("IDLE")) throw new BadCommandException("IDLE not supported"); idleTag = writeCommand("IDLE", null); } catch (LiteralException lex) { v.add(lex.getResponse()); } catch (Exception ex) { v.add(Response.byeResponse(ex)); done = true; r = readResponse(); } catch (IOException ioex) { r = Response.byeResponse(ioex); } catch (ProtocolException pex) { continue; // skip this response if (r.isContinuation() || r.isBYE()) done = true; notifyResponseHandlers(responses); if (!r.isContinuation()) handleResult(r);
Response[] r; r = fetch(msgno, body); notifyResponseHandlers(r); if (response.isOK()) { List<BODY> bl = FetchResponse.getItems(r, msgno, BODY.class); if (bl.size() == 1) return bl.get(0); // the common case if (logger.isLoggable(Level.FINEST)) logger.finest("got " + bl.size() + " BODY responses for section " + section); if (logger.isLoggable(Level.FINEST)) logger.finest("got BODY section " + br.getSection()); if (br.getSection().equalsIgnoreCase(section)) } else if (response.isNO()) return null; else { handleResult(response); return null;
/** * STARTTLS Command. * * @exception ProtocolException for protocol failures * @see "RFC3501, section 6.2.1" */ public void startTLS() throws ProtocolException { try { super.startTLS("STARTTLS"); } catch (ProtocolException pex) { logger.log(Level.FINE, "STARTTLS ProtocolException", pex); // ProtocolException just means the command wasn't recognized, // or failed. This should never happen if we check the // CAPABILITY first. throw pex; } catch (Exception ex) { logger.log(Level.FINE, "STARTTLS Exception", ex); // any other exception means we have to shut down the connection // generate an artificial BYE response and disconnect Response[] r = { Response.byeResponse(ex) }; notifyResponseHandlers(r); disconnect(); throw new ProtocolException("STARTTLS failure", ex); } }
/** * Process a response returned by readIdleResponse(). * This method will be called with appropriate locks * held so that the processing of the response is safe. * * @param r the response * @return true if IDLE is done * @exception ProtocolException for protocol failures * @since JavaMail 1.4.1 */ public boolean processIdleResponse(Response r) throws ProtocolException { Response[] responses = new Response[1]; responses[0] = r; boolean done = false; // done reading responses? notifyResponseHandlers(responses); if (r.isBYE()) // shouldn't wait for command completion response done = true; // If this is a matching command completion response, we are done if (r.isTagged() && r.getTag().equals(idleTag)) done = true; if (done) idleTag = null; // no longer in IDLE handleResult(r); return !done; }
} catch (Exception ex) { v.add(Response.byeResponse(ex)); done = true; break; r = Response.byeResponse(ioex); } catch (ProtocolException pex) { logger.log(Level.FINE, "ignoring bad response", pex); continue; // skip this response if (r.isBYE()) { byeResp = r; continue; if (r.isTagged() && r.getTag().equals(tag)) done = true;
args.writeString(Integer.toString(start) + ":" + Integer.toString(end)); args.writeString("BODY[]"); Response[] r = protocol.command("FETCH", args); Response response = r[r.length - 1]; if (response.isOK()) { Properties props = new Properties(); props.setProperty("mail.store.protocol", "imap"); protocol.notifyResponseHandlers(r); protocol.handleResult(response);
/** * Handle notifications and alerts. * Response must be an OK, NO, BAD, or BYE response. */ void handleResponseCode(Response r) { if (enableResponseEvents) notifyStoreListeners(IMAPStore.RESPONSE, r.toString()); String s = r.getRest(); // get the text after the response boolean isAlert = false; if (s.startsWith("[")) { // a response code int i = s.indexOf(']'); // remember if it's an alert if (i > 0 && s.substring(0, i + 1).equalsIgnoreCase("[ALERT]")) isAlert = true; // strip off the response code in any event s = s.substring(i + 1).trim(); } if (isAlert) notifyStoreListeners(StoreEvent.ALERT, s); else if (r.isUnTagged() && s.length() > 0) // Only send notifications that come with untagged // responses, and only if there is actually some // text there. notifyStoreListeners(StoreEvent.NOTICE, s); }