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"); Contents.getContents(mm, i); } catch (MessagingException e) { e.printStackTrace(); protocol.notifyResponseHandlers(r); protocol.handleResult(response);
/** * The NOOP command. * * @exception ProtocolException for protocol failures * @see "RFC2060, section 6.1.2" */ public void noop() throws ProtocolException { logger.fine("IMAPProtocol noop"); simpleCommand("NOOP", null); }
/** * Fetch the IMAP UID for the given message. * * @param msgno the message number * @return the UID * @exception ProtocolException for protocol failures */ public UID fetchUID(int msgno) throws ProtocolException { Response[] r = fetch(msgno, "UID"); // dispatch untagged responses notifyResponseHandlers(r); Response response = r[r.length-1]; if (response.isOK()) return FetchResponse.getItem(r, msgno, UID.class); else if (response.isNO()) // XXX: Issue NOOP ? return null; else { handleResult(response); return null; // NOTREACHED } }
private void storeFlags(String msgset, Flags flags, boolean set) throws ProtocolException { Response[] r; if (set) r = command("STORE " + msgset + " +FLAGS " + createFlagList(flags), null); else r = command("STORE " + msgset + " -FLAGS " + createFlagList(flags), null); // Dispatch untagged responses notifyResponseHandlers(r); handleResult(r[r.length-1]); }
/** * LOGOUT Command. * * @exception ProtocolException for protocol failures * @see "RFC2060, section 6.1.3" */ public void logout() throws ProtocolException { try { Response[] r = command("LOGOUT", null); authenticated = false; // dispatch any unsolicited responses. // NOTE that the BYE response is dispatched here as well notifyResponseHandlers(r); } finally { disconnect(); } }
if (folder.protocol.isREV1()) command.append(first ? "BODY.PEEK[HEADER]" : " BODY.PEEK[HEADER]"); Vector v = new Vector(); // to collect non-FETCH responses & r = folder.getProtocol().fetch(msgsets, command.toString()); } catch (ConnectionException cex) { throw new FolderClosedException(folder, cex.getMessage()); } catch (CommandFailedException cfx) { throw new MessagingException(pex.getMessage(), pex); continue; if (!(r[i] instanceof FetchResponse)) { v.addElement(r[i]); // Unsolicited Non-FETCH response continue; IMAPMessage msg = folder.getMessageBySeqNumber(f.getNumber()); folder.uidTable = new Hashtable(); folder.uidTable.put(new Long(u.uid), msg); v.addElement(f); Response[] responses = new Response[size]; v.copyInto(responses); folder.handleResponses(responses);
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;
p.addResponseHandler(nonStoreResponseHandler); p.removeResponseHandler(nonStoreResponseHandler); } catch(Exception ex1) { if (p != null) try { p.disconnect(); } catch (Exception ex2) { } p = null; long lastUsed = System.currentTimeMillis() - p.getTimestamp(); if (lastUsed > pool.serverTimeoutInterval) { try { p.removeResponseHandler(this); p.addResponseHandler(nonStoreResponseHandler); p.noop(); p.removeResponseHandler(nonStoreResponseHandler); p.addResponseHandler(this); } catch (ProtocolException pex) { try { p.removeResponseHandler(nonStoreResponseHandler); p.disconnect(); } finally { !proxyAuthUser.equals(p.getProxyAuthUser()) && p.hasCapability("X-UNAUTHENTICATE")) { try {
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;
checkClosed(); // insure that we are not already open protocol.addResponseHandler(this); mi = protocol.examine(fullName); else mi = protocol.select(fullName); } catch (CommandFailedException cex) { protocol.logout(); } catch (ProtocolException pex2) { try { protocol.close(); releaseProtocol(true); } catch (ProtocolException pex) { protocol.logout(); } catch (ProtocolException pex2) { messageCache = new Vector(total); messageCache.addElement(new IMAPMessage(this, i+1, i+1)); throw new MessagingException("folder cannot contain messages"); throw new MessagingException(exc.getMessage(), exc);
if (pool.authenticatedConnections.isEmpty()) { pool.logger.fine("getStoreProtocol() - no connections " + "in the pool, creating a new one"); try { if (p != null) try { p.logout(); } catch (Exception ex2) { } p = null; "failed to create new store connection"); p.addResponseHandler(this); pool.authenticatedConnections.addElement(p); if (pool.logger.isLoggable(Level.FINE)) pool.logger.fine("getStoreProtocol() - " + "connection available -- size: " + pool.authenticatedConnections.size()); p = pool.authenticatedConnections.firstElement(); !proxyAuthUser.equals(p.getProxyAuthUser()) && p.hasCapability("X-UNAUTHENTICATE")) { p.unauthenticate(); login(p, user, password);
/** * Release the protocol object back to the connection pool. */ void releaseProtocol(IMAPFolder folder, IMAPProtocol protocol) { synchronized (pool) { if (protocol != null) { // If the pool is not full, add the store as a response handler // and return the protocol object to the connection pool. if (!isConnectionPoolFull()) { protocol.addResponseHandler(this); pool.authenticatedConnections.addElement(protocol); if (logger.isLoggable(Level.FINE)) logger.fine( "added an Authenticated connection -- size: " + pool.authenticatedConnections.size()); } else { logger.fine( "pool is full, not adding an Authenticated connection"); try { protocol.logout(); } catch (ProtocolException pex) {}; } } if (pool.folders != null) pool.folders.removeElement(folder); timeoutConnections(); } }
", 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 protocol.disconnect(); protocol = null; throw new ReferralException(ex.getUrl(), ex.getMessage()); protocol.disconnect(); protocol = null; Response r = cex.getResponse(); throw new AuthenticationFailedException( r != null ? r.getRest() : cex.getMessage()); } catch (ProtocolException pex) { // any other exception protocol.disconnect(); protocol = null; throw new MessagingException(pex.getMessage(), pex); } catch (SocketConnectException scex) { throw new MailConnectException(scex); } catch (IOException ioex) { throw new MessagingException(ioex.getMessage(), ioex);
boolean poolEmpty; synchronized (pool) { poolEmpty = pool.authenticatedConnections.isEmpty(); out.println("DEBUG: trying to connect to host \"" + host + "\", port " + port + ", isSSL " + isSSL); protocol = new IMAPProtocol(name, host, port, session.getDebug(), session.getDebugOut(), login(protocol, user, password); protocol.addResponseHandler(this); pool.authenticatedConnections.addElement(protocol); protocol.disconnect(); protocol = null; throw new AuthenticationFailedException( cex.getResponse().getRest()); } catch (ProtocolException pex) { // any other exception throw new MessagingException(pex.getMessage(), pex); } catch (IOException ioex) { throw new MessagingException(ioex.getMessage(), ioex);
FetchItem[] fitems; synchronized (messageCacheLock) { checkOpened(); isRev1 = protocol.isREV1(); fitems = protocol.getFetchItems(); command.append(getEnvelopeCommand()); first = false; if (!first) command.append(" "); command.append(createHeaderCommand(hdrs, isRev1)); r = getProtocol().fetch(msgsets, command.toString()); } catch (ConnectionException cex) { throw new FolderClosedException(this, cex.getMessage()); } catch (CommandFailedException cfx) { throw new MessagingException(pex.getMessage(), pex);
r = p.fetch(seqnum, EnvelopeCmd); p.notifyResponseHandlers(r); p.handleResult(r[r.length - 1]); } catch (ConnectionException cex) { throw new FolderClosedException(folder, cex.getMessage()); } catch (ProtocolException pex) { forceCheckExpunged(); throw new MessagingException(pex.getMessage(), pex); throw new MessagingException("Failed to load IMAP envelope");
checkClosed(); // insure that we are not already open protocol.addResponseHandler(this); if (!protocol.isEnabled("CONDSTORE") && !protocol.isEnabled("QRESYNC")) { if (protocol.hasCapability("CONDSTORE")) protocol.enable("CONDSTORE"); else protocol.enable("QRESYNC"); if (!protocol.isEnabled("QRESYNC")) protocol.enable("QRESYNC"); mi = protocol.examine(fullName, rd); else mi = protocol.select(fullName, rd); } catch (CommandFailedException cex) { protocol.logout(); } catch (ProtocolException pex2) { protocol.close(); releaseProtocol(true); } catch (ProtocolException pex) { protocol.logout(); } catch (ProtocolException pex2) {
checkClosed(); // insure that we are not already open protocol.addResponseHandler(this); if (!protocol.isEnabled("CONDSTORE") && !protocol.isEnabled("QRESYNC")) { if (protocol.hasCapability("CONDSTORE")) protocol.enable("CONDSTORE"); else protocol.enable("QRESYNC"); if (!protocol.isEnabled("QRESYNC")) protocol.enable("QRESYNC"); mi = protocol.examine(fullName, rd); else mi = protocol.select(fullName, rd); } catch (CommandFailedException cex) { checkExists(); // throw exception if folder doesn't exist throw new MessagingException( "folder cannot contain messages"); throw new MessagingException(cex.getMessage(), cex); type = 0; releaseProtocol(true);
session, dprop, m.equals("XOAUTH2")); if (disabled) { if (logger.isLoggable(Level.FINE)) logger.fine("mechanism " + m + " disabled by property: " + dprop); continue; if (!(p.hasCapability("AUTH=" + m) || (m.equals("LOGIN") && p.hasCapability("AUTH-LOGIN")))) { logger.log(Level.FINE, "mechanism {0} not supported by server", m); continue; p.authplain(authzid, user, password); else if (m.equals("LOGIN")) p.authlogin(user, password); else if (m.equals("NTLM")) p.authntlm(authzid, user, password); else if (m.equals("XOAUTH2")) p.authoauth2(user, password); else { logger.log(Level.FINE, "no authenticator for mechanism {0}", m); if (!p.hasCapability("LOGINDISABLED")) { p.login(user, password); return;
if (enableStartTLS && p.hasCapability("STARTTLS")) { p.startTLS(); p.capability(); if (p.isAuthenticated()) return; // no need to login p.getCapabilities().put("__PRELOGIN__", ""); String authzid; if (authorizationID != null) p.sasllogin(saslMechanisms, saslRealm, authzid, u, pw); if (p.isAuthenticated()) else if (p.hasCapability("AUTH=PLAIN") && !disableAuthPlain) p.authplain(authzid, u, pw); else if ((p.hasCapability("AUTH-LOGIN") || p.hasCapability("AUTH=LOGIN")) && !disableAuthLogin) p.authlogin(u, pw); else if (!p.hasCapability("LOGINDISABLED")) p.login(u, pw); else throw new ProtocolException("No login methods supported!"); p.proxyauth(proxyAuthUser); if (p.hasCapability("__PRELOGIN__")) {