/** * Convenience routine to handle simple IAP commands * that do not have responses specific to that command. * * @param cmd the command * @param args the arguments * @exception ProtocolException for protocol failures */ public void simpleCommand(String cmd, Argument args) throws ProtocolException { // Issue command Response[] r = command(cmd, args); // dispatch untagged responses notifyResponseHandlers(r); // Handle result of this command handleResult(r[r.length-1]); }
throws IOException, ProtocolException { boolean connected = false; // did constructor succeed? tagPrefix = computePrefix(props, prefix); try { this.host = host; "mail.debug.quote", false); initStreams(); processGreeting(readResponse()); disconnect();
/** * Read a new Response from the given Protocol * * @param p the Protocol object * @exception IOException for I/O errors * @exception ProtocolException for protocol failures */ public Response(Protocol p) throws IOException, ProtocolException { // read one response into 'buffer' ByteArray ba = p.getResponseBuffer(); ByteArray response = p.getInputStream().readResponse(ba); buffer = response.getBytes(); size = response.getCount() - 2; // Skip the terminating CRLF utf8 = p.supportsUtf8(); parse(); }
/** * Start TLS on the current connection. * <code>cmd</code> is the command to issue to start TLS negotiation. * If the command succeeds, we begin TLS negotiation. * If the socket is already an SSLSocket this is a nop and the command * is not issued. * * @param cmd the command to issue * @exception IOException for I/O errors * @exception ProtocolException for protocol failures */ public synchronized void startTLS(String cmd) throws IOException, ProtocolException { if (socket instanceof SSLSocket) return; // nothing to do simpleCommand(cmd, null); socket = SocketFetcher.startTLS(socket, host, props, prefix); initStreams(); }
commandStart(command); List<Response> v = new ArrayList<Response>(); boolean done = false; tag = writeCommand(command, args); } catch (LiteralException lex) { v.add(lex.getResponse()); while (!done) { try { r = readResponse(); } catch (IOException ioex) { if (byeResp != null) // connection closed after BYE was sent v.toArray(responses); timestamp = System.currentTimeMillis(); commandEnd(); return responses;
private OutputStream startLiteral(Protocol protocol, int size) throws IOException, ProtocolException { DataOutputStream os = (DataOutputStream)protocol.getOutputStream(); boolean nonSync = protocol.supportsNonSyncLiterals(); os.write('{'); os.writeBytes(Integer.toString(size)); if (nonSync) // server supports non-sync literals os.writeBytes("+}\r\n"); else os.writeBytes("}\r\n"); os.flush(); // If we are using synchronized literals, wait for the server's // continuation signal if (!nonSync) { for (; ;) { Response r = protocol.readResponse(); if (r.isContinuation()) break; if (r.isTagged()) throw new LiteralException(r); // XXX - throw away untagged responses; // violates IMAP spec, hope no servers do this } } return os; } }
/** * Close socket connection. * * This method just makes the Protocol.disconnect() method * public. */ public void disconnect() { super.disconnect(); authenticated = false; // just in case }
/** * Write out given String as either NIL, QuotedString, or Literal. */ private void nstring(byte[] bytes, Protocol protocol) throws IOException, ProtocolException { if (bytes == null) { DataOutputStream os = (DataOutputStream)protocol.getOutputStream(); os.writeBytes("NIL"); } else nastring(bytes, protocol, true); }
private void nastring(byte[] bytes, Protocol protocol, boolean doQuote) throws IOException, ProtocolException { DataOutputStream os = (DataOutputStream)protocol.getOutputStream(); int len = bytes.length; boolean utf8 = protocol.supportsUtf8();
/** * Read a new Response from the given Protocol * * @param p the Protocol object * @exception IOException for I/O errors * @exception ProtocolException for protocol failures */ public Response(Protocol p) throws IOException, ProtocolException { // read one response into 'buffer' ByteArray ba = p.getResponseBuffer(); ByteArray response = p.getInputStream().readResponse(ba); buffer = response.getBytes(); size = response.getCount() - 2; // Skip the terminating CRLF parse(); }
tag = writeCommand(command, args); } catch (LiteralException lex) { v.addElement(lex.getResponse()); r = readResponse(); } catch (IOException ioex) {
/** * Check the greeting when first connecting; look for PREAUTH response. */ protected void processGreeting(Response r) throws ProtocolException { super.processGreeting(r); // check if it's BAD if (r.isOK()) { // check if it's OK setCapabilities(r); return; } // only other choice is PREAUTH IMAPResponse ir = (IMAPResponse)r; if (ir.keyEquals("PREAUTH")) { authenticated = true; setCapabilities(r); } else throw new ConnectionException(this, r); }
commandStart(command); List<Response> v = new ArrayList<>(); boolean done = false; tag = writeCommand(command, args); } catch (LiteralException lex) { v.add(lex.getResponse()); Response r = null; try { r = readResponse(); } catch (IOException ioex) { if (byeResp == null) // convert this into a BYE response v.toArray(responses); timestamp = System.currentTimeMillis(); commandEnd(); return responses;
private OutputStream startLiteral(Protocol protocol, int size) throws IOException, ProtocolException { DataOutputStream os = (DataOutputStream)protocol.getOutputStream(); boolean nonSync = protocol.supportsNonSyncLiterals(); os.write('{'); os.writeBytes(Integer.toString(size)); if (nonSync) // server supports non-sync literals os.writeBytes("+}\r\n"); else os.writeBytes("}\r\n"); os.flush(); // If we are using synchronized literals, wait for the server's // continuation signal if (!nonSync) { for (; ;) { Response r = protocol.readResponse(); if (r.isContinuation()) break; if (r.isTagged()) throw new LiteralException(r); // XXX - throw away untagged responses; // violates IMAP spec, hope no servers do this } } return os; } }
/** * Start TLS on the current connection. * <code>cmd</code> is the command to issue to start TLS negotiation. * If the command succeeds, we begin TLS negotiation. * If the socket is already an SSLSocket this is a nop and the command * is not issued. * * @param cmd the command to issue * @exception IOException for I/O errors * @exception ProtocolException for protocol failures */ public synchronized void startTLS(String cmd) throws IOException, ProtocolException { if (socket instanceof SSLSocket) return; // nothing to do simpleCommand(cmd, null); socket = SocketFetcher.startTLS(socket, host, props, prefix); initStreams(); }
/** * Close socket connection. * * This method just makes the Protocol.disconnect() method * public. */ @Override public void disconnect() { super.disconnect(); authenticated = false; // just in case }
/** * Write out given String as either NIL, QuotedString, or Literal. */ private void nstring(byte[] bytes, Protocol protocol) throws IOException, ProtocolException { if (bytes == null) { DataOutputStream os = (DataOutputStream)protocol.getOutputStream(); os.writeBytes("NIL"); } else nastring(bytes, protocol, true); }
private void nastring(byte[] bytes, Protocol protocol, boolean doQuote) throws IOException, ProtocolException { DataOutputStream os = (DataOutputStream)protocol.getOutputStream(); int len = bytes.length; boolean utf8 = protocol.supportsUtf8();
/** * Read a new Response from the given Protocol * @param p the Protocol object */ public Response(Protocol p) throws IOException, ProtocolException { // read one response into 'buffer' ByteArray ba = p.getResponseBuffer(); ByteArray response = p.getInputStream().readResponse(ba); buffer = response.getBytes(); size = response.getCount() - 2; // Skip the terminating CRLF parse(); }
/** * Check the greeting when first connecting; look for PREAUTH response. */ protected void processGreeting(Response r) throws ProtocolException { super.processGreeting(r); // check if it's BAD if (r.isOK()) { // check if it's OK setCapabilities(r); return; } // only other choice is PREAUTH IMAPResponse ir = (IMAPResponse)r; if (ir.keyEquals("PREAUTH")) { authenticated = true; setCapabilities(r); } else throw new ConnectionException(this, r); }