in java: when I fetch imaps folders multiple in one minute, i see this error: Unexpected item LIST

Viewed 91
  • my code is

    import javax.mail.Folder;
    import javax.mail.Session;
    import javax.mail.Store;
    import javax.net.ssl.SSLContext;
    import java.util.Properties;
    
    
    ....
    ....
    
            Store store = null;
            Folder mailFolder = null;
            Properties props = System.getProperties();
            props.setProperty("mail.store.protocol", "imaps");
            try {
                SSLContext ctx = SSLContext.getInstance("TLSv1.2");
                ctx.init(null, null, null);
                SSLContext.setDefault(ctx);
            } catch (Exception e) {
                e.printStackTrace();
            }
            props.setProperty("mail.imaps.sasl.enable", "true");
    
            Session session2 = Session.getDefaultInstance(props);
            session2.setDebug(true);
            store = session2.getStore("imaps");
            store.connect("mailtest.com", 993, "test", "test");
            mailFolder = store.getDefaultFolder();
            javax.mail.Folder[] f = mailFolder.list("*");
    

    debug is:

    DEBUG: setDebug: JavaMail version 1.4ea DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc] DEBUG: mail.imap.fetchsize: 16384 DEBUG: enable SASL

    • OK mailtest.com A0 CAPABILITY
    • CAPABILITY IMAP4rev1 CHILDREN IDLE LITERAL+ MULTIAPPEND SPECIAL-USE NAMESPACE UIDPLUS QUOTA XLIST ID LOGINDISABLED AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=GSSAPI ACL RIGHTS=texkbn A0 OK CAPABILITY completed IMAP DEBUG: AUTH: CRAM-MD5 IMAP DEBUG: AUTH: DIGEST-MD5 IMAP DEBUG: AUTH: GSSAPI DEBUG: protocolConnect login, host=mailtest.com, user=test, password= IMAP SASL DEBUG: Mechanisms: CRAM-MD5 DIGEST-MD5 GSSAPI IMAP SASL DEBUG: callback length: 2 IMAP SASL DEBUG: callback 0: javax.security.auth.callback.NameCallback@663b1c53 IMAP SASL DEBUG: callback 1: javax.security.auth.callback.PasswordCallback@32c0c194 IMAP SASL DEBUG: SASL client CRAM-MD5 A1 AUTHENTICATE CRAM-MD5
    • PDQwMjM2ODc1MTEuMTU2NjkxNDZAd2VibWFpbC5zaGlyYXp1LmFjLmlyPg== IMAP SASL DEBUG: challenge: 4023687511.15669146@mailtest.com : IMAP SASL DEBUG: response: test 8127c2303f4866ee9e7e934227f10bc7 : c3NvdGVzdDEgODEyN2MyMzAzZjQ4NjZlZTllN2U5MzQyMjdmMTBiYzc= A2 LIST "" "*" A1 NO AUTHENTICATE failed A2 BAD Error: Unexpected item LIST javax.mail.MessagingException: A2 BAD Error: Unexpected item LIST;
      nested exception is: com.sun.mail.iap.BadCommandException: A2 BAD Error: Unexpected item LIST at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:2337) at com.sun.mail.imap.DefaultFolder.list(DefaultFolder.java:62) at com.liferay.portlet.action.NotificationPortlet.serveResource(NotificationPortlet.java:146)
1 Answers

The key:

A1 NO AUTHENTICATE failed
A2 BAD Error: Unexpected item LIST

The first line says you couldn't log in, for whatever reason. Because of that, the next command surprised the server. (The LIST command is only valid after successful login.)

Related